adjust-icon

Android SDK integration guide

The Adjust Android SDK enables you to record attribution, events, and more in your Android app. Follow the steps in this guide to set up your app to work with the Adjust SDK.

Before you begin

Here’s what you need to do before updating to SDK v5:

  1. SDK v5 supports SDK signature verification natively. If you currently use the SDK signature library, you need to uninstall this first.
  2. If your app targets API versions lower than 21 you need to update your app before you can use SDK v5.

1. Set up your environment

To use the Adjust SDK, you need to add it to your project as a dependency. The Adjust SDK is available on Maven.

To add the Adjust SDK to your project:

  1. Add the Adjust SDK and Android install referrer implementations to your build.gradle file. Optionally add the Adjust web view bridge if you use web views in your app.

    build.gradle
    dependencies {
    implementation 'com.adjust.sdk:adjust-android:5.0.0'
    implementation 'com.android.installreferrer:installreferrer:2.2'
    // Add the following if you are using the Adjust SDK inside web views on your app
    implementation 'com.adjust.sdk:adjust-android-webbridge:5.0.0'
    }

2. Add Google Play Services

Apps that target the Google Play Store must use the gps_adid (Google Advertising ID) to identify devices. You need to add the play-services-ads-identifier AAR to your project to access the gps_adid.

If you’re using Maven, add the following to your build.gradle file:

build.gradle
dependencies {
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
}

3. Add permissions

To give the Adjust SDK access to device information, you need to declare which permissions your app requires. To do this, add permissions to your AndroidManifest.xml file.

Add the following permissions to get access to online features:

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

If your app doesn’t target the Google Play Store, add the following permission to access the device’s network state:

AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

The Adjust SDK includes the com.google.android.gms.AD_ID permission by default. If you need to make your app COPPA (Children’s Online Privacy Protection Act) compliant or if your app doesn’t target the Google Play Store, you must remove this permission using a remove directive.

AndroidManifest.xml
<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>

4. Set up Proguard

If you’re using Proguard to optimize your app, you must add rules to prevent Proguard from removing classes.

Proguard.pro
-keep class com.adjust.sdk.** { *; }
-keep class com.google.android.gms.common.ConnectionResult {
int SUCCESS;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {
com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context);
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {
java.lang.String getId();
boolean isLimitAdTrackingEnabled();
}
-keep public class com.android.installreferrer.** { *; }

If you’re not publishing your app in the Google Play Store, add the following rule:

Proguard.pro
-keep public class com.adjust.sdk.** { *; }

5. Set up install referrer

An install referrer is a unique identifier used to attribute an install to a source. The Adjust SDK requires this information to perform attribution. Use one of the following methods to retrieve the install referrer information:

Google Play Referrer API

The Google Play Referrer API is available to apps that target the Google Play Store.

To support the Google Play Referrer API, add the following to your build.gradle file:

build.gradle
dependencies {
implementation 'com.android.installreferrer:installreferrer:2.2'
}

If you’re using Proguard, remember to add a rule to prevent the dependency from being removed.

Proguard.pro
-keep public class com.android.installreferrer.** { *; }

Huawei Referrer API

The Huawei Referrer API is available to apps that target Huawei devices. The Adjust SDK can record installs on Huawei devices using the Adjust Huawei Referrer plugin.

To install this plugin, add the following dependency to your build.gradle file:

build.gradle
dependencies {
implementation: "com.adjust.sdk:adjust-android-huawei-referrer:5.0.0"
}

Xiaomi referrer plugin

The Xiaomi referrer plugin enables you to record install referrer values for apps that target Xiaomi devices. See the plugin documentation for install information.

Samsung referrer plugin

The Samsung referrer plugin enables you to record install referrer values for apps that target the Samsung Galaxy store. See the plugin documentation for install information.

Meta referrer integration

The Adjust SDK supports the Meta Install Referrer using the Adjust Meta Install Referrer plugin. See the documentation for integration details.

6. Set up SDK Signature

SDK v5 includes the SDK signature library. Signature protection is inactive by default. To enable it, you need to:

  1. Enforce signature validation.
  2. Provide your app’s SHA-1 fingerprints prior to testing.

7. Integrate the Adjust SDK

The following information is required to initialize the Adjust SDK:

  • appToken: Your Adjust app token.
  • environment: The environment your app is running in. Set this to AdjustConfig.ENVIRONMENT_SANDBOX to test your app locally.

The recommended way to initialize the Adjust SDK is inside a global Android Application class. If you haven’t already set this up for your app, follow these steps:

  1. Create a class that extends the Application.

  2. Open the AndroidManifest.xml file and locate the <application> element.

  3. Add the android:name attribute to the <application> element and set it to the name of your application class. For example, if your Application class is named GlobalApplication, you would set the following:

    AndroidManifest.xml
    <application android:name=".GlobalApplication">
    <!-- ... -->
    </application>
  4. Find the initSdk method in your Application class or add one if it doesn’t exist. Pass the following parameters to initialize the Adjust SDK:

    • Your appToken
    • The environment you want to run the app in
    • The LogLevel you want to record

Integrate the Adjust Web View SDK

If your app uses web views, you need to use the Adjust Web View SDK to record information. You need to obtain the reference to your WebView object. Once you’ve done this, follow these steps:

  1. Call webView.getSettings().setJavaScriptEnabled(true) to enable Javascript in the web view.
  2. Start the default AdjustBridgeInstance by calling AdjustBridge.registerAndGetInstance(getApplication(), webview). This registers the Adjust bridge as a Javascript interface in the web view.
  3. Call AdjustBridge.setWebView() to set a new WebView.
  4. Call AdjustBridge.unregister() to unregister the AdjustBridgeInstance and the WebView.
  5. Here’s an example of a full setup:
  1. Import the Adjust Javascript files in your HTML:

    <script type="text/javascript" src="adjust.js"></script>
    <script type="text/javascript" src="adjust_event.js"></script>
    <script type="text/javascript" src="adjust_third_party_sharing.js"></script>
    <script type="text/javascript" src="adjust_config.js"></script>
  2. You can now initialize the Adjust SDK in your web view by passing your appToken and environment to the AdjustConfig class:

    let yourAppToken = "{YourAppToken}";
    let environment = AdjustConfig.EnvironmentSandbox;
    let adjustConfig = new AdjustConfig(yourAppToken, environment);
    adjustConfig.setLogLevel(AdjustConfig.LogLevelVerbose);
    Adjust.initSdk(adjustConfig);

8. Build your app for production

Once you’ve finished your testing, you can build your app for production. To do this, you need to update your config object.

  1. Adjust your log level to return only what you need.
  2. Set your environment to AdjustConfig.ENVIRONMENT_PRODUCTION.