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

« Previous Version 9 Next »

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: ^24.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

  1. Follow steps 1-4 in Mobile Protect SDK for Android via Maven | Installing Mobile Protect SDK with Maven for v23 and above. Please note:

    1. 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 the Maven for v23 and above section of the Android installation instructions.

    2. the settings.gradle of your flutter project is located at android/settings.gradle, while the build.gradle of your flutter project is located at android/build.gradle, both relative to the flutter project root.

Step 3: configure for iOS

  1. 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 and git 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 it

  2. In 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.

Setup callbacks

MobileProtect supports 2 types of callbacks: protections and events. Protection callbacks are triggered before closing the app and event callbacks are triggered on security events.

They can be setup using FlutterMobileProtect.onProtectionCallback((reason) async { TODO(); }); and FlutterMobileProtect.onEventsCallback((reason) async { TODO(); });

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:

  1. 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: ^24.0.0
  2. Remove references to the previous Android installation:

    1. 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
    2. remove any references to mobileprotect and aspectj from the dependencies section of android/build.gradle

  3. 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 using flutter clean and finally rebuilding for iOS.

  • No labels