This section explains the steps to build the IoTivity project for Android.
This section assumes that you have completed the steps in "How to use IoTivity Gerrit" .
|System Variables||Description||Default Path (if they are not set)|
|GRADLE_HOME||Path to Gradle||GRADLE_HOME=<iotivity>/extlibs/android/gradle|
|ANDROID_NDK||Path to Android NDK||ANDROID_NDK=<iotivity>/extlibs/android/ndk|
|ANDROID_HOME||Path to Android SDK||ANDROID_HOME=<iotivity>/extlibs/android/sdk|
To install and verify OpenJDK 1.7 or later on Ubuntu, perform the steps shown below. The examples shown are for installing OpenJDK 1.7.
$ sudo apt-get update $ sudo apt-get install openjdk-7-jdk
$ java -version
java version "1.7..."
<iotivity>to refer to the root directory of the IoTivity project.
$ scons TARGET_OS=android
This builds IoTivity for Android using the default values for architecture, transport, mode, and security.
In addition to
TARGET_OS , the following command-line argument options can be passed to the SCons build script to build IoTivity for Android:
|TARGET_TRANSPORT||Supported transport types:|
|Note: You may also build permutations of the above options by passing a comma-separated list.|
|RELEASE||Supported release modes:|
|1 (release mode) (default)|
|0 (debug mode)|
|SECURED||Supported security modes: DTLS (Datagram Transport Layer Security)|
|1 (DTLS enabled) (default)|
|0 (DTLS disabled)|
|ANDROID_HOME||This takes the path to the Android SDK (if installed). If not, the SCons script will try to install Android SDK.|
|ANDROID_NDK||This takes the path to the Android NDK (if installed). If not, the SCons script will try to install Android NDK.|
|ANDROID_GRADLE||This takes the path to the Gradle bin (if installed). If not, the SCons script will install Gradle.|
The SCons build command including all the optional arguments for building IoTivity for Android might look like the example shown below:
$ scons TARGET_OS=android TARGET_ARCH=<target arch> TARGET_TRANSPORT=<target transport> RELEASE=<release mode> SECURED=<secure> ANDROID_HOME=<path to android SDK> ANDROID_NDK=<path to android NDK> ANDROID_GRADLE=<path to gradle/bin>
The basic command shown in Step 2 creates the binary distribution of the IoTivity Base Android API.
The output directory of the IoTivity Base Android API (
.aar file) build is:
The above command also builds all the android example apps.
The output directory for each example APK can be found at:
<iotivity>/java/android-examples/<example name>/build/outputs/apk/<example name>-<release mode>.apk
Note: for convenience, a script (auto_build.sh) is provided to run possible build at once. Following is the usage:
$ auto_build.sh <path-to-android-ndk>
$ auto_build.sh -c
If you see the following build error message :
The Android SDK Manager should automatically come up as follows:
Note: If the Android SDK Manager does not automatically come up make sure you are physically building on your development system or vnc into your system. The GUI will not pop up if you are just “ssh” into development system.
Just as the instructions say the Android SDK Manager GUI appears:
1. Under "Tools" select "Android SDK Build-tools" Revision 20. 2. Under "Android 5.0.1 (API 21)" select "SDK Platform"
After selecting the correct packages click on the “Install 2 Packages…” button and the following license dialogue box will come up:
Accepted all the licenses and click on the “Install” button. All the packages will install and the following Android SDK Manager Log dialogue box will come up when done.
You can now close Android SDK Manager Log and Android SDK Manager Application.
Note: If you installed the correct packages required the build system that build will continue on with the build and is one time set-up requirement as you do not delete the the android directory (i.e. gradle, ndk, and/or sdk directories).
After the IoTivity Base Android API and the example apps have been built, you can run the example apps on either the emulator or an android device.
The example android apps that you built in Step 2 can be found at:
<iotivity>/java/examples-android/<example name>/build/outputs/apk/<example name>-<release mode>.apk
Note : Iotivity main code build architecture and target emulator or an android device architecture should be same.
Below have possible architecture of apk files.
Below is a list of the android example apps. Most of the apps come in client-server pairs and need to be run together; note that the server apps should be started before the client apps.
|SimpleServer and SimpleClient||A basic sample for hosting, discovering and performing GET, PUT, POST and OBSERVE operations on a resource. We recommend that you start with these two apps.|
|DeviceDiscoveryServer and DeviceDiscoveryClient||Samples for the Platform and Device Discovery APIs.|
|FridgeServer and FridgeClient||Fridge samples provide usage of constructResourceObject API.|
|FridgeGroupServer and FridgeGroupClient||FridgeGroup samples provide usage of constructResourceObject API, default device entity handler and header options support.|
|GroupServer and GroupClient||Example for demonstrating grouping resources into collections, discovering them and performing operations on them.|
|PresenceServer and PresenceClient||Presence samples to demonstrate the usage of the Presence APIs.|
|ProvisioningClient||Example for demonstrating Provisioning Manager|
Android example apps can be run on Android Lollipop (5.0 and above). If running on an android device, please perform the following steps:
$ adb devices
adb can be found at
<path to Android sdk>/platform-tools.
You should see something similar to the following output:
List of devices attached 5C7DJ06J
After your device is listed, you can install any example app APK on the device and run it.
$ adb install <iotivity>/java/examples-android/<example_name>/build/outputs/apk/<apk name>
For example, assuming the APK location hasn't been changed, run the following command to install the simpleserver app APK on the device:
$ adb install <iotivity>/java/examples-android/simpleserver/build/outputs/apk/simpleserver-release.apk
This section lists the steps to use the binary distribution of the IoTivity Base Android API in an Android Studio project.
The binary distribution of the IoTivity Base Android API (a .aar file) that you built previously can be found at:
<iotivity>/java/iotivity-android/build/outputs/aar/iotivity-base-<your arch>-<release mode>.aar
To import IoTivity Base Android API module into an existing Android Studio project, skip to Step 4.
To generate JavaDocs for the Android API, do the following:
<iotivity> $ cd resource/docs
This creates a Java_API directory to contain the JavaDocs for Android API in the current directory.
index.htmlfile inside Java_API for explanation of the Android API.
This concludes the procedures.