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.0.0'
}

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 android:name="com.raygun.raygun4android.apikey"> 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.enableRUM(activity);

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.