Set up a mobile app
Send errors from an Android, iOS, macOS, React Native or Expo app with Sentry's own SDK, and make its release stack traces readable.
Sentry's mobile SDKs send to App Monitoring unmodified: only the DSN, and for uploads the token, point here. Create a project with the Platform of your app (Android, iOS, macOS or React Native, see Create a project); its Setup tab shows the snippets below with your DSN, organization and project filled in.
What you see in a release build
| App | Stack traces of a release build | What makes them readable |
|---|---|---|
| Android, Java or Kotlin code | Class and method names as R8 renamed them (a.b.c) |
The build's ProGuard mapping file, uploaded by the Gradle plugin |
| React Native and Expo, JS code | Positions in index.android.bundle or main.jsbundle |
The bundle's source map, uploaded by the build |
| iOS and macOS, Swift and Obj-C | The binary and the address of each frame (MyApp 0x0000000100a4) |
Not supported yet: debug symbols (dSYMs) are accepted, not used |
| Native code (NDK, C and C++) | The binary and the address | Not supported yet |
Mapping files and source maps are applied when an event arrives: upload them with the build, before the app reaches users. A frame that is shown as it was sent is marked on the issue page (no mapping file, no source map or not symbolicated).
Android
In
app/build.gradle.kts, add the Sentry Android Gradle plugin and point it at App Monitoring. The plugin adds the SDK to the app and uploads the mapping file of every release build.plugins { id("com.android.application") id("io.sentry.android.gradle") version "6.27.0" } sentry { org.set("my-org") projectName.set("my-app") url.set("https://errors.example.com/") authToken.set(System.getenv("SENTRY_AUTH_TOKEN")) includeProguardMapping.set(true) autoUploadProguardMapping.set(true) telemetry.set(false) }In
AndroidManifest.xml, inside<application>, set the DSN:<meta-data android:name="io.sentry.dsn" android:value="https://public-key@errors.example.com/42" />Set
SENTRY_AUTH_TOKENwhere the release build runs (see Upload ProGuard mapping files).
The app's own classes are marked in-app, and Android, AndroidX, Kotlin and Sentry classes are not.
iOS and macOS
Add
https://github.com/getsentry/sentry-cocoawith Swift Package Manager, orpod 'Sentry'to the Podfile.Start the SDK at launch, in your
Appinitializer or inapplication(_:didFinishLaunchingWithOptions:):import Sentry SentrySDK.start { options in options.dsn = "https://public-key@errors.example.com/42" }(Optional) In a macOS app built with AppKit, report uncaught exceptions as crashes:
UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions": true])
A crash's stack is read from the crashed thread. Frames are grouped by binary and function name,
never by address, so the same crash from two launches or two builds is one issue. An upload of
debug symbols (sentry-cli debug-files upload, the Xcode build phase, Fastlane) succeeds, and
the files are not kept.
React Native
Install the SDK:
npm install @sentry/react-native, thenpod installinapps/ios/.In
App.tsx, initialize the SDK and wrap the root component:import * as Sentry from '@sentry/react-native'; Sentry.init({ dsn: 'https://public-key@errors.example.com/42' }); export default Sentry.wrap(App);In
metro.config.js, add the Sentry serializer, which writes the debug IDs that tie each bundle to its source map:const { getDefaultConfig } = require('@react-native/metro-config'); const { withSentryConfig } = require('@sentry/react-native/metro'); module.exports = withSentryConfig(getDefaultConfig(__dirname));Write
android/sentry.propertiesandios/sentry.properties:defaults.url=https://errors.example.com/ defaults.org=my-org defaults.project=my-appUpload the source maps of every release build: apply
sentry.gradleinandroid/app/build.gradle, and runsentry-xcode.shin Xcode's Bundle React Native code and images build phase. The Setup tab shows both lines.Set
SENTRY_AUTH_TOKENwhere the release build runs (see Upload source maps).
Source maps of Hermes builds are applied too. The function name comes from your source; the build machine's project directory is cut from the file name, so builds on two machines group alike.
Expo
Install the SDK:
npx expo install @sentry/react-native.Add the config plugin to
app.json, pointed at App Monitoring:{ "expo": { "plugins": [ [ "@sentry/react-native/expo", { "url": "https://errors.example.com/", "organization": "my-org", "project": "my-app" } ] ] } }In
metro.config.js, usegetSentryExpoConfig:const { getSentryExpoConfig } = require('@sentry/react-native/metro'); module.exports = getSentryExpoConfig(__dirname);Initialize the SDK and wrap the root layout, as for React Native.
Store
SENTRY_AUTH_TOKENas a secret environment variable of the EAS project, never inapp.json. EAS builds then upload their source maps.