Crash reports

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

Proguard

When proguard 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 {
        jcenter()
    }

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

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

!Kotlin

buildscript {
    repositories {
        jcenter()
    }

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

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

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' // Or 'com.android.feature'

// Activate Bugsee plugin
apply plugin: 'bugsee' 

!Kotlin

// 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>'
}

!Kotlin

bugsee {
    appToken("<your_app_token>")
}

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

!Groovy

import com.android.build.gradle.api.BaseVariant;

bugsee {
    appToken { 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
        }
    }
}

!Kotlin

import com.android.build.gradle.api.BaseVariant
import com.bugsee.android.gradle.AppTokenProvider

class MyAppTokenProvider : AppTokenProvider {
    override fun getAppToken(variant : 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:

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);
        }
    };