The Mobile Protect SDK for Flutter supports the iOS and Android platforms. This document will take you through the steps to integrate the SDK into your project. For other guides, check out https://datatheorem.atlassian.net/plugins/servlet/servicedesk/customer/confluence/shim/spaces/PKB/pages/1800142885
In order for Mobile Protect Flutter to correctly fetch its dependencies a Mobile Protect API key is needed. If you haven’t received an API key for Mobile Protect, please contact us.
Installation
Some steps are done in the pubspec.yaml
file while some of them are done in the native iOS and Android configuration files.
Step 1: add MobileProtect as a dependency
Mobile Protect is most commonly added as a dependency via pub.dev, in which case the plugin will be fetched automatically. This is the recommended approach. It is also possible to add the dependency via a local copy of the plugin. Please choose only one of the following options:
Option 1: adding Mobile Protect via pub.dev
Add the following entry to the pubspec.yaml
file in your project:
dependencies: //... mobile_protect: ^23.0.0
Note: the latest version of the SDK can be seen here:
Alternatively, you can run the following command in your project’s root folder:
$ flutter pub add mobile_protect
Option 2: adding Mobile Protect via a local copy of the plugin
Download the Mobile Protect Flutter SDK from the Data Theorem portal, unzip it and copy the flutter_mobile_protect
directory to the root of the Flutter project. Then add the following entry to the pubspec.yaml
file in your project:
dependencies: //... mobile_protect: path: flutter_mobile_protect
Alternatively, you can run the following command in your project’s root folder:
$ flutter pub add mobile_protect --path flutter_mobile_protect/
Step 2: configure for Android
Follow steps 1-4 in Mobile Protect SDK for Android via Maven | Installing Mobile Protect SDK with Maven for v23 and above. Please note:
the version of Mobile Protect for Android can and usually does differ from the version of Mobile Protect for Flutter. Thus the version specified in the
pubspec.yaml
may be different from that specified in the gradle build files. Please use theMaven for v23 and above
section of the Android installation instructions.the settings.gradle of your flutter project is located at
android/settings.gradle
, while the build.gradle of your flutter project is located atandroid/build.gradle
, both relative to the flutter project root.
Step 3: configure for iOS
The API key is necessary to access the Podfile upon which Mobile Protect depends. This API key should be added to your netrc file, which will be used automatically by CocoaPods,
curl
andgit
when fetching the SDK.Add the following entry to the file at
~/.netrc
:machine mobile-protect-repos.securetheorem.com password {MOBILEPROTECT_REPO_API_KEY}
Replacing
{MOBILEPROTECT_REPO_API_KEY}
with the Mobile Protect API key.
Please note: this entry should be placed as the first entry in.netrc
, otherwise cocoapods may fail to read itIn the iOS project copy the
MobileProtect.plist
config file into the Flutter project's Xcode project, placing it in the project root, and then add it to your xcode project - see Add Existing Files and Folders to a Project for instructions.
Installation of the SDK is now complete. No initialization of MobileProtect is necessary for flutter as the SDK will be initialized automatically.
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.
Upgrading from earlier versions (prior to v23.0.0)
In order to update the Mobile Protect Flutter version from an earlier version to 23.0.0 or later, the following changes must be made:
update the Flutter plugin version in the project’s
pubspec.yaml
file, or if installing from a local copy of the plugin, update that local copy to the new plugin. For example, we may change:dependencies: //... mobile_protect: ^22.3.14 # OLD VERSION!
to:
dependencies: //... mobile_protect: ^23.0.0
Remove references to the previous Android installation:
remove the old remove the reference to the old android plugin by removing this line from
android/app/build.gradle
:apply plugin: 'com.dtplugin.mobileprotect
remove any references to
mobileprotect
andaspectj
from the dependencies section ofandroid/build.gradle
Follow the steps outlined in the section Step 2: configure for Android above. Note that no changes are necessary for iOS configuration.
Common errors during upgrade
If the following error occurs when running on Android
> A problem occurred configuring project ':app'. > Cannot add task 'aopWeaveDebug' as a task with that name already exists.
The cause is likely that the (new) plugin is correctly applied in android/build.gradle
, but the (old) plugin apply plugin: 'com.dtplugin.mobileprotect'
was not removed from android/app/build.gradle
.
If a pod-related error occrs while running on iOS, such as the following:
Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies. To update the CocoaPods specs, run: pod repo update
it may be necessary to remove the file
ios/Podfile.lock
, then cleaning the project usingflutter clean
and finally rebuilding for iOS.