User Tools

Site Tools


getting_started_iotivity_services_for_android_0_9_1

IoTivity Services: Getting Started for Android

This guide provides instructions and resources to help developers set up the development environment, build the IoTivity stack and build sample applications for Android platform. Developers should also read the IoTivity Programmer’s Guide before starting development to better understand IoTivity architecture and use cases.

Tools and Libraries

The following tools and libraries are necessary to build the IoTivity code in Linux for Android platform. The commands and instructions provided in this section are specifically for Ubuntu LTS 12.04. Open the terminal window and use the following instructions to install all the necessary tools and libraries to build an IoTivity project.

Ubuntu LTS 12.04

Ubuntu LTS version 12.04 is the supported OS for building the IoTivity stack. The instructions may be different for other versions of Ubuntu and Linux.

Git

Git is a source code management software. Git is necessary to gain access to the IoTivitiy source code. Use the following command to download and install git:

  $ sudo apt-get install git-core

SSH

Secure Shell is required to connect to the git repository to check out the IoTivity source code. Secure Shell is typically part of the base operating system and should be included. If for any reason it is not available, it can be installed by running the following command in your terminal window:

  $ sudo apt-get install ssh

SCons

SCons is a build tool used for compiling IoTivity source code. Please refer to the following link to install SCons:
http://www.scons.org/doc/production/HTML/scons-user.html#chap-build-install

Android NDK

Android NDK is a tool required for building IoTivity project for Android platform. Please refer the below links on how to install Android NDK:
http://developer.android.com/tools/sdk/ndk/index.html

Proxy configuration

If you do not need a proxy to access the internet just skip this section.

The gradle proxy setting are configured in $HOME/.gradle/gradle.properties if it does not exists create it.

systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost    
systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=userid
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost

The Andoird build proxy settings are stored in this file: $HOME/.android/androidtool.cfg

http.proxyPort=<YOUR_PORT_NUMBER>
sdkman.monitor.density=108
http.proxyHost=<YOUR_HTTP_PROXY_ADDRESS>
sdkman.show.update.only=true
sdkman.ask.adb.restart=false
sdkman.force.http=true
sdkman.show.updateonly=true

Checking Out the Source Code

Gerrit is a web-based code review tool built on top of the git version control system. Gerrit’s main features are side-by-side difference viewing and inline commenting, streamlining code review. Gerrit allows authorized contributors to submit changes to the git repository after reviews are done. Contributors can have code reviewed with little effort, and get their changes quickly through the system.

The following five steps describe how to check out the source code on the development machine.

Note: skip Step 1 to use existing ssh keys.

Step 1: Create ssh keys

On the terminal, type the following (replace “your name <your_email_address>” with your name and email address):

  $ ssh-keygen –t rsa –C “your_name your_email_address”

For example John Doe with an email address john.doe@example.com would type:

  $ ssh-keygen –t rsa –C “John Doe john.doe@example.com”

After pressing the Enter key at several prompts, an ssh key-pair will be created at ~/.ssh/id_rsa.pub.

Step 2: Upload and register an ssh public key

A. Log in to IoTivity Gerrit.

B. Click on Settings on the top right side as shown here:

C. Click on SSH Public Keys and add key.

D. Open ~/.ssh/id_rsa.pub, copy the content, and paste the content in the “Add SSH Public Key” window.

E. Click Add.

Step 3: Setting up ssh

A. Open ~/.ssh/config in a text editor.

B. Add the following lines:

  Host iotivity gerrit.iotivity.org
  Hostname gerrit.iotivity.org
  IdentityFile ~/.ssh/id_rsa
  User <Insert_Your_Name_Here>
  Port 29418

C. To connect behind the proxy, add the following line after IdentityFile ~/.ssh/id_rsa with the appropriate proxy address and port:

  ProxyCommand nc –X5 –x <proxy-address>:<port> %h %p

Step 4: Verify your ssh connection

Execute the following command in the terminal window:

  $ ssh gerrit.iotivity.org

Upon successful connection, the following message should appear indicating proper ssh and configuration connection.

  ∗∗∗∗    Welcome to Gerrit Code Review    ∗∗∗∗

If the connection is not established, check for the proxy and use the proxy settings described in Step 3.

Step 5: Cloning the project source

To build the IoTivity resource stack:

A. Using your terminal window, browse to the directory where code will be checked out.

B. Execute the following command in the terminal window to clone the oic-resource and oic-utilities repositories:

  $ git clone iotivity:iotivity
  or
  $ git clone ssh://gerrit.iotivity.org/iotivity

This command clones the repository in your current working directory.

Build IoTivity Project for Android Platform using Scons

To run the applications of IoTivity services on Android targets, IoTivity stack should be built for Android platform. SCons tool is used to build for Android platform.

A. Build IoTivity base stack libraries and services libraries using this command. Run the below command in the top directory of IoTivity project.

  $ scons TARGET_OS=android TARGET_ARCH=XXX TARGET_TRANSPORT=IP

Note: XXX can be x86, armeabi, armeabi-v7a, armeabi-v7a-hard.

B. After successful build, user can find the “out” folder having the libraries in the directory where scons command is given.

Build and Run Protocol Plugin Manager Sample Application

Once the IoTivity base stack and services are built for Android, you may follow the steps to run the sample Protocol Plugin Android application. In this context, we assume that the code was cloned into ‘iotivity’ folder.

The path for Protocol Plugin Manager directory is as follows;

  iotivity/service/protocol-plugin/

The protocol-plugin directory includes following sub directories

Directories Description
lib It contains cpluff library used by plugin Manager.
plugin-manager/src It has plugin manager service (.cpp and .h) files.
plugins/Android It is the folder where plugins are located. If we want to add any new plugin it should be located under this folder.
plugin-manager/src/Android It is the sample application for Android.

Pre-requisites

A. Build the iotivity code to get the *.so libraries for Android platform.

B. Download felix.jar from http://felix.apache.org/downloads.cgi

C. Build gearnoti.jar, hue.jar and wemo.jar using a Plug-in project in Eclipse IDE

  1. Create new Plug-in project
    File → New → Other → Plug-in Development → Plug-in Project  select an OSGi framework Equinox → Select No Execution Environment → uncheck Create a plug-in using one of the templates → Finish
  2. Add external libraries
    Properties → Java Build Path  Libraries → Add External JARs → select android.jar, felix.jar, base.jar and the third party JARs corresponding to the plug-in being created as given in the above table.
  3. Create libs folder in the main project folder:
    • Right click on libs folder → Import → General → Archive File → add & select all 3rd party JAR files
    • Delete the automatically generated folder libs/META-INF
  4. Managing MANIFEST.MF file in META-INF folder
    • Be sure to include all packages in Import-Package & Export-Package list on the right hand side.
    • Update class path: Runtime → Classpath → Add… → libs
  5. Coding Activator.java to activate the bundle (JAR)
  6. Codeing EntityHandler.java to handle GET, PUT, POST, DELETE
  7. Create the final JAR
    Right click on project → Export → JAR file → Use existing manifest from workspace → finish
  8. Dexify with gearnoti.jar, hue.jar and wemo.jar
    $ cd $ANDROID_SDK/build_tool/22.0.1 
    $ dx --dex --output=classes.dex $WEMO_JAR
    $ aapt add $WEMO_JAR classes.dex

Build the Android Sample Application

A. Import PPM Sample Application project to Eclipse IDE. Follow the below steps for importing the sample application

  1. File → Import → Android → Existing Android code into Workspace → next → browse
  2. Enter the path for importing:
    iotivity/service/protocol-plugin/plugin-manager/src/Android

B. Add external JARs felix.jar (as explained in Pre-requisites Section) and classes.jar to the Java Build path of the application.
Right click the project in IDE → Properties → Java Build Path → Libraries → Add External Jars → select classes.jar and felix.jar files → OK.

Path for the classes.jar: “(~/iotivity/android/android_api/base/build/intermediates/bundles/release)”

C. Create(if not exist) libs/armeabi/ folder in the above project and copy the below mentioned libraries:

  • libca-interface.so
  • libconnectivity_abstraction.so
  • libexpat.so (Path : “iotivity/dep/android/armeabi/usr/lib”)
  • libgnustl_shared.so
  • liboc_logger.so
  • liboc.so
  • libocstack-jni.so
  • liboctbstack.so

Path for the above libs: “iotivity/android/android_api/base/libs/armeabi”

  • libPluginManager.so
  • libpmimpl.so

Path for the above libs: “iotivity/out/android/armeabi/release”

D. Copy gearnoti.jar, hue.jar, wemo.jar files created previously (refer Pre-requisites section) to the “assets/files” folder of the project.

E. Right click on the project → Build project

Run the Android Sample Application

Right Click the project → Run As → Android Application. This will launch the application on the Android device.

Build and Run Soft Sensor Manager Sample Application

Once the IoTivity base stack and services are built for Android, you may follow the steps to build and execute Soft Sensor Manager and its applications. In this context, we assume that the code was downloaded into ‘iotivity’ folder. The path for Soft Sensor Manager directory is as follows;

  iotivity/service/soft-sensor-manager/

The soft-sensor-manager directory includes following sub directories

Directories Description
build It contains library files and binary files.
SampleApp/android It contains the SSM sample application. The application can be imported into eclipse to build and to run on any android device.
SDK/java It contains the Java SDK APIs for Soft Sensor Manager service.
SSMCore It contains the SSM service codes
SoftSensorPlugin It contains the source codes, for example : soft sensors .
Examples of soft sensors are DiscomfortIndexSensor and IndoorTrajectorySensor.

Built libraries are located in this folder.

  ~/out/android/{TARGET_ARCH}/release

Pre-requisites

1. Sample application (SSMTesterApp) depends on other Linux applications for functionality testing , so build the iotivity project for Linux platform. (refer Readme.scons.txt available in iotivity home directory).

2. Run the Linux THSensorApp & Linux THSensorApp1 to test the SSM functionality.

 Steps to run:	
 - Export LD_LIBRARY_PATH to “<iotivity>/out/linux/<arch>/release”.
 - Run THSensorApp and THSensorApp1 application from the below path: 
   <iotivity>/out/linux/<arch>/release/service/soft-sensor manager/
   
   Note: '<iotivity>' is the path to 'iotivity' project.
   

Build the Android Sample Application

  1. Import SSMTesterApp to Eclipse IDE.
    Follow the below steps for importing the sample application.
    1. File → Import → Android → Existing Android code into Workspace → next → browse
    2. Enter path for importing:
      “~/iotivity/service/soft-sensor-manager/SampleApp/android”

  2. In the assets folder of the project, create a lib folder and inside that copy these two files:
    • libDiscomfortIndex.so
      Path is: “~/iotivity/out/android/armeabi/release”
    • SoftSensorDescription.xml
      Path is : “~/iotivity/service/soft-sensor-manager/SoftSensorPlugin”

  3. Create a 'libs' folder in SSMTesterApp. Inside the 'libs' folder create an 'armeabi' folder.

  4. Copy these libraries to armeabi folder:
    • liboc.so
    • liboctbstack.so
    • libconnectivity_abstraction.so
    • liboc_logger.so
    • libgnustl_shared.so
    • libca-interface.so
    • libocstack-jni.so
    • libSSMCore.so
      Path for libSSMCore is : “~/iotivity/out/android/armeabi/release”
      Path for remaining libraries is : “~/iotivity/android/ android_api/base/libs/armeabi“.

  5. Navigate to ssm folder in the SSMTesterApp application.
    The folder path is: “SSMTesterApp\src\org\iotivity\service\ssm”.

  6. Add these files to the above folder :
    • CoreCOntroller.java
    • DataReader.java
    • IQueryEngineEvent.java
    • IReportReceiver.java
    • ModelData.java
    • QueryEngine.java
    • SSMInterface.java
      Path for these files : “~iotivity/service/soft-sensor-manager/SDK/java/org/iotivity/service/ssm”.

  7. Add External JAR “classes.jar” to the SSMTesterApp application.
    Right Click on the project→ Build Path→ Configure Build Path→ Libraries→ Add External JARs→browse the path of the jar file (“~/iotivity/android/android_api/base/build/intermediates/bundles/release”) select “classes.jar”→Order and Export →select classes.jar→Ok.
  8. Run the application on android device.

Build and Run Things Manager Sample Application

Once the IoTivity base stack and services are built for Android, you may follow the steps to build and execute the sample Things Manager Android application. In this context, we assume that the code was cloned into ‘iotivity’ folder.

The path for Things Manager directory is as following:

  iotivity/service/things-manager/

Pre-requisites

  1. Things Manager Library Project (Things Manager SDK) is needed. Build it using NDK.
    Go to the following path: “~/iotivity/service/things-manager/sdk/java”, and execute the following command to build the libraries (Note: ~PATH stands for path where Android NDK is installed on your machine): $ ~PATH/ndk-build
  2. Import Things Manager application (Things Manager SDK) into eclipse IDE.
    File → Import → Android → Existing Android code into Workspace → next → browse
    1. Enter path for importing:
      “~/iotivity/service/things-manager/sdk/java”
    2. Add Base project jar dependency.
      Right Click on the project→ Build Path→ Configure Build Path→ Libraries→ Add External JARs→browse the path of the jar file (“~/iotivity/android/android_api/base/build/intermediates/bundles/release”) select “classes.jar”→Order and Export →select classes.jar→Ok.

3. The sample applications (Sample and con-server) depend on other Linux applications for functionality testing, so build iotivity project for Linux platform. (refer Readme.scons.txt available in iotivity home directory).

4. Con-server(Linux) and bootstrapserver(Linux) should be running in the same test environment for testing configuration features.

5. Lightserver(Linux) and bookmark(Linux) should be running in the same test environment to test group action features.

Build the Android Sample Application

  1. Import sample application to Eclipse IDE.
    Follow the below steps for importing the TM application.
    1. File → Import → Android → Existing Android code into Workspace → next → browse
    2. Enter path for importing:
      “iotivity/service/things-manager/sampleapp/android/Sample”

  2. Import Con-server application to Eclipse IDE.
    Follow the below steps for importing the TM application.
    1. File → Import → Android → Existing Android code into Workspace → next → browse
    2. Enter path for importing:
      “iotivity/service/things-manager/sampleapp/android/con-server”

  3. Run the applications on android device.

Build and Run Resource Hosting Sample Application

Once the IoTivity base stack and services are built for Android, you may follow the steps to build and execute the Resource Hosting Sample applications. In this context, we assume that the code was cloned into ‘iotivity’ folder.

The path for Resource Hosting directory is as following:

  iotivity/service/resource-hosting/
  

Pre-requisites

  1. “ResourceHosting” Library project is needed. Build it using NDK.
    Go to the following path: “~/iotivity/service/resource-hosting/android/resource_hosting”, and execute the following command to build the libraries (Note: ~PATH stands for path where Android NDK is installed on your machine): $ ~PATH/ndk-build
  2. Import “ResourceHosting” project into eclipse IDE.
    File → Import → Android → Existing Android code into Workspace → next → browse
    1. Enter path for importing:
      “~/iotivity/service/resource-hosting/android/resource_hosting”
    2. Make it library project, if it is not. Right click on the project→properties→Android check the “Is Library”→Apply→ok

Build the Android Sample Application

  1. Import SampleProvider App to eclipse IDE.
    Follow the below steps for importing the sample application.
    1. File → Import → Android → Existing Android code into Workspace → next → browse
    2. Enter the path for importing: iotivity/service/resource-hosting/SampleApp/android/SampleProviderApp
    3. Add Base project jar dependency.
      Right Click on the project→ Build Path→ Configure Build Path→ Libraries→ Add External JARs→browse the path of the jar file (“~/iotivity/android/android_api/base/build/intermediates/bundles/release”) select “classes.jar”→Order and Export →select classes.jar→Ok.
    4. Add android-support-v4 jar
      Right Click on the project→ Build Path→ Configure Build Path→ Libraries→ Add External JARs→browse the path of the jar file (“~\sdk\extras\android\support\v4”) select “android-support-v4.jar”→Order and Export →select android-support-v4.jar→Ok.
  2. Import SampleResourceHosting App to eclipse IDE.
    Follow the below steps for importing the sample application.
    1. File → Import → Android → Existing Android code into Workspace → next → browse
    2. Enter the path for importing: iotivity/service/resource-hosting/SampleApp/android/SampleResourceHosting
    3. Add Base project jar dependency.
      Right Click on the project→ Build Path→ Configure Build Path→ Libraries→ Add External JARs→browse the path of the jar file (“~/iotivity/android/android_api/base/build/intermediates/bundles/release”) select “classes.jar”→Order and Export →select classes.jar→Ok.
  3. Import SampleConsumer App to eclipse IDE.
    Follow the below steps for importing the sample application.
    1. File → Import → Android → Existing Android code into Workspace → next → browse
    2. Enter the path for importing: iotivity/service/resource-hosting/SampleApp/android/SampleConsumer
    3. Add Base project jar dependency.
      Right Click on the project→ Build Path→ Configure Build Path→ Libraries→ Add External JARs→browse the path of the jar file (“~/iotivity/android/android_api/base/build/intermediates/bundles/release”) select “classes.jar”→Order and Export →select classes.jar→Ok.
  4. Run all three application on android devices.

getting_started_iotivity_services_for_android_0_9_1.txt · Last modified: 2015/10/08 07:48 by Jay Sharma