After you have imported the Leanplum SDK unity package do the following steps to complete the integration for the Android platform:
- Enable custom main manifest file in Unity. In the Unity Editor, navigate to
Build Settings - Player Settings - Publishing Settingsand enableCustom Main Manifest. - Edit
Assets/Plugins/Android/AndroidManifest.xmlto set the application class. You can use the providedLeanplumApplicationclass, extend it with your own class, or have a completely separate class, which calls the appropriate Leanplum API.
- Add the application class to the manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> - <application> + <application android:name="com.leanplum.LeanplumUnityApplication"> <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <meta-data android:name="unityplayer.UnityActivity" android:value="true" /> </activity> </application> </manifest> - If you are using a custom application class extend
LeanplumApplication:or callpublic class YourApplication extends LeanplumUnityApplication { ... }
LeanplumUnity.initialize(this)in theonCreatemethod:public class YourApplication extends Application { @Override public void onCreate() { super.onCreate(); LeanplumUnity.initialize(this); } }
- Enable main gradle template file in Unity. In the Unity Editor, navigate to
Build Settings - Player Settings - Publishing Settingsand enableCustom Main Gradle Template. - Edit
Assets/Plugins/Android/mainTemplate.gradleto include only the desired optional features:
dependencies {
// Push
implementation "com.leanplum:leanplum-push:${LP_VERSION}"
// FCM
implementation "com.leanplum:leanplum-fcm:${LP_VERSION}"
implementation 'com.google.firebase:firebase-messaging:22.0.0'
// HMS
implementation "com.leanplum:leanplum-hms:${LP_VERSION}"
// Location
implementation "com.leanplum:leanplum-location:${LP_VERSION}"
implementation "com.google.android.gms:play-services-location:18.0.0"
}- Use the same version for the optional features as the Leanplum version in
Assets/Plugins/Android/leanplum-unity-wrapper.androidlib/build.gradle
def LP_VERSION = "X.X.X"- If you are using FCM, download
google-service.jsonfile and put it into root ofAssetsfolder. When Android project is exported it will automatically parse the file.
-
Edit
Assets/Plugins/Android/AndroidManifest.xmlto set the launcher activity to the CleverTap class:<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <application> <application android:name="com.leanplum.LeanplumUnityApplication"> - <activity android:name="com.unity3d.player.UnityPlayerActivity" + <activity android:name="com.clevertap.unity.CleverTapOverrideActivity" android:theme="@style/UnityThemeSelector"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <meta-data android:name="unityplayer.UnityActivity" android:value="true" /> </activity> </application> </manifest>In Unity 6, the Android Player settings provide two application entry point options:
- Activity
- GameActivity
For CleverTap integration, ensure that the Activity option is selected in:
Project Settings → Player → Android → Others Settings → Appication Entry Point -
Use CleverTap Unity API after
Leanplum.CleverTapInstanceReadyevent is received:Leanplum.CleverTapInstanceReady += () => { // CleverTap is ready to use CleverTap.CreateNotificationChannel( "YourChannelId", "Your Channel Name", "Your Channel Description", 5, true); };
-
Do not use CleverTapSettings from the Unity editor and do not add CleverTap account data in the AndroidManifest.xml file, Leanplum will apply the correct values automatically.
-
See how to enable the optional CleverTap features here