Adding the IBM MobileFirst Platform Foundation SDK to a new or existing application with Android Studio

Before you begin

Ensure that you set up Android Studio and the Android SDK properly. For more information about how to set up your system, see Android Studio Overview.

About this task

The official development environment for Android applications is now Android Studio. To develop a new IBM MobileFirst™ Platform Foundation native Android application with Android Studio, follow these steps to prepare your application to use the IBM MobileFirst Platform Foundation SDK.

Procedure

  1. If you do not already have one, create an Android application in Android Studio.
  2. 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.
    allprojects {
      repositories {
        jcenter()
        // other repositories
      }
    }
    The following example shows a sample build.gradle file:
    // 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()   
      }
    }
    The actual contents of your file can vary, depending on if you add other repositories or dependencies.
  3. 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
  4. Add the following packaging options under your android{} closure in the build.gradle file:
    packagingOptions {
      pickFirst 'META-INF/ASL2.0'
      pickFirst 'META-INF/LICENSE'
      pickFirst 'META-INF/NOTICE'
    }
    The following example shows the final app/build.gradle file:
    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
      }
    }
  5. 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.
  6. Optional: If push notification is used, follow these steps.
    1. Copy the push.png file from the Native API application.
    2. 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.
    3. For more information about how to set up Google Play Services in your Android project, see Adding Google Play services to your Android project.
  7. 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.

  8. 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" />
  9. Optional: If app authenticity is required follow the following steps.
    1. 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.
    2. Find the build.gradle file in the main project folder and add this to the android section: sourceSets { main { jniLibs.srcDirs = ['libs'] } }.
  10. Rebuild your application.

Results

You can now start developing your native Android application with the IBM MobileFirst Platform Foundation SDK.