...
Code Block |
---|
plugins { id "com.dtplugin.mobileprotect" version("$VERSION") // if you want to auto update to the latest use: version("+") } |
...
Preface
These instructions will be modifying two different build.gradle
files:
The project
build.gradle
, at the root of the Android Studio project.The app module
build.gradle
, in theapp
directory.
Step 1: Add the Mobile Protect Gradle Plugin
Download the latest release of the SDK from https://www.securetheorem.com/mobile/protect. You will have a zip file containing multiple folders that correspond to the Android Gradle Plugin (AGP) version.
...
Chose the appropriate version corresponding to your project and copy the mobile-protect-gradle-plugin.jar
into your projects folder, for example <project-root>/plugins/mobile-protect-gradle-plugin.jar
.
Declare dependencies within your project’s build.gradle
as follows:
Code Block |
---|
buildscript {
dependencies {
classpath files('PATH_TO/mobile-protect-gradle-plugin.jar')
classpath 'org.aspectj:aspectjtools:1.9.4'
}
} |
Replacing PATH_TO
with the correct path to the plugin jar file, using the example above: PATH_TO=plugins
Step 2: Add the Mobile Protect Maven Repository
The Mobile Protect for Android SDK is hosted on a private Maven repository. To be able to fetch the dependency, you must first register the dependency within your Gradle manifest. Within your project’s build.gradle
file, add:
Code Block |
---|
allprojects {
repositories {
google()
mavenCentral()
# Mobile Protect 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'
}
}
} |
Security Note: To avoid a hard-coded credential within the build.gradle
file, which may be exposed in a VCS, it is recommended to set it up as an environment variable or use the local.properties
file.
Step 3: Configure the Mobile Protect API Key
If you chose to define the API key globally, you can add it to the global Gradle properties in ~/.gradle/gradle.properties
(plaintext file) or in your local.properties
with:
Code Block |
---|
MOBILEPROTECT_REPO_API_KEY={MOBILEPROTECT_REPO_API_KEY} |
Replacing {MOBILEPROTECT_REPO_API_KEY}
with the Mobile Protect API key, which can be found in the mobile_protect_sdk_update_api_key.txt
file from the zip downloaded in step 1. Do not wrap the key in any quote characters.
Note: If you chose the global option, make sure to set the environment variable GRADLE_USER_HOME
to ~/.gradle
.
Step 4: Add the Mobile Protect libraries
Activate the plugin in your App module's build.gradle
file, by adding the following statement after the apply plugin: 'com.android.application'
statement:
Code Block |
---|
apply plugin: 'com.dtplugin.mobileprotect' |
And add Mobile Protect dependencies and an external dependency on Google SafetyNet
Code Block |
---|
dependencies {
// [...] other dependencies
implementation("com.datatheorem:mobileprotect-android:$VERSION")
implementation("com.datatheorem:mobileprotect-transformations:$VERSION")
implementation("com.google.android.gms:play-services-safetynet:18.0.1")
}
|
$VERSION
can be found at the top of this document, note that you can still use v23 dependencies even if you’re using the legacy jar plugin.
Step 5: Add the Mobile Protect configuration
In the Android project, create the xml
directory (/app/src/main/res/xml
) if it does not exist. Then, copy the mobileprotect.xml
config file into the xml
resources folder.
Step 6: Start Mobile Protect
Now you're ready to initialize the SDK. Within your application's main Application class, preferably in the onCreate()
method, add the following initializing code:
Code Block |
---|
MobileProtect.init(this, R.xml.mobileprotect); |
Note: this step should be skipped for ReactNative and Flutter apps
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.