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.
Note: MobileFirst SDK
is compatible with Android version Ice Cream Sandwich (API level 14)
and later.
About this task
The documented and supported development environment for
Android applications with MobileFirst SDK
is now Android Studio. To develop a new Android application with Android
Studio and MobileFirst SDK,
follow these steps.
Procedure
- If you do not already have one, create an Android application
in Android Studio by using File > New > New Project wizard.
Make sure the project compiles without error.
Note: There
are two versions of the build.gradle file created,
one in the main project folder and one in the \apps folder.
- Make sure the [project]\build.gradle file
has the jcenter() in list of repositories in the allprojects{} closure.
allprojects {
repositories {
jcenter()
// other repositories
}
}
The following example shows a sample [project]\build.gradle file
created by the Android Studio wizard:// 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.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The actual contents of your file can vary, depending
on whether other repositories or dependencies have been added.
- Add the following packaging options within your android{} closure
in the app\build.gradle file:
packagingOptions {
pickFirst 'META-INF/ASL2.0'
pickFirst 'META-INF/LICENSE'
pickFirst 'META-INF/NOTICE'
}
- Depending on whether you are installing aar files
from a local copy or accessing them remotely, add the following lines
to your app\build.gradle file.
- If you are installing from remote copies of the files
add this line to the dependencies closure.
compile 'com.ibm.mobile.foundation:ibmmobilefirstplatformfoundation:8.0.+'
Note: In this example the latest version of
8.0 is
imported. If you want to import a specific version such as
8.0.2016021411,
replace with the
MobileFirst version
number you are using, including the major, minor, and patch numbers.
The patch number is in the format
YYYYMMDDHH. For example:
compile 'com.ibm.mobile.foundation:ibmmobilefirstplatformfoundation:8.0.2016021411'
The
following is an example of an
app/build.gradle file
for adding the SDK from remote files:
applyplugin: 'com.android.application'
repositories {
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.myname.myapplicationandroidgradle"
minSdkVersion 23
targetSdkVersion 23
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 'com.ibm.mobile.foundation:ibmmobilefirstplatformfoundation:8.0.+'
}
}
- Remove the proguardFiles line from
the buildTypes enclosure and save the file. Proguard
is not supported in IBM MobileFirst™ Platform Foundation V8.0.0.
See Obfuscating
Android code with ProGuard.
- If you are installing from local files:
Add the following to the dependencies
closure.
compile(name:'ibmmobilefirstplatformfoundation', ext:'aar')
Add
a repositories
enclosure:
repositories {
flatDir {
dirs 'libs'
}
}
The following is
an example of an app\build.gradle file for adding
the SDK from local files:apply plugin: 'com.android.application'
repositories {
flatDir {
dirs 'libs'
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.myname.myapplicationandroidgradle"
minSdkVersion 23
targetSdkVersion 23
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(name:'ibmmobilefirstplatformfoundation', ext:'aar')
}
- The imported SDK does not include the Javadocs. To add
the Javadocs to your project see Registering Javadocs to an Android Studio Gradle project.
- For information on adding additional features see Adding the optional MobileFirst components with Gradle.
- Add the following lines to the AndroidManifest.xml file
of your native app for Android:
- Rebuild your application.
Results
You can now start developing your native Android application
with the
IBM MobileFirst Platform Foundation SDK.
What to do next
Before you can access server resources, you must register
your app. See
Registering Android applications from the MobileFirst Platform CLI.
For details about the
mfpclient.plist file see
Android client properties file. Once the
app is registered you can write some initial code for testing the
server connection (
Some initial code for accessing the server.