Hello World

This page presents a simple guide on how to use MpOS API with Android platform.

Technologies used in this guide:

  • Eclipse Platform 4.2.1v with ADT 23.0.x
  • Oracle Java SDK 8.x (for any OS)
  • Android SDK installed (API 19 or above)

1) Create an Android project (or download and import a simple Calculator project on this link)

2) Download the MpOS source code: Download Page

3) Import Android components on Eclipse ADT

  1. Import -> Android -> Existing Android Code Into Workspace
  2. Browse the path where the project is located. Choose ‘/android’ and click on ‘OK’ button
  3. Select the ‘MpOS API’ project to import and click on ‘Finish’ button (You will see the project on your Eclipse workspace)
  4. Update the target Android version for each project: Properties -> Android -> Selected “Target Name: Android 4.x” and click on ‘OK’ button.

4) Configure the Calculator project (called “Hello”) to use MpOS API

  • The first step is to add MpOS API project as a library of Hello (associating the two projects).
    • Selected the “Hello” project. Go to Properties -> Android -> Add…
    • Selected the “MpOS API” project and click on “OK” button
  • The second step is to configure the interfaces where the methods that will be offloaded were defined. MpOS requires the use of interfaces, once MpOS API needs to intercept all methods which are called from this interface in order to decide whether or not to perform an offloading operation.
    • Use the @Remotable annotation to identify the methods that can be offloaded on the Calculable.java file.
    • The figure below shows the @Remotable annotation being used to configure the sum and multiplication methods as candidates for offloading.

annotation

  • The third step is to configure the main activity of Hello to start MpOS.
    • On MainActivity.java, use @MposConfig annotation to define the MpOS framework settings.
    • Use the @Inject annotation above the Calculable object instantiation. Such annotation permits MpOS to intercept the methods defined in the Calculable interface.
    • Use “onCreate()” and “onDestroy()” methods of the MainActivity to start and stop MpOS.
    • The figure below shows the aforementioned steps.

activityNote: You can configure the Cloudlet IP address manually using the property “endpointSecondary”  on @MposConfig. This feature is necessary when the Wi-Fi network does not support/allow multicast.

  • Before generating the final .apk file, the developer needs to generate a “jar” file based on the project.
    • Selected the “Hello” project. Go to Export -> Java -> JAR File.
    • Selected ONLY “src” folder.
    • Selected the item “Export generated class files and resources”.
    • Select the export destination: <your_project>/assets/dep (create the folder if “dep” does not exist) and click on “OK”.

Note: The developer needs update the jar file for each source code change. The framework can handle different versions of the application, but to do that, the developer needs to change the projects “version name”, in AndroidManifest.xml file. This jar file will be transferred to remote server automatically by MpOS.

  • Finally, run the mobile application on your mobile device and make sure the “MpOS Platform” is already running on the Cloudlet (see First steps page for more details).