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.

The io.sentry.android.gradle >= 3.0.0 requires Android Gradle Plugin >= 7.0.0.

Gradle

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

Copied
buildscript {
    repositories {
        mavenCentral()
    }
}

plugins {
    id "io.sentry.android.gradle" version "2.1.5"
}

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 your app/build.gradle:

Copied
sentry {
    // 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.
    // Default is enabled.
    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

    // Enable or disable the tracing instrumentation.
    // Does auto instrumentation for 'androidx.sqlite' and 'androidx.room' libraries.
    // It starts and finishes a Span within any CRUD operation.
    // Default is enabled.
    // Only available v3.0.0 and above.
    tracingInstrumentation {
      enabled = true
    }
}

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 in your app/build.gradle:

Copied
android {
    buildTypes {
        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.

Variant Filtering

You can specify which variant/flavor/build-type should be ignored by Sentry in your app/build.gradle file:

Copied
sentry {
    // List the build types that should be ignored (e.g. "release").
    ignoredBuildTypes = ["release"]

    // List the build flavors that should be ignored (e.g. "production").
    ignoredFlavors = ["production"]

    // List the build variant that should be ignored (e.g. "productionRelease").
    ignoredVariants = ["productionRelease"]
}
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").