Initializing the sdk - optimove-tech/Optimove-SDK-Android GitHub Wiki
- Add the following to the app module's
build.gradle
file, under theandroid
object.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
- For Kotlin support only
Kotlin is completely interoperable with Java and Apps that are written in Kotlin can use the SDK. However, these apps should add the following in addition to the compile options.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
If you get an error like :app:transformClassesWithDesugarForDebug
, you may have to enable desugaring in your gradle.properties
file:
android.enableD8.desugaring = true
-
Make sure that you have the mavenCentral() repository in your project level
build.gradle
filebuildscript { repositories { mavenCentral() //... } //... }
-
In your app module's
build.gradle
file, update your dependency statement (underdependencies
object) to:implementation 'com.optimove.android:optimove-android:7.+'
If after adding the dependency you get an error building like Manifest merger failed
, follow the steps below to adjust Automatic Backup
Important Note: Optimove uses semantic versioning, which means that each time you
Sync Now
yourbuild.gradle
, Optimove SDK will automatically get updated with any minor features, improvements and hotfixes.
Depending on which features were enabled for your app you will be able to retreive the following credentials from your Mobile Marketing UI.
- YOUR_OPTIMOVE_CREDENTIALS – Your unique SDK token in order to identify your Optimove tenant
- YOUR_OPTIMOVE_MOBILE_CREDENTIALS – The mobile config used to identify your app bundle
The SDK can be initialized with either credential depending on which features are to be used, or both. But at least one must be provided.
If you know your credentials when application starts, your initialisation should look as follows:
public class YourApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Optimove.initialize(this, new OptimoveConfig.Builder(
"<YOUR_OPTIMOVE_CREDENTIALS>", "<YOUR_OPTIMOVE_MOBILE_CREDENTIALS>"
).build());
}
}
In rare cases when you determine credentials dynamically, use the following:
public class YourApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
OptimoveConfig.FeatureSet desiredFeatures = new OptimoveConfig.FeatureSet().withOptimobile().withOptimove();
Optimove.initialize(this, new OptimoveConfig.Builder(OptimoveConfig.Region.EU, desiredFeatures).build());
}
}
When SDK is initialised this way, events and deferred deep link clicks are cached, in-app messages are not delivered. To finish the initialisation do
Optimove.setCredentials( "<YOUR_OPTIMOVE_CREDENTIALS>", "<YOUR_OPTIMOVE_MOBILE_CREDENTIALS>");
After credentials are set all caches are flushed and the SDK starts behaving identical to the Standard Initialisation.
If you are using staging and prod environments, you will receive 2 different sets of credentials. Consider using your BuildConfig file to declare them:
buildTypes {
release {
...
buildConfigField "String", "OPTIMOVE_CREDENTIALS", '"<YOUR_OPTIMOVE_CREDENTIALS>"'
buildConfigField "String", "OPTIMOVE_MOBILE_CREDENTIALS", '"<YOUR_OPTIMOVE_MOBILE_CREDENTIALS>"'
}
stg {
...
buildConfigField "String", "OPTIMOVE_CREDENTIALS", '"<YOUR_OPTIMOVE_STAGING_CREDENTIALS>"'
buildConfigField "String", "OPTIMOVE_MOBILE_CREDENTIALS", '"<YOUR_OPTIMOVE_MOBILE_STAGING_CREDENTIALS>"'
}
}
Then initialize Optimove using:
Optimove.initialize(this, new OptimoveConfig.Builder(
BuildConfig.OPTIMOVE_CREDENTIALS,
BuildConfig.OPTIMOVE_MOBILE_CREDENTIALS
).build());
Starting from Android SDK version 23
, Android offers the Auto Backup for Apps feature as a way to back up and restore the user's data in the app.
The Optimove SDK depends on various local files being deleted once the app is uninstalled.
For that reason if the hosting app also defines android:fullBackupContent="@xml/app_backup_rules"
in the manifest.xml file, Android will raise a merge conflict.
Follow these steps to resolve the conflict and maintain the data integrity of the Optimove SDK:
- Add
tools:replace="android:fullBackupContent">
to the application tag. - Copy the content of the
optimove_backup_rules.xml
to your full-backup-content xml.
If your target version is 31 and higher and your app defines android:dataExtractionRules="@xml/app_backup_rules"
, follow the same steps above.
If you consume SDK version higher or equal to 4.2.0 and your target version is lower than 31 add tools:remove="android:dataExtractionRules"
to the application tag.
For more information about Android Automatic Backup checkout backup Developer's Guide article.