The Mobile Protect SDK has a dedicated integration for iOS and Android apps built using Flutter. This document will take you through the steps to integrate the SDK into your build system. For other guides, check out Mobile Protect Installation Guides
To fetch the Mobile Protect SDK via Flutter, an API key is needed. If you haven’t received an API key for Mobile Protect, please contact us.
Preface
This will involve some steps on the Flutter side as well as some steps on both iOS and Android.
Flutter Integration
Step 1
Download the SDK from the Mobile Protect in the Portal.
Step 2
Copy the flutter_mobile_protect
directory to the root of the Flutter project.
Step 3
Add flutter_mobile_protect
as a dependency in your pubspec.yaml file:
$ flutter pub add flutter_mobile_protect --path flutter_mobile_protect/
The project’s pubspec.yaml
should then contain the following entry:
dependencies: flutter_mobile_protect: path: flutter_mobile_protect
Step 4
In your main.dart
file
Import the Mobile Protect for Flutter library:
import 'package:flutter_mobile_protect/flutter_mobile_protect.dart';
Add the following initialiser method:
Future<void> initMobileProtect() async { try { await FlutterMobileProtect.init; } on PlatformException { print("Failed to initialize"); } }
Call
initMobileProtect()
when initialising your main App widget.
Android Integration
Step 1: Add the Mobile Protect Gradle Plugin
Declare dependencies within your project’s build.gradle
as follows:
buildscript { dependencies { classpath files('../flutter_mobile_protect/android/mobileprotect/gradle{VERSION}+_plugin/mobile-protect-gradle-plugin.jar') classpath 'org.aspectj:aspectjtools:1.9.4' } }
Note: replace {VERSION}
with one of the provided versions in the SDK that matches the version of Gradle your project is using.
Step 2: Activate the Plugin
Activate the plugin in your App module's build.gradle
file, by adding the following statement after the apply plugin: 'com.android.application'
statement.
apply plugin: 'com.dtplugin.mobileprotect'
Step 3: Add the Mobile Protect configuration
In the Android project, create the xml
directory (flutter_app/android/app/src/main/res/xml
) if it does not exist. Then, copy the mobileprotect.xml
config file into the xml
resources folder.
iOS Integration
In the iOS project copy the MobileProtect.plist
config file into the Flutter project's Xcode project, place it in the project root. See Add Existing Files and Folders to a Project for instructions.
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.