Use RudderStack’s Android SDK using Android Studio to send events from your Android device to various destinations.

The RudderStack Android SDK lets you track event data from your Android applications and send it to your specified destinations via RudderStack.

You can check the GitHub codebase to get more a hands-on understanding of the SDK and its architecture.

Github Badge

SDK setup requirements

To set up the RudderStack Android SDK, the following prerequisites must be met:

Android source write key
  • You will also need a data plane URL. Refer to the Glossary for more information on the data plane URL and where to find it.
The Setup tab in the RudderStack dashboard (seen above) has an SDK installation snippet containing both the write key and the data plane URL. You can use it to integrate the Android SDK into your project.

Installing the SDK

As Bintray has sunset from 1st May, we’re moving the Android SDK to Maven Central. All the versions from 1.0.10 are available in Maven Central only.

We distribute the Android SDK through Maven Central. The recommended and easiest way to add the SDK to your project is through the Android Gradle build system.

Follow these steps:

  • Open your project level build.gradle file, and add the following lines of code:
buildscript {
    repositories {
allprojects {
    repositories {
  • Then open your app/build.gradle and add the dependency under dependencies as shown below:
implementation ''
// add the following line if you don't have Gson included already
implementation ''
It is recommended to use the Core Android SDK without any device-mode destination SDKs as you will have a better view on the captured data from the SDK.

Using the Android SDK on applications with minSDKVersion less than 20

By default, the Android SDK does not support applications with minSDKVersion less than 20. You can add this support by following the steps below:

  • Add the following dependency to the build.gradle file of your application:
implementation ''
  • Add the function tlsBackport() in your MainActivity as shown:
private fun tlsBackport() {
        try {
            Log.e("Rudder", "Play present")
            val sslContext: SSLContext = SSLContext.getInstance("TLSv1.2")
            sslContext.init(null, null, null)
        } catch (e: GooglePlayServicesRepairableException) {
            // Prompt the user to install/update/enable Google Play services.
                .showErrorNotification(this, e.connectionStatusCode)
            Log.e("Rudder", "Play install")
        } catch (e: GooglePlayServicesNotAvailableException) {
            // Indicates a non-recoverable error: let the user know.
            Log.e("SecurityException", "Google Play Services not available.");
  • Finally, call the tlsBackport() function at the very beginning of your onCreate() method in MainActivity.
override fun onCreate(savedInstanceState: Bundle?) {
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
For more details, refer to this Android documentation.

Setting Android Permission

Add this line to your AndroidManifest.xml file of your application for internet permission:

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

We also declare android.permission.BLUETOOTH and android.permission.ACCESS_WIFI_STATE as optional by mentioning required="false" . If we get these permissions, we’ll capture the Bluetooth status and the WiFi status of the device and pass it under

Initializing the RudderStack client

Import the library on the classes you desire to use RudderClient library


Add the following code to the onCreate method in your Application class:

Follow our guide on Adding an Application Class to Your Android Application for more information.

RudderStack automatically tracks the following optional application lifecycle events:

You can disable these events using the withTrackLifecycleEvents method and passing false. But it is highly recommended to keep them enabled.

Enabling/disabling user tracking via the optOut API (GDPR Support)

RudderStack gives the users (e.g., an EU user) the ability to opt out of tracking any user activity until the user gives their consent. You can do this by leveraging RudderStack’s optOut API.

The optOut API takes true or false as a Boolean value to enable or disable tracking user activities. This flag persists across device reboots.

The following snippet highlights the use of the optOut API to disable user tracking:

the user grants their consent, you can enable user tracking once again by using the optOut API with false as a parameter sent to it:

The optOut API is available in the RudderStack Android SDK from version 1.0.21.


Google Chromecast is a device that plugs into your TV or monitor with an HDMI port, and can be used to stream content from your phone or computer.

RudderStack supports integrating the Android SDK with your Cast app. Follow these instructions to build your Android sender app. Then, add the Android SDK to it. Follow the Google Cast developer guide for more details.


You can record the users’ activity through the track method. Every user action is called an event.

A sample track event is as shown below:

Follow the method signatures below:

NameData TypeRequiredDescription
nameStringYesName of the event you want to track
propertyRudderProperty or Map<String, Object>NoExtra data properties you want to send along with the event
optionsRudderOptionNoExtra event options


We capture deviceId and use that as anonymousId for identifying the user. It helps to track the users across the application installation. To attach more information to the user, you can use the identify method. Once you set the identify information to the user, those will be passed to the successive track or screen calls. To reset the user identification, you can use the reset method.

On the Android devices, the deviceId is assigned during the first boot. It remains consistent across the applications and installs. It changes only after factory reset.

An sample identify event is as shown:

Follow the method signatures below:

NameData TypeRequiredDescription
traitsRudderTraitsYesTraits information for the user
optionsRudderOptionNoExtra options for the identify event


NameData TypeRequiredDescription
userIdStringYesDeveloper identity for the user
traitsRudderTraitsNoTraits information for user
optionRudderOptionNoExtra options for the identify event


You can use the screen call to record whenever the user sees a screen on the mobile device. You can also send some extra properties along with this event.

An example of the screen event is as shown:

Follow the method signatures below:

NameData TypeRequiredDescription
screenNameStringYesName of the screen viewed.
categoryStringNoCategory of the screen visited, such as HomeScreen, LoginScreen. Useful for tracking multiple Fragment views under a single Activity.
propertyRudderPropertyNoExtra property object that you want to pass along with the screen call.
optionRudderOptionNoExtra options to be passed along with screen event.


The group call associates a user to a specific organization. A sample group call for the API is below:

Follow the method signatures below:

NameData TypeRequiredDescription
groupIdStringYesAn ID of the organization with which you want to associate your user
traitsRudderTraitsNoAny other property of the organization you want to pass along with the call
optionsRudderOptionNoEvent level options
RudderStack doesn’t persist the traits for the group across the sessions.


The alias call associates the user with a new identification. A sample alias call for the API is below:

Alternatively, you can use the following method signature

NameData TypeRequiredDescription
newIdStringYesThe new userId you want to assign to the user
optionsRudderOptionNoEvent level option

RudderStack replaces the old userId with the newUserId and we persist that identification across the sessions.


You can use the reset method to clear the persisted traits for the identify call. This is required for Logout operations.

Configuring your RudderStack client

You can configure your client based on the following parameters using RudderConfig.Builder:

ParameterTypeDescriptionDefault value
logLevelIntegerControls how much of the log you want to see from the SDK.RudderLogger.RudderLogLevel.NONE
dataPlaneUrlStringYour data plane URL.
flushQueueSizeIntegerNumber of events in a batch request to the RudderStack server.30
dbThresholdCountIntegerNumber of events to be saved in the SQLite database. Once the limit is reached, older events are deleted from the database.10000
sleepcountIntegerMinimum waiting time to flush the events to the RudderStack server. The minimum value can be set to 1 second.10 seconds
configRefreshIntervalIntegerThe SDK will fetch the config from dashboard after the specified time2 hours
trackLifecycleEventsBooleanDetermines if the SDK will automatically capture the application lifecycle events.true
autoSessionTrackingBooleanDetermines if the SDK automatically tracks the user sessions. Refer to Tracking user sessions for more information.true
sessionTimeoutIntegerMaximum inactivity period before the session expires.300000 ms (5 minutes)
recordScreenViewsBooleanDetermines if the SDK will automatically capture the screen view events.false
autoCollectAdvertIdBooleanDetermines if the SDK will collect the advertisement ID.false
controlPlaneUrlStringChange this parameter only if you are self-hosting the control plane. Check the Self-hosted control plane section below for more information. The SDK will add /sourceConfig along with this URL to fetch the source configuration.

A sample code snippet to configure your client using RudderConfig.Builder is shown below:

rudderClient = RudderClient.getInstance(

Self-hosted control plane

If you are using a device mode destination like Adjust, Firebase, etc., the Android SDK needs to fetch the required configuration from the Control Plane. If you are using the Control plane lite utility to host your own Control Plane, then follow the steps in this section and specify controlPlaneUrl in yourRudderConfig.Builder that points to your hosted source configuration file.

You shouldn’t pass the controlPlaneUrl parameter during SDK initialization if you are using the dashboard from RudderStack Cloud Dashboard. This parameter is supported only if you are using our open-source Control plane lite to self-host your Control Plane.

Setting the Android device token

You can set your device-token for push notification to be sent to the destinations that support Push Notification. We set the token under context.device.token.

Follow the code snippets below:

Setting the advertisement ID

By default, RudderStack collects the advertisement ID only if the following three conditions are met:

val rudderClient = RudderClient.getInstance(
  • is present in your application’s class path.
  • limitAdTrackingis not enabled for your device.

To set your own advertisement ID, you can use the putAdvertisingId method:


RudderStack sets gaid under context.device.advertisementId.

Anonymous ID

We use the deviceId as anonymousId by default. You can use the following method to override and use your own anonymousId with the SDK.

An example of setting the anonymousId is shown below:


To retrieve the anonymousId, you can use the following method:

The method getAnonymousId is available from v1.0.11 onwards.

Filtering events

When sending events to a destination via device mode, you can explicitly specify which events should be discarded or allowed to flow through - by allowlisting or denylisting them.

Refer to the Client-side Event Filtering guide for more information on this feature.

Enable/disable events for specific destinations

The RudderStack Android SDK allows you to enable or disable event flow to a specific destination or all destinations to which the source is connected. You can specify these destinations by creating a RudderOption object as shown:

The keyword All in the above snippet represents all destinations the source is connected to. Its value is set to true by default.

Make sure the destination display name that you pass while specifying the destinations should exactly match the destination name as shown here.

You can pass the destination(s) specified in the above snippet to the SDK in two ways:

Pass destinations while initializing the SDK

This is helpful when you want to enable/disable sending the events across all event calls made using the SDK to the specified destination(s).

Pass destinations while making event calls

This approach is helpful when you want to enable/disable sending only a particular event to the specified destination(s) or if you want to override the specified destinations passed with the SDK initialization for a particular event.

If you specify the destinations both while initializing the SDK as well as while making an event call, then the destinations specified at the event level only will be considered.

External ID

You can pass your custom userId along with standard userId in your identify calls. We add those values under context.externalId. The following code snippet shows a way to add externalId to your identify request.

    RudderTraits().putFirstName("First Name"),
        .putExternalId("brazeExternalId", "some_external_id")

Tracking user sessions

By default, the Android SDK automatically tracks the user sessions. This means that RudderStack automatically determines the start and end of a user session depending on the inactivity time configured in the SDK (default time is 5 minutes).

To automatically track sessions in the Android SDK, withTrackLifecycleEvents should also be set to true. This is because RudderStack considers the Application Opened, Application Installed, or Application Updated events as the start of a new session.

To disable automatic session tracking, set withAutoSessionTracking to false.

For more information on the user sessions and how to track them using the Android SDK, refer to the Session Tracking guide.


If you run into any issues regarding the RudderStack Android SDK, you can turn on the VERBOSE or DEBUG logging to find out what the issue is. To turn on the logging, change your RudderClient initialization to the following:

Developing a device mode destination

You can easily develop a device mode destination in case RudderStack doesn’t support it already, by following the steps listed in this section.

More information on RudderStack device mode can be found in RudderStack Connection Modes.
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


public class CustomFactory extends RudderIntegration<CustomFactory> {
    private static final String FACTORY_KEY = "Custom Factory";

    public static Factory FACTORY = new Factory() {
        public RudderIntegration<?> create(Object settings, RudderClient client, RudderConfig rudderConfig) {
            return new CustomFactory(client,rudderConfig);

        public String key() {
            return FACTORY_KEY;

    private CustomFactory(@NonNull RudderClient client, RudderConfig config) {


    private void processRudderEvent(RudderMessage element) {
        System.out.println("Processing RudderEvent of type "+element.getType());


    public void reset() {
        System.out.println("Reset is called");

    public void flush() {
        System.out.println("Flush is called");

    public void dump(@Nullable RudderMessage element) {
        try {
            if (element != null) {
        } catch (Exception e) {

    public CustomFactory getUnderlyingInstance() {
        return this;

Some pointers to keep in mind:

  • You can use the constructor of the CustomFactory class to initialize the native SDK of the device mode destination you are working on.
  • RudderStack’s Android SDK dumps every event it receives to the dump() method of the CustomFactory class. From here, you can process the event and hand it over to the native SDK of the device mode destination.
  • The SDK also triggers the reset() method of the CustomFactory class on every reset() call made via the SDK. You can use this to handle the destination-specific reset.
  • RudderStack’s Android SDK also triggers the flush() method of the CustomFactory class on every flush() call made via the SDK which you can use to handle the destination-specific reset logic. You can make a flush call using the SDK as shown below:

Make sure you return a valid value from getUnderlyingInstance() as it is used by the Android SDK to validate CustomFactory.

  • Make sure you do not duplicate the value of FACTORY_KEY across multiple CustomFactory that you develop.
  • Register CustomFactory with the RudderStack Android SDK during its initialization:
var rudderClient = RudderClient.getInstance(

That’s it! Your Device Mode destination is good to go.


Do I need to add anything to my ProGuard rules?

If you are facing any event delivery issues in your production environment, verify if you have added the following line in your ProGuard rules:

-keep class** { *; }

What is the Android version required to set up the RudderStack Android SDK?

We currently support API 14: Android 4.0 (IceCreamSandwich) or higher.

I don’t have an Application class to initialize my RudderStack client. What do I do?

Follow our guide on How to Add an Application Class to Your Android App to add an Application class.

How do I set the Android permissions?

Please refer to the Setting the Android Permission section above to do this.

Can I use the library with Maven?

Yes, you can use the library with maven.


How do I check whether a specific event is getting fired or not?

Using the following command in the Logcat tool once you set the logLevel to VERBOSE.

adb logcat -s RudderSDK:V \
    -v tag -e "EventRepository: dump: message:"

How do I get the user traits after making the identify call?

You can get the user traits after making an identify call as shown in the following snippet:

Yes, you can. RudderStack gives you the ability to disable tracking any user activity until the user gives their consent, by leveraging the optOut API. This is required in cases where your app is audience-dependent (e.g. minors) or where you’re using the app to track the user events (e.g. EU users) to meet the data protection and privacy regulations. The optOut API takes true or false as a Boolean value to enable or disable tracking user activities. So, to disable user tracking, you can use the optOut API as shown:


Once the user gives their consent, you can enable user tracking again:


For more information on the optOut API, refer to the Enabling/Disabling User Tracking via optOut API section above.

You only need to call the optOut API with the required parameter once, as the information persists within the device even if you reboot it.

How does the SDK handle different client/server errors?

In case of client-side errors, e.g. if the source write key passed to the SDK is incorrect, RudderStack gives you a 400 Bad Request response and aborts the operation immediately.

For other types of network errors (e.g. Invalid Data Plane URL), the SDK tries to flush the events to RudderStack in an incremental manner (every 1 second, 2 seconds, 3 seconds, and so on).

Questions? Contact us by email or on Slack