Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

...

Code Block
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 for these files:

  • Custom Main Gradle Template

  • Custom Base Gradle Template

  • Custom Gradle Properties Template

To do it, go to player settings > player > android > Publishing settings > build, you will need to then tick the 3 corresponding boxes like the screenshot below:

...

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:

...

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.