Skip to content

Commit 132522c

Browse files
authored
Merge pull request #65 from getsentry/feature/improved-linking
Improve react-native link
2 parents 1fb1a4c + 68707f5 commit 132522c

File tree

5 files changed

+544
-134
lines changed

5 files changed

+544
-134
lines changed

docs/index.rst

Lines changed: 51 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -5,143 +5,95 @@
55
React Native
66
============
77

8-
This is the documentation for our beta clients for React-Native. This is
9-
an early release with various different levels of support. iOS is best
10-
supported if you are also using the native extension and if not we fall
11-
back to pure JavaScript for basic support.
12-
13-
We would love to get your feedback!
8+
This is the documentation for our beta clients for React-Native. The
9+
React-Native client uses a native extension for iOS and Android but can
10+
fall back to a pure JavaScript version if needed.
1411

1512
Installation
1613
------------
1714

18-
Start with adding sentry and linking it::
15+
Start by adding Sentry and then linking it::
1916

2017
$ npm install react-native-sentry --save
2118
$ react-native link react-native-sentry
2219

23-
The `link` step will pull in the native dependency. If you are using
24-
expo you don't have to (or can't) run that step. In that case we fall
25-
back automatically.
20+
The `link` step will pull in the native dependency and patch your project
21+
accordingly. If you are using expo you don't have to (or can't) run that
22+
link step. For more information about that see :doc:`expo`.
23+
24+
On linking you will automatically be prompted for your DSN and other
25+
information and we will configure your app automatically for react-native
26+
and change files accordingly. You will need to provide the following
27+
data: your DSN, the slug of your organization in Sentry, the slug of your
28+
project in Sentry as well as the API key.
29+
30+
You can find the slugs in the URL of your project
31+
(``sentry.io/your-org-slug/your-project-slug``) If you don't have an auth
32+
token yet you can `create an auth token here <https://sentry.io/api/>`_.
2633

27-
On linking you will usually be prompted for your DSN and we will configure
28-
your app automatically for react-native and change files accordingly.
2934
Upon linking the following changes will be performed:
3035

31-
* added the raven-java package for native crash reporting on android
32-
* added the sentry-swift package for native crash reporting on iOS
33-
* enabled the sentry gradle build step for android
36+
* add the raven-java package for native crash reporting on Android
37+
* add the sentry-swift package for native crash reporting on iOS
38+
* enable the sentry gradle build step for android
3439
* patch `AppDelegate.m` for iOS
3540
* patch `MainApplication.java` for Android
36-
* configured Sentry for the supplied DSN in your `index.js` files
41+
* configure Sentry for the supplied DSN in your `index.js` files
42+
* store build credentials in `ios/sentry.properties` and
43+
`android/sentry.properties`.
44+
45+
To see what is happening during linking you can refer to
46+
:doc:`manual-setup` which will give you all the details.
3747

3848
Note that we only support ``react-native >= 0.38`` at the moment.
3949

50+
Upgrading
51+
---------
52+
53+
If you are upgrading from an earlier version of sentry-react-native you
54+
should re-link the package to ensure the generated code is updated to the
55+
latest version::
56+
57+
$ react-native unlink react-native-sentry
58+
$ react-native link react-native-sentry
59+
4060
iOS Specifics
4161
-------------
4262

4363
Since we use our `Swift Client
4464
<https://github.com/getsentry/sentry-swift>`_ in the background, your
45-
project has to embed the swift standard libraries.
46-
47-
Search for ``ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES`` in your Xcode project
48-
build settings and set it to ``YES``.
49-
50-
You will get this error message if you forget to set it::
51-
52-
dyld: Library not loaded: @rpath/libswiftCore.dylib
53-
Referenced from: [Redacted]/Sentry.framework/Sentry
54-
Reason: image not found
55-
56-
Also note that if you build the project without setting this, you have to
57-
run clean in order to make the change work.
65+
project has to embed the swift standard libraries. The link step will do
66+
this automatically for your project.
5867

5968
When you use xcode you can hook directly into the build process to upload
60-
debug symbols. Open up your xcode project in the iOS folder, go to your
61-
project's target and change the "Bundle React Native code and images"
62-
build script. The script that is currently there needs to be adjusted as
63-
follows::
64-
65-
export SENTRY_ORG=___ORG_NAME___
66-
export SENTRY_PROJECT=___PROJECT_NAME___
67-
export SENTRY_AUTH_TOKEN=YOUR_AUTH_TOKEN
68-
export NODE_BINARY=node
69-
../node_modules/react-native-sentry/bin/bundle-frameworks
70-
../node_modules/sentry-cli-binary/bin/sentry-cli react-native-xcode \
71-
../node_modules/react-native/packager/react-native-xcode.sh
72-
../node_modules/sentry-cli-binary/bin/sentry-cli upload-dsym
73-
74-
You can find the slugs in the URL of your project
75-
(sentry.io/your-org-slug/your-project-slug) If you don't have an auth
76-
token yet you can `create an auth token here <https://sentry.io/api/>`_.
77-
78-
This also uploads debug symbols in the last line which however will not
79-
work for bitcode enabled builds. If you are using bitcode you need to
80-
remove that line (``../node_modules/sentry-cli-binary/bin/sentry-cli
81-
upload-dsym``) and consult the documentation on dsym handling instead (see
82-
:ref:`dsym-with-bitcode`).
83-
84-
Note that uploading of debug simulator builds by default is disabled for
85-
speed reasons. If you do want to also generate debug symbols for debug
86-
builds you can pass `--allow-fetch` as a parameter to ``react-native-xcode``.
69+
debug symbols and sourcemaps. If you however are using bitcode you will
70+
need to disable the "Upload Debug Symbols to Sentry" build phase and then
71+
separately upload debug symbols from iTunes Connect to Sentry.
8772

8873
Android Specifics
8974
-----------------
9075

9176
For Android we hook into gradle for the sourcemap build process. When you
92-
run ``react-native link`` the gradle files are automatically updated but
93-
in case you are not using linked frameworks you might have to do it
94-
manually. Whenever you run ``./gradlew assembleRelease`` sourcemaps are
95-
automatically built and uploaded to Sentry.
96-
97-
To enable the gradle integration you need to change your
98-
``android/app/build.gradle`` file and add the following line after the
99-
``react.gradle`` one::
100-
101-
apply from: "../../node_modules/react-native-sentry/sentry.gradle"
102-
103-
Additionally you need to create an ``android/sentry.properties`` file with
104-
the access credentials:
105-
106-
.. sourcecode:: ini
107-
108-
defaults.org=___ORG_NAME___
109-
defaults.project=___PROJECT_NAME___
110-
auth.token=YOUR_AUTH_TOKEN
77+
run ``react-native link`` the gradle files are automatically updated.
78+
When you run ``./gradlew assembleRelease`` sourcemaps are automatically
79+
built and uploaded to Sentry.
11180

11281
Client Configuration
11382
--------------------
11483

115-
Note: When you run ``react-native link`` we will attempt to automatically
116-
patch your code so you might notice that some of these changes were
117-
already performed.
118-
119-
Add Sentry to your `index.ios.js` and `index.android.js`:
84+
Note: When you run ``react-native link`` we will automatically update your
85+
`index.ios.js` / `index.android.js` with the following changes:
12086

12187
.. sourcecode:: javascript
12288

12389
import { Sentry } from 'react-native-sentry';
124-
12590
Sentry.config('___DSN___').install();
12691

127-
If you are using the binary version of the package (eg: you ran
128-
``react-native link``) then you additionally need to register the native
129-
crash handler in your `AppDelegate.m` after the root view was created for
130-
iOS:
131-
132-
.. sourcecode:: objc
133-
134-
#if __has_include(<React/RNSentry.h>)
135-
#import <React/RNSentry.h> // This is used for versions of react >= 0.40
136-
#else
137-
#import "RNSentry.h" // This is used for versions of react < 0.40
138-
#endif
139-
140-
/* in your didFinishLaunchingWithOptions */
141-
[RNSentry installWithRootView:rootView];
92+
You can pass additional configuration options to the `config()` method if
93+
you want to do so.
14294

143-
More
144-
----
95+
Deep Dive
96+
---------
14597

14698
.. toctree::
14799
:maxdepth: 2
@@ -150,3 +102,4 @@ More
150102
expo
151103
sourcemaps
152104
cocoapods
105+
manual-setup

docs/manual-setup.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
Manual Setup
2+
============
3+
4+
If you can't (or don't want) to run the linking step you can see here what
5+
is happening on each platform.
6+
7+
iOS
8+
---
9+
10+
Since we use our `Swift Client
11+
<https://github.com/getsentry/sentry-swift>`_ in the background, your
12+
project has to embed the swift standard libraries.
13+
14+
Xcode Settings
15+
``````````````
16+
17+
The link step sets ``ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES`` in your Xcode
18+
project's build settings to ``YES``.
19+
20+
You will get this error message if that setting is not set::
21+
22+
dyld: Library not loaded: @rpath/libswiftCore.dylib
23+
Referenced from: [Redacted]/Sentry.framework/Sentry
24+
Reason: image not found
25+
26+
Build Steps
27+
```````````
28+
29+
When you use Xcode you can hook directly into the build process to upload
30+
debug symbols. When linking one build phase script is changed and two more
31+
are added.
32+
33+
We modify the react-native build phase ("Bundle React Native code and images")
34+
slightly from this::
35+
36+
export NODE_BINARY=node
37+
../node_modules/react-native/packager/react-native-xcode.sh
38+
39+
To this::
40+
41+
export NODE_BINARY=node
42+
export SENTRY_PROPERTIES=sentry.properties
43+
../node_modules/sentry-cli-binary/bin/sentry-cli react-native-xcode \
44+
../node_modules/react-native/packager/react-native-xcode.sh
45+
46+
Additionally we add a build script called "Bundle react-native-sentry
47+
Frameworks" which bundles necessary frameworks as well as a build
48+
step called "Upload Debug Symbols to Sentry" which uploads debug symbols
49+
to Sentry. The latter needs to be disabled if you use bitcode.
50+
51+
This also uploads debug symbols in the last line which however will not
52+
work for bitcode enabled builds. If you are using bitcode you need to
53+
remove that line (``../node_modules/sentry-cli-binary/bin/sentry-cli
54+
upload-dsym``) and consult the documentation on dsym handling instead (see
55+
:ref:`dsym-with-bitcode`).
56+
57+
Note that uploading of debug simulator builds by default is disabled for
58+
speed reasons. If you do want to also generate debug symbols for debug
59+
builds you can pass `--allow-fetch` as a parameter to ``react-native-xcode``
60+
in the above mentioned build phase.
61+
62+
Android
63+
-------
64+
65+
For Android we hook into gradle for the sourcemap build process. When you
66+
run ``react-native link`` the gradle files are automatically updated.
67+
68+
We enable the gradle integration in your ``android/app/build.gradle`` file
69+
by adding the following line after the ``react.gradle`` one::
70+
71+
apply from: "../../node_modules/react-native-sentry/sentry.gradle"

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
"react-native": ">=0.38.0"
2121
},
2222
"dependencies": {
23+
"chalk": "^1.1.1",
24+
"glob": "7.1.1",
25+
"inquirer": "3.0.6",
2326
"raven-js": "^3.15.0",
2427
"sentry-cli-binary": "^1.9.0",
25-
"inquirer": "3.0.6",
26-
"glob": "7.1.1"
28+
"xcode": "0.9.3"
2729
},
2830
"rnpm": {
2931
"commands": {

0 commit comments

Comments
 (0)