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. 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:
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.
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:
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:
If your app doesn't target the Google Play Store, add the following permission to access the device's network 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.
4. Set up Proguard
If you're using Proguard to optimize your app, you must add rules to prevent Proguard from removing classes.
If you're not publishing your app in the Google Play Store, add the following rule:
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:
If you're using Proguard, remember to add a rule to prevent the dependency from being removed.
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:
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
If you want to use the SDK signature library to secure communications between the Adjust SDK and Adjust's servers, follow the instructions in the SDK signature guide on the Adjust Help Center.
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 toAdjustConfig.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:
Create a class that extends the
Application
.Open the
AndroidManifest.xml
file and locate the<application>
element.Add the
android:name
attribute to the<application>
element and set it to the name of your application class. For example, if yourApplication
class is namedGlobalApplication
, you would set the following:Find the
initSdk
method in yourApplication
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
- 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
AdjustBridgeInstance
by 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 theAdjustBridgeInstance
and theWebView
.Here's an example of a full setup:
Import the Adjust Javascript files in your HTML:
You can now initialize the Adjust SDK in your web view by passing your
appToken
andenvironment
to theAdjustConfig
class:
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
environment
toAdjustConfig.ENVIRONMENT_PRODUCTION
.