Migrate to latest Adobe Experience Platform Mobile SDKs for Android
If you have implemented the previous versions of the Android Mobile SDKs, then this guide will help you understand the steps required to migrate to the latest version. In summary, you will need to:
- Switch Gradle dependencies to latest versions
- Update SDK initialization
- Replace the deprecated API calls with the new API calls
Switch Gradle dependencies to latest versions
At this time, the previous versions of the Android Mobile SDKs may be switched out with their respective latest version. See instructions on proceeding further if you have manually imported SDK libraries , or if you used Gradle to manage SDK dependencies.
Starting with version 2.0.0, the sdk-core
bundle (which includes Core, Lifecycle, Identity, Signal) will no longer receive updates. You need to include those libraries individually as described below.
SDK Name | Latest Version |
---|---|
sdk-core | |
userprofile | |
assurance | |
edge | |
edgeidentity | |
edgeconsent | |
messaging | |
optimize | |
analytics | |
audience | |
target | |
media | |
places | |
campaign | |
campaignclassic |
Manual library import
If you are manually importing the Mobile SDK libraries, update your app dependencies to the latest versions shown in the table above.
Gradle
If you are using Gradle to manage your app dependencies, the following example shows how to upgrade to latest version in the build.gradle
file.
Copied to your clipboarddependencies {//replace sdk-core with Core/Lifecycle/Identity/Signal 2.0//implementation 'com.adobe.marketing.mobile:sdk-core:1.+'implementation 'com.adobe.marketing.mobile:core:2.+'implementation 'com.adobe.marketing.mobile:lifecycle:2.+'implementation 'com.adobe.marketing.mobile:identity:2.+'implementation 'com.adobe.marketing.mobile:signal:2.+'//replace UserProfile 1.+ with UserProfile 2.0//implementation 'com.adobe.marketing.mobile:userprofile:1.+'implementation 'com.adobe.marketing.mobile:userprofile:2.+'}
Using dynamic dependency versions is not recommended for production apps. Refer to this page for managing Gradle dependencies.
Save the build.gradle
file and select Sync Project with Gradle Files
in Android Studio to download the latest Android SDK.
Update SDK initialization
After you have imported the new Android libraries, you'll need to update SDK initialization code as described below. With Mobile Core version 2.0.0 and above, the MobileCore.start()
API is no longer required. The SDK has simplified initialization and registration of extensions by providing the MobileCore.registerExtensions()
API. After the given extensions have been registered, the SDK will be initialized and the completion block will be executed. The code which used to reside in the start() block will now reside in the MobileCore.registerExtensions()
's completion block.
The following code snippets show the recommended initialization code for the latest Mobile SDKs.
Copied to your clipboardpublic class MainApp extends Application {private static final String ENVIRONMENT_FILE_ID = "ENVIRONMENT_FILE_ID";@Overridepublic void onCreate() {super.onCreate();MobileCore.setApplication(this);MobileCore.configureWithAppID(ENVIRONMENT_FILE_ID);List<Class<? extends Extension>> extensions = new ArrayList<>();extensions.add(Lifecycle.EXTENSION);extensions.add(Signal.EXTENSION);extensions.add(UserProfile.EXTENSION);extensions.add(Assurance.EXTENSION);extensions.add(Identity.EXTENSION);MobileCore.registerExtensions(extensions, o -> {Log.d(LOG_TAG, "AEP Mobile SDK is initialized");});}}
Copied to your clipboardclass MyApp : Application() {val ENVIRONMENT_FILE_ID = "ENVIRONMENT_FILE_ID"override fun onCreate() {super.onCreate()MobileCore.setApplication(this)MobileCore.configureWithAppID(ENVIRONMENT_FILE_ID)val extensions = listOf(Identity.EXTENSION, Signal.EXTENSION, Lifecycle.EXTENSION, UserProfile.EXTENSION, Assurance.EXTENSION)MobileCore.registerExtensions(extensions) {Log.d(LOG_TAG, "AEP Mobile SDK is initialized")}}}
Copied to your clipboardpublic class MainApp extends Application {private static final String ENVIRONMENT_FILE_ID = "ENVIRONMENT_FILE_ID";@Overridepublic void onCreate() {super.onCreate();MobileCore.setApplication(this);MobileCore.configureWithAppID(ENVIRONMENT_FILE_ID);List<Class<? extends Extension>> extensions = new ArrayList<>();extensions.add(Lifecycle.EXTENSION);extensions.add(Signal.EXTENSION);extensions.add(UserProfile.EXTENSION);extensions.add(Assurance.EXTENSION);extensions.add(Identity.EXTENSION);MobileCore.registerExtensions(extensions, o -> {Log.d(LOG_TAG, "AEP Mobile SDK is initialized");});}}
Copied to your clipboardclass MyApp : Application() {val ENVIRONMENT_FILE_ID = "ENVIRONMENT_FILE_ID"override fun onCreate() {super.onCreate()MobileCore.setApplication(this)MobileCore.configureWithAppID(ENVIRONMENT_FILE_ID)val extensions = listOf(Identity.EXTENSION, Signal.EXTENSION, Lifecycle.EXTENSION, UserProfile.EXTENSION, Assurance.EXTENSION)MobileCore.registerExtensions(extensions) {Log.d(LOG_TAG, "AEP Mobile SDK is initialized")}}}
Replace the deprecated API calls with the new API calls
Some of the APIs available in previous major versions of the Mobile SDK for Android are now deprecated. You can choose to replace the deprecated APIs in your code with the alternative APIs in the latest version, as described in the table below:
The registerExtension
API for each extension is deprecated in the latest version of the mobile SDK. You don't need to register extensions separately, now you can call MobileCore.registerExtensions
API instead. See the Update SDK initialization section for more details.
Deprecated API | Alternative API |
---|---|
EXTENSION.registerExtension | MobileCore.registerExtensions |
UserProfile.updateUserAttribute | UserProfile.updateUserAttributes |
UserProfile.removeUserAttribute | UserProfile.removeUserAttributes |