Gradle plugin to automatically upload ProGuard mapping files to Bugsnag.
Bugsnag for Android automatically detects crashes in your Android apps, collecting diagnostic information and immediately notifying your development team.
Create a free account to start capturing exceptions from your applications.
If you aren't using Gradle or need more manual control, see the API docs for alternative ways to use Bugsnag with Proguard.
Add the plugin to the plugins
section at the top of your Module-level Gradle
Settings, at <project dir>/<module name>/build.gradle
(usually
<project_dir>/app/build.gradle
):
plugins {
id "com.bugsnag.android.gradle" version "2.3.2"
}
Add this plugin as a dependency in your main Project Gradle Settings, at <project_dir>/build.gradle
:
buildscript {
dependencies {
// Add this line to your `dependencies` section
classpath 'com.bugsnag:bugsnag-android-gradle-plugin:2.3.2'
}
}
You'll then need to "apply" the plugin by adding the following line to the top of your Module Gradle Settings, at <project_dir>/<module_name>/build.gradle
(usually <project_dir>/app/build.gradle
).
apply plugin: 'com.bugsnag.android.gradle'
In most situations, the basic installation steps above will suffice, but you can manually configure further settings as follows:
By default this plugin will read your API key from your manifest. You should ensure that you have the following code in AndroidManifest.xml
.
<application ...>
<meta-data android:name="com.bugsnag.android.API_KEY" android:value="your-api-key-here"/>
</application>
Alternatively, you can set your API key in your app's build.gradle
as follows:
bugsnag {
apiKey 'your-api-key-here'
}
By default, this plugin will automatically upload the proguard mapping file generated for every build, if you'd prefer to disable this automatic uploading, set the autoUpload
property in your app's build.gradle
:
bugsnag {
autoUpload false
}
If you disable automatic uploading, you can still run the upload task manually, with the uploadBugsnagVariantMapping task:
./gradlew clean package uploadBugsnagReleaseMapping
In order for Bugsnag to de-duplicate errors correctly it needs to know the file and line number for every crash. Proguard strips this information by default, so we'll automatically add the following line into your Proguard configuation to avoid this:
-keepattributes SourceFile,LineNumberTable
-keep class com.bugsnag.android.NativeInterface { *; }
-keep class com.bugsnag.android.Breadcrumbs { *; }
-keep class com.bugsnag.android.Breadcrumbs$Breadcrumb { *; }
-keep class com.bugsnag.android.BreadcrumbType { *; }
-keep class com.bugsnag.android.Severity { *; }
-keep class com.bugsnag.android.ndk.BugsnagObserver { *; }
If you'd prefer to add this into your Proguard configuration yourself, you can disable our automatic configuration in your app's build.gradle
as follows:
bugsnag {
autoProguardConfig false
}
By default, we'll upload mapping files to upload.bugsnag.com
, if you are using Bugsnag Enterprise, you can configure your upload endpoint in your app's build.gradle
as follows:
bugsnag {
endpoint 'http://upload.bugsnag.example.com'
}
To completely disable the Bugsnag plugin, use the extension property enableBugsnag
, for example:
android {
buildTypes {
debug {
ext.enableBugsnag = false
}
}
}
Bugsnag supports uploading NDK shared object symbol mappings as well as ProGuard mappings. If you are using the Native Development Kit, enable symbol upload as follows:
bugsnag {
ndk true
}
To overwrite a mapping file, you can set the overwrite
property as follows:
bugsnag {
overwrite false
}
You can also declare this inside a product flavor. Conflicting values (between multiple flavors or a flavor and a build-type) are ignored and the plugin will be disabled if false
was set anywhere.
You may want to do this to speed up build types or flavors where you don't require Bugsnag's functionality. Bugsnag's generation of a UUID for each build into your manifest (see Build UUIDs) causes the resources task to be run for each build, introducing a small delay if your build's changes don't involve resources.
To enable retrying the file upload, set the retryCount
property:
bugsnag {
retryCount 5
}
This plugin automatically generates a UUID for each build (excluding Instant
Run builds,
which is inserted into your AndroidManifest.xml
during the build process. This
UUID is used to uniquely identify each build, along with your appId
and
versionCode
, to help us determine which proguard mapping file to use with each
crash report.
This UUID is available as com.bugsnag.BUILD_UUID
in a meta-data
element
in case you'd like to use yourself it in your applications.
- Additional Documentation
- Search open and closed issues for similar problems
- Report a bug or request a feature
We'd love your contributions! For information on how to build, test and release this plugin, see our contributing guide.
This plugin is free software released under the MIT License. See LICENSE.txt for details.