Adding the IBM MobileFirst Platform Foundation SDK to a new or existing application with Android Studio
Before you begin
About this task
Procedure
- If you do not already have one, create an Android application in Android Studio.
- Ensure that you have JCenter as one of
the repositories that your application uses to look for dependencies. Edit the build.gradle file, usually at
the root of the Android project, by adding jcenter() to
the list of repositories in the allprojects{} closure.
The following example shows a sample build.gradle file:allprojects { repositories { jcenter() // other repositories } }
The actual contents of your file can vary, depending on if you add other repositories or dependencies.// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.1.3' } } allprojects { repositories { jcenter() } }
- Edit the build.gradle file under your
app/module to add the IBM MobileFirst Platform Foundation SDK
to your compile scope dependencies. Add the following lines
under your dependencies:
compile group: 'com.ibm.mobile.foundation', name:'ibmmobilefirstplatformfoundation', version:'7.1.0.0', ext: 'aar', transitive: true
- Add the following packaging options under your android{} closure
in the build.gradle file:
The following example shows the final app/build.gradle file:packagingOptions { pickFirst 'META-INF/ASL2.0' pickFirst 'META-INF/LICENSE' pickFirst 'META-INF/NOTICE' }
apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion "21.1.2" defaultConfig { applicationId "com.ibm.test" minSdkVersion 10 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } packagingOptions { pickFirst 'META-INF/ASL2.0' pickFirst 'META-INF/LICENSE' pickFirst 'META-INF/NOTICE' } dependencies { compile group: 'com.ibm.mobile.foundation', name:'ibmmobilefirstplatformfoundation', version:'7.1.0.0', ext: 'aar', transitive: true // other dependencies } }
- Add a wlclient.properties file under the app/src/main/assets folder. Create the asets folder if it does not exist. This file is created when you deploy your native Android application to the MobileFirst Server and is in the same folder as the native Android application descriptor. For more information about the wlclient.properties file, see Client property file for Android.
- Optional: If push notification is used, follow
these steps.
- Copy the push.png file from the Native API application.
- In the res folder of your native app for Android, identify the folders with a name that starts with drawable, such as res/drawable or res/drawable-ldpi. Paste the push.png file into each of these folders.
- For more information about how to set up Google Play Services in your Android project, see Adding Google Play services to your Android project.
- Add the following lines to the AndroidManifest.xml file
of your native app for Android:
- <activity android:name="com.worklight.wlclient.ui.UIActivity"
/>
This line adds the ability for a designated MobileFirst UI activity to run in the user application.
- <uses-permission android:name="android.permission.INTERNET"
/>
This line adds internet access permissions to the user application.
- <uses-permission android:name="android.permission.GET_TASKS"
/>
This line adds the permission to get a list of running tasks that are used for the heartbeat functions.
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"
/>
This permission is required if you are targeting your apps for Android API level 13 and earlier.
- <activity android:name="com.worklight.wlclient.ui.UIActivity"
/>
- Optional: If push notification support is used,
add the following permissions to the AndroidManifest.xml file
of your native app for Android.
<uses-permission android:name="com.worklight.androidnativepush.permission.C2D_MESSAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- Optional: If app authenticity is required follow
the following steps.
- Copy the armeabi, armeabi-v7a, mips, and x86 folders (subfolders of the Native API application folder) into the app/libs folder. These folders each contain a version of the libauthjni.so file.
- Find the build.gradle file in the main project folder and add this to the android section: sourceSets { main { jniLibs.srcDirs = ['libs'] } }.
- Rebuild your application.
Results
Parent topic: Methods of setting up your environment