ProGuard

To use ProGuard with Sentry, upload the ProGuard mapping files by either the recommended method of using our Gradle integration or manually by using sentry-cli.

Gradle

Using Gradle (Android Studio) in your app/build.gradle add:

app/build.gradle
Copied
apply plugin: 'io.sentry.android.gradle'

And declare a dependency in your top-level build.gradle:

build.gradle
Copied
buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        // https://github.com/getsentry/sentry-android-gradle-plugin/releases
        classpath 'io.sentry:sentry-android-gradle-plugin:1.7.36'
    }
}

The plugin will automatically generate appropriate ProGuard mapping files and upload them when you run gradle assemble{BuildVariant}. For example, assembleRelease — Release is the default, but the plugin works for others if you have enabled ProGuard/R8. The credentials for the upload step are loaded via environment variables or from a sentry.properties file in your project root.

For more information, see the full sentry-cli documentation.

At the very minimum you will need something similar to:

Copied
defaults.project=your-project
defaults.org=your-org
auth.token=YOUR_AUTH_TOKEN

Gradle Configuration

Additionally, we expose a few configuration values directly in Gradle:

app/build.gradle
Copied
sentry {
    // Disables or enables the automatic configuration of ProGuard
    // for Sentry.  This injects a default config for ProGuard so
    // you don't need to do it manually.

    // Only enable it if you are using sentry-android <= v1.7,
    // sentry-android >= v2.0 already does it automatically.
    autoProguardConfig false

    // Enables or disables the automatic upload of mapping files
    // during a build.  If you disable this, you'll need to manually
    // upload the mapping files with sentry-cli when you do a release.
    autoUpload true

    // Disables or enables the automatic configuration of Native Symbols
    // for Sentry. This executes sentry-cli automatically so
    // you don't need to do it manually.
    // Default is disabled.
    uploadNativeSymbols false

    // Does or doesn't include the source code of native code for Sentry.
    // This executes sentry-cli with the --include-sources param. automatically so
    // you don't need to do it manually.
    // Default is disabled.
    includeNativeSources false
}

Now when you build your app, the plugin will upload the ProGuard/R8 mappings, source bundle, and native symbols as you configured them to Sentry.

Multi-Dex Support

If you're using Multi-Dex and our SDK, we recommend updating your Multi-Dex configuration:

app/build.gradle
Copied
release {
    multiDexKeepProguard file('multidex-config.pro')
}

And, add to multidex-config.pro the following lines:

Copied
-keep class io.sentry.android.core.SentryAndroidOptions
-keep class io.sentry.android.ndk.SentryNdk

If you experience issues like Could not find class on devices running the Dalvik VM, you may expand the above rules to keep the necessary classes in the main dex file.

You can edit this page on GitHub.