Crash reports

Bugsee automatically intercepts uncaught exceptions and sends crash reports on app restart.

Proguard

When ProGuard/R8 is used, crash reports are likely to have obfuscated parts in them. In order to process them a matching mapping.txt has to be uploaded to Bugsee servers. The mapping can be uploaded manually at any time, but Bugsee also provides a special mechanism to upload mapping files automatically at build time using a gradle plugin:

Add the following code to your build.gradle or build.gradle.kts in the root of your project (your project's or app module's build.gradle file) to initiate Bugsee gradle plugin when appropriate:

!Groovy

buildscript {
    repositories {
        mavenCentral()
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.1'

        // Add Bugsee plugin as a dependency
        classpath 'com.bugsee:bugsee-android-gradle-plugin:3+' 
    }
}

!KTS

buildscript {
    repositories {
        mavenCentral()
        google()
    }

    dependencies {
        classpath("com.android.tools.build:gradle:7.4.1")

        // Add Bugsee plugin as a dependency
        classpath("com.bugsee:bugsee-android-gradle-plugin:3+") 
    }
}

And now add the following line to your build.gradle or build.gradle.kts in app folder (app/feature module's build.gradle file)

!Groovy

// !!! This line is already in your app/feature module's build.gradle file
apply plugin: 'com.android.application'

// Activate Bugsee plugin
apply plugin: 'bugsee' 

!KTS

// Add Bugsee plugin to "plugins" section in your app/feature module's build.gradle.kts file
plugins {
    // Other plugins
    //...

    // Activate Bugsee plugin
    id("bugsee")
}

Application token is required to associate the uploaded mapping file with the right application. If you have the single app token for all build variants, you might add the following section to the app/feature module's build.gradle file

!Groovy

bugsee {
    appToken '<your_app_token>'
}

!KTS

bugsee {
    appToken("<your_app_token>")
}

But if you have several app tokens for different build variants, you can provide Bugsee plugin with closure

!Groovy

bugsee {
    appToken { com.android.build.gradle.api.BaseVariant variant ->
        switch (variant.buildType.name) { // Check build type or any other condition based on a given BaseVariant.
            case 'release': '<release app token>'
                break
            case 'qa': '<qa app token>'
                break
        }
    }
}

!KTS

class MyAppTokenProvider : com.bugsee.android.gradle.AppTokenProvider {
    override fun getAppToken(variant : com.android.build.gradle.api.BaseVariant) : String? {
        return when (variant.buildType.name) {
            "release" -> "<release app token>"
            "qa" -> "<qa app token>"
            else -> null
        }
    }
}

bugsee {
    appToken(MyAppTokenProvider())
}

Proguard optimization

If you enable ProGuard optimization by, for example, adding 'proguard-android-optimize.txt' to proguardFiles list, it is necessary to add the following ProGuard rule:

-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*,!code/allocation/variable 

First part is taken from standard 'proguard-android-optimize.txt' file and last part '!code/allocation/variable' is added in order to compile with Bugsee.

Special cases

If you use other libraries, which intercept uncaught exceptions, Bugsee.launch() method should be called after all these libraries are initialized. When uncaught exceptions occurs, Bugsee will inform these libraries about exception.

If you set uncaught exceptions handler in your app using Thread.setDefaultUncaughtExceptionHandler() method after calling Bugsee.launch(), you should call Bugsee.onUncaughtException() method from your handler:

!Java

Thread.setDefaultUncaughtExceptionHandler(mExceptionHandler);
//...
private final Thread.UncaughtExceptionHandler mExceptionHandler = new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread thread, Throwable ex) {
            Bugsee.onUncaughtException(thread, ex);

            // App specific exception handling.
            System.exit(1);
        }
    };

!Kotlin

Thread.setDefaultUncaughtExceptionHandler(mExceptionHandler)
//...
private val mExceptionHandler = Thread.UncaughtExceptionHandler { thread, ex ->
    Bugsee.onUncaughtException(thread, ex)

    // App specific exception handling.
    System.exit(1)
}