Installation

Raygun4Android supports all devices that have the following requirements.

  • minSdkVersion 16+
  • compileSdkVersion 28

Ensure jcenter() or mavenCentral() are present in your project's build.gradle:

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

Then add the following to your module's build.gradle:

dependencies {
    implementation 'com.raygun:raygun4android:4.+'
}

In your app's AndroidManifest.xml, make sure you have granted Internet permissions. Beneath the <manifest> element add:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Inside the <application> element, add the following:

<service android:name="com.raygun.raygun4android.services.CrashReportingPostService"
         android:exported="false"
         android:permission="android.permission.BIND_JOB_SERVICE"
         android:process=":crashreportingpostservice"/>
<service android:name="com.raygun.raygun4android.services.RUMPostService"
         android:exported="false"
         android:permission="android.permission.BIND_JOB_SERVICE"
         android:process=":rumpostservice"/>
<meta-data android:name="com.raygun.raygun4android.apikey"
           android:value="PASTE_YOUR_API_KEY_HERE" />

Replace the value in <meta-data> with your API key, available from your Raygun dashboard under Application settings.

In a central activity (we suggest to use your common launch activity), call the following:

RaygunClient.init(application);
RaygunClient.enableCrashReporting();

The above exception handler automatically catches and sends all uncaught exceptions. You can create your own or send from a catch block by calling RaygunClient.send() and passing in the Throwable.


Raygun supports retracing your exceptions that have been obfuscated with ProGuard or R8. This can be achieved by uploading the relevant mapping.txt file/s into your Raygun Application. Retracing is done automatically to each report as they come into Raygun so that you are presented with readable stacktraces.

Documentation for ProGuard/R8 support can be found here.


Raygun supports tracking the unique users who encounter bugs in your apps.

By default, a device-derived UUID is transmitted. You can also add the currently logged in user's data like this:

String identifier = "ronald@raygun.com";

RaygunUserInfo user = new RaygunUserInfo(identifier);
user.setFirstName("Ronald");
user.setFullName("Ronald Raygun");
user.setEmail("ronald@raygun.com");

RaygunClient.setUser(user);

Any of the properties but identifier and isAnonymous are optional. The property isAnonymous will be set to true if the identifier is null or an empty string. There is also a constructor overload if you prefer to specify all in one statement, and a convenience constructor to only set an identifier.

The identifier should be a unique representation of the current logged in user - we will assume that messages with the same identifier are the same user. If you do not set it, it will be automatically set to the device UUID.

The string properties on a User have a maximum length of 255 characters. Users who have fields that exceed this amount will not be processed.

If the user context changes, for instance on log in/out, you should remember to call setUser again to store the updated user identifier. If a user logs out, and you want to use the default device identifier again, just create an empty RaygunUserInfo object without an identifier. In this case isAnonymous will be set to true.


The provider is open source and available at the Raygun4Android repository.