Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This documentation will guide you through the installation of Mobile Protect Android in a Unity project, For other guides, check out Mobile Protect Installation Guides

Step 1: Create an Android library project

First, you will need to create a new native Android library project, that project will allow you to read the Mobile Protect config file and add its gradle plugin.

In this example the library is called library and uses the com.datatheorem.mobileprotect.unitylibrary namespace.

Step 2: Add mobile Protect to that library

Follow steps 1 through 4 from Mobile Protect SDK for Android via Maven

Step 3: Start Mobile Protect

This last step will differ from the Maven installation because we are setting it up as a library that will be started from Unity.

You will need to create a class in the library, for example MobileProtectBridge, that has an initialisation function that will then be called using a Unity bridge

public class MobileProtectBridge {
    public void initialize(Activity activity) {
        MobileProtect.init(activity.getApplication(), R.xml.mobileprotect);
    }
}

Step 4: Build the library

Run ./gradlew assembleRelease to build the library, this will generate a .aar file located in your $library/build/outputfolder.

Step 5: Add Mobile Protect dependencies to Unity

In your Assets folder, create a Plugins/Android folder if it doesn’t exist and place the aar file we generated in step 4 in that folder.

In that folder you will need to add 3 overrides to the Unity default gradle config, in player settings > player > android > Publishing settings > build, you will need to tick the 3 boxes like the screenshot below:

That will create 3 new pre-generated files from your existing settings:

baseProjectTemplate.gradle, mainTemplate.gradle and gradleTemplate.properties

In baseProjectTemplate.gradle, you will need to add our private maven repository:

maven {
    credentials {
        //Leave the username as "MAVEN"
        username "MAVEN"
        password "$MOBILEPROTECT_REPO_API_KEY"
    }
    url "https://mobile-protect-repos.securetheorem.com/mobileprotect-android"
}

In mainTemplate.gradle, you will need to add our 2 dependencies:

 dependencies {
    implementation 'com.datatheorem:mobileprotect-android:$VERSION'
    implementation 'com.datatheorem:mobileprotect-transformations:$VERSION'
    [...]
}

The latest $VERSION can be found at Mobile Protect SDK for Android via Maven.

And in gradleTemplate.properties

You will need to add support for AndroidX if it’s not enabled:

android.useAndroidX=true

Step 6: Create the unity bridge class

In your assets/scripts, create a new C# script to call the native library we created previously, and start Mobile Protect:

// Get the unity activity 
AndroidJavaClass unityPlayerJavaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayerJavaClass.GetStatic<AndroidJavaObject>("currentActivity");
// Initialize Mobile Protect
AndroidJavaObject dtpluginObject = new AndroidJavaObject("com.datatheorem.mobileprotect.unitylibrary.MobileProtectBridge");
dtpluginObject.Call("initialize", currentActivity);

Make sure this script is executed when launching your game and you’re ready!

Results

Please visit https://www.securetheorem.com/mobile/protect to see the list of your apps and the state of protection, along with the individual protection item details.

  • No labels