Unity SDK 7.0.0

The Leanplum Unity SDK 7.0.0 brings changes to the Leanplum integration and CleverTap migration.

Dependencies

  • Leanplum iOS SDK 6.6.1
  • Leanplum Android SDK 7.6.3
  • CleverTap Unity SDK 5.1.0

Android Setup

Leanplum SDK 7.0.0 has structural changes to its Android project setup, which enable more flexible ways of integrating the SDK and improve the integration with the CleverTap Unity SDK. Namely the leanplum-wrapper is now included as a module in the android project generated by Unity, instead of it being supplied as an .aar library. Due to some limitations of how Unity packages are distributed, there are a few manual changes that need to be made when updating from a previous version of the SDK:

Leanplum Update

  1. Import the updated Leanplum Unity package to your project.

  2. Edit Assets/Plugins/Android/mainTemplate.gradle with the following changes:

    • Remove Leanplum Core and CleverTap dependencies. They will be automatically provided in the leanplum-wrapper module.
    -def CT_SDK_VERSION = "6.1.1"
    
    -    implementation "com.leanplum:leanplum-core:${LEANPLUM_SDK_VERSION}"
    -    implementation "com.clevertap.android:clevertap-android-sdk:${CT_SDK_VERSION}"
    -    //implementation(name: "com.leanplum.unity-wrapper-${LEANPLUM_SDK_VERSION}", ext:'aar')
    -    //implementation project(':android-unity-wrapper')
    
    • If you are using other leanplum libraries like :push, :fcm, :location or :hms update their version to the one in Assets/Plugins/Android/leanplum-unity-wrapper.androidlib/build.gradle
    def LP_VERSION = "X.X.X"
    
    Assets/Plugins/Android/mainTemplate.gradle
    -def LEANPLUM_SDK_VERSION = "7.4.1"
    +def LEANPLUM_SDK_VERSION = "X.X.X"
    
    • Remove mi-push libraries. They are not longer supported
    -    // Uncomment for MiPush. Note that leanplum-mipush package is deprecated. MiPush will be used through CleverTap SDK.
    -    // implementation "com.leanplum:leanplum-mipush:${LEANPLUM_SDK_VERSION}"
    
  3. Enable custom main manifest file in Unity. In the Unity Editor, navigate to Build Settings - Player Settings - Publishing Settings and enable Custom Main Manifest.

  4. Edit Assets/Plugins/Android/AndroidManifest.xml to set the application class. You can use the provided LeanplumApplication class, 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:

    public class YourApplication extends LeanplumUnityApplication {
        ...
    }
    

    or call LeanplumUnity.initialize(this) in the onCreate method:

    public class YourApplication extends Application {
    
        @Override
        public void onCreate() {
            super.onCreate();
            LeanplumUnity.initialize(this);
        }
    }
    

CleverTap Integration Update

  1. Edit Assets/Plugins/Android/AndroidManifest.xml to 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>
    
  2. Use CleverTap Unity API after Leanplum.CleverTapInstanceReady event is received:
        Leanplum.CleverTapInstanceReady += () =>
        {
            // CleverTap is ready to use
            CleverTap.CreateNotificationChannel(
                "YourChannelId",
                "Your Channel Name",
                "Your Channel Description",
                5,
                true);
        };
    
  3. 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.
  4. See how to enable the optional CleverTap features here

iOS Setup

Leanplum SDK 7.0.0 has iOS integration changes. The Leanplum iOS SDK and its dependencies CleverTap iOS SDK and SDWebImage are no longer included as xcframeworks in the Plugins/iOS folder. The dependencies are now resolved using the External Dependency Manager for Unity.

Leanplum Update

  1. Dependencies
    Delete the xcframeworks from Plugins/iOS folder if they exist.
    The required dependencies are installed using CocoaPods and the EDM4U plugin. Set up EDM4U plugin to install CocoaPods automatically. Go to Assets > External Dependency Manager > iOS Resolver > Settings. Check Podfile generate and choose Cocoapods Integration - Add Cocoapods to the Xcode workspace.
    Alternatively, manually install pods by running pod install in the exported XCode project. Ensure to start .xcworkspace to build the app with dependencies.

  2. LeanplumUnityAppController
    Leanplum adds a subclass of the UnityAppController. It sets up UNUserNotificationCenter. It is primarily used for CleverTap Unity migration.
    If you use your own UnityAppController override, inherit from the CleverTapUnityAppController or call the CleverTap methods. If you use your own one, you can disable the LeanplumUnityAppController by setting LP_NO_APP_CONTROLLER_SUBCLASS preprocessor macro.

  3. Post Process Build Script
    Ensure the LeanplumApplePostProcessor script is updated when you update the SDK and import the assets. The build script no longer adds the xcframeworks. It updates GCC_PREPROCESSOR_DEFINITIONS macros.

  4. Do not use CleverTapSettings from the Unity editor and do not add CleverTap account data in the Info.plist file, Leanplum will apply the correct values automatically.

CleverTap Usage

It is no longer required to have a "CleverTapUnity" GameObject. Remove the object since the CleverTap SDK will create the required game objects automatically.
You should now use the CleverTap static interface (not CleverTapBinding). CleverTap callbacks can be registered from any object now (no longer required to be in CleverTapUnity.cs).

If you want to do any CleverTap configurations or call CleverTap SDK directly, you need to do that inside the CleverTapReady callback. This ensures CleverTap is initialized and ready:

Leanplum.CleverTapInstanceReady += () =>
{
    // Record basic event with no properties
    CleverTap.RecordEvent("testEvent");
};