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.
1. Get the Adjust SDK
To use the Adjust SDK in your Android app, you need to add it to your project. You can download the latest version from the GitHub releases page.
If you’re using Maven, add the following to your build.gradle file:
dependencies { implementation 'com.adjust.sdk:adjust-android:4.38.5' implementation 'com.android.installreferrer:installreferrer:2.2' // Add the following if you're using the Adjust SDK inside web views on your app implementation 'com.adjust.sdk:adjust-android-webbridge:4.38.5'}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:
dependencies { implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'}Collect App Set Identifier
The App Set Identifier is a unique identifier that enables you to measure information from any of your apps that a user has installed on their device. All apps by the same developer share the same App Set ID, meaning you can gather meaningful insights from users across all your apps. To record a device’s App Set ID, you need to add the following permission to your build.gradle file:
dependencies { implementation 'com.google.android.gms:play-services-appset:16.0.2'}If this permission is enabled, the App Set ID is sent to Adjust’s servers as part of the device information payload.
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:
<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:
<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.
<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.
-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:
-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:
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.
-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 Huawei App Gallery v10.4 and later. You don’t need to make any changes to support this API.
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 in v4.36.0 and above. To enable this feature:
- Find your Meta app ID in your App Dashboard. See Meta’s App Dashboard documentation for more information.
- Pass your App ID as a
Stringargument to theAdjustConfig.setFbAppIdmethod.
6. 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 toAdjustConfig.ENVIRONMENT_SANDBOXto 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:
- Create a class that extends the
Application. - Open the
AndroidManifest.xmlfile and locate the<application>element. - Add the
android:nameattribute to the<application>element and set it to the name of your application class. For example, if yourApplicationclass is namedGlobalApplication, you would set the following:
<application android:name=".GlobalApplication"> <!-- ... --></application>-
Find the
onCreatemethod in yourApplicationclass or add one if it doesn’t exist. Pass the following parameters to initialize the Adjust SDK:- Your
appToken - The
environmentyou want to run the app in - The
LogLevelyou want to record
- Your
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:
- Call
webView.getSettings().setJavaScriptEnabled(true)to enable Javascript in the web view. - Start the default
AdjustBridgeInstanceby callingAdjustBridge.registerAndGetInstance(getApplication(), webview). This registers the Adjust bridge as a Javascript interface in the web view. - Call
AdjustBridge.setWebView()to set a newWebView. - Call
AdjustBridge.unregister()to unregister theAdjustBridgeInstanceand theWebView. - Here’s an example of a full setup:
- 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>- You can now initialize the Adjust SDK in your web view by passing your
appTokenandenvironmentto theAdjustConfigclass:
let yourAppToken = "{YourAppToken}";let environment = AdjustConfig.EnvironmentSandbox;let adjustConfig = new AdjustConfig(yourAppToken, environment);adjustConfig.setLogLevel(AdjustConfig.LogLevelVerbose);Adjust.onCreate(adjustConfig);7. Configure session recording
To record session information, you need to call methods at different stages of your app’s activity lifecycle. These stages are different depending on the API level your app targets.
API level 14 and above
To set up session recording for API level 14 and above:
- If you have
Adjust.onResumeandAdjust.onPausecalls in your activities, remove them. - Add a private class that implements the
ActivityLifecycleCallbacksinterface. - Edit the
onActivityResumed(Activity activity)method and add a call toAdjust.onResume(). - Edit the
onActivityPaused(Activity activity)method and add a call toAdjust.onPause(). - Add the
onCreate()method to your Adjust SDK configuration step. - Call
registerActivityLifecycleCallbackswith an instance of the createdActivityLifecycleCallbacksclass:
API level 9 to 13
To set up session recording in apps targeting API level 13 and below, follow these steps:
- Add a call to
Adjust.onResume()in your activity’sonResumemethod. - Add a call to
Adjust.onPause()in your activity’sonPausemethod. - Repeat these steps for each activity in your app. Depending on your coding style, you might want to add this in a common superclass of all your activities.
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.
- Adjust your log level to return only what you need.
- Set your
environmenttoAdjustConfig.ENVIRONMENT_PRODUCTION.