This app demonstrates how to use Sentry in an Android application:
Error Events
- Unhandled Exceptions
- Handled Exceptions
- HTTP Client Errors
- Application Not Responding
- Native Crashes from C++ native code
- Message Capture
Performance Issues
- DB on Main Thread
- File IO on Main Thread
- Image Decoding on Main Thread
- Regex on Main Thread
- JSON Decoding on Main Thread
Tracing
- Time to Initial/Full Display
- Automatic Instrumentation for UI Activity (UI Load, App Start Warm/Cold, Slow and Frozen Frames, OkHttp Library, File I/O Instrumentation, SQLite and Room query)
- Manual Instrumentation
- Profiling
- CPU Usage, Memory
Other
- Session Replay
- Logs
- Screenshots
- View Hierary
- User Feedback
dependency | version |
---|---|
sentry-java | 8.17.0 |
sentry-android-gradle-plugin | 5.8.0 |
Android Studio Narwhal | 2025.1.1 Patch 1 |
Android Gradle Plugin | 8.6.0 (requires a minimum Gradle version of 8.7) |
sentry-cli | 2.44.0 |
macOS | Sequoia 15.5 |
OpenJDK supported, supported java -version : |
openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment Homebrew (build 21.0.2)
OpenJDK 64-Bit Server VM Homebrew (build 21.0.2, mixed mode, sharing)
-
git clone [email protected]:sentry-demos/android.git
-
Open project using Android Studio. It will take a few minutes for Gradle to configure itself and download dependencies.
-
Set your Build Variant to 'release' instead of debug. Or else debug symbols won't get uploaded. Build Variants tab (left side of Android Studio) > Select 'release' under Active Build Variant Column > if that's missing then go to Build > Edit Build Types.
-
Sync the project with the Gradle files
Tools -> Android -> Sync Project with Gradle Files In some Android Studio version this will be available under: File -> Sync Project with Gradle Files
-
Put your Sentry DSN key in
AndroidManifest.xml
and your 'project' name in the Makefile -
For Performance Demo: Configure your backend endpoint in the
empowerplant.domain
attribute inAndroidManifest.xml
(application-monitoring-python
by default) -
Put your AUTH Token and project name in sentry.properties
-
make all
-
Android Studio install Android NDK in Preferences > System & Behavior > System Settings > Android SDK > SDK Tools > and install the following:
-
Maintain a separate branch which has your auth token.
-
Optional - Add se: tag to buildConfigField in build.gradle.
make all
if you haven't yet, or have made significant changes to your code. Otherwise run the app.- Run 'app' in Android Studio on an Android Virtual Device.
- Open the app, add items to cart, check out; open List App and click error-related buttons
master
branch, with no untracked git changes. This is necessary because we rely on these releases for our automated test data ("TDA") and don't want unintended local modifications (i.e. to DSNs or project names) to accidentally make it into our automated data.
- Checkout a new git branch.
- Run
./generate_release_artifacts.sh
, then run./gradlew assembleRelease
to generate debug-build and release-build.apk
files; copy them to the/release
folder withcp app/build/outputs/apk/release/app-release.apk ./release
- Commit the changes to
build.gradle
,app-release.apk
, andapp-debug.apk
. - Push up the changes in a pull request.
- Get an approval and merge the changes.
(After completing the steps in Part 1, and once your release branch is merged in.)
- Run the Release GitHub Action https://github.com/sentry-demos/android/actions/workflows/release.yml, choose a version name and version code as prompted, then
Run workflow
. - You'll see that a new release was created in https://github.com/sentry-demos/android/releases.
- Restart your demo automation tools so they'll still hitting the latest APK release.
The version code is unique. This is already part of build system in Android. The app won't compile without it.
Optional - Setting the release in AndroidManifest.xml will override what's set in src/build.gradle. Possible uses cases would be:
- Indicating Paid vs Free versions of your apps
- Match versions for your Android and iOS apps together. force a release name.
- The pattern 'package@name+version' is new from Sentry, so you could override that in AndroidManifest.xml
- Good for testing if you're iterating quickly, but not publishing your app.
<meta-data android:name="io.sentry.release" android:value="[email protected]+1" />
- Change to the latest Sentry Android Gradle Plugin as shown in https://docs.sentry.io/platforms/android/configuration/gradle/#setup:
plugins {
id "com.android.application"
id "io.sentry.android.gradle" version "5.8.0"
}
- Match the sdk_version from https://github.com/getsentry/sentry-android-gradle-plugin/blob/main/plugin-build/gradle.properties in src/build.gradle like:
implementation 'io.sentry:sentry-android:8.17.0'
Note: This step may not be necessary with newer versions of Sentry Android Gradle Plugin
- Make a new Release
- Click 'Sync Now' for sync'ing your gradle files in AndroidStudio
make all
will do a new./gradlew build
- If you put app to background, then put to foreground within 30 seconds, it does not create new Session.
- If you put app to background, then wait more than 30 seconds, then put to foreground, it will create new session.
- 30 seconds is mentioned here, but we set our default in AndroidManifest.xml to 3 seconds (3000 millisecond) for demo purposes.
- Swiping up "close", there's no way to know what happened to the session. It's not a error/crash. It's a normal exited session.
- Opening the app again right away should great a fresh new session.
- If device has a stable connection, events sent right away.
- SentryServer has a pipeline that's queuing events, depends on state of Sentry.
- C++ crashes go through Symbolicator which has its own queuing and symbolication takes slightly longer.
- Need to restart the app.
- Session (ending) is sent when App goes to Background OR there's a crash.
- Session data is sent when Session Starts and when Session Ends.
- So if you make a Handled Error, the Session data is not sent just yet. updates the session only locally in the device.
- Difficult to compare crashes with a report in Discover (with
handled:no
) vs the Release because when a crash happens, you have to wait for the device to come back online again. - If you are ever filtering, sampling, or rate .imiting events/crashes out, then it's possible that the Sessions data isn't getting filtered/sampled and so your Crash Free Rate will appear higher than it actually is.