Mistake on this page? Email us

Setting up the Android Package Kit (APK)

You can use the SDA SDK in Android applications to implement an SDA technician application that logs into Pelion Device Management, requests an access token and then connects to the IoT device to instruct it to perform the requested operation.

To include the secure device access SDK as a library in your project and build the APK:

  1. Clone the SDA SDK GitHub repository to your computer.

  2. To connect to Device Management, you must provide your application with the Device Management base URL, your device's endpoint name or device ID and your account ID by editing the arm-sda-android/app/src/main/res/values/properties.xml file:

        <string name="env_url">https://api.us-east-1.mbedcloud.com</string>
        <string name="account_id">Your account ID goes here</string>
      <string name="device_ep">Paste your device endpoint name from the developer certificate</string>


    • env\_url is the Device Management base URL (this URL is different only if you have Device Management on-premises).
    • account_id is your account ID, which you can see in Device Management Portal by selecting Team configuration > Team profile from the side menu.
    • device_ep is the device endpoint name, which you can see in the mbed_cloud_dev_credentials.c file you downloaded earlier.
    **Notes about endpoint name:**
    For the convenience of the demo and for development purposes, you can provide a default endpoint name in the `arm-sda-android/app/src/main/res/values/properties.xml` file, as described above. You can also use tools such as [Android Debug Bridge (adb)](https://developer.android.com/studio/command-line/adb) to supply long names to the application. In the field, a technician would enter the endpoint name in the SDA technician application or use the device ID if the device has bootstrapped. Bootstrapping the device enables you to associate custom properties to the device, such as assigning the device to a region to which a certain policy applies.
    In the `mbed_cloud_dev_credentials.c` file, note the device endpoint name in the following line: `const char MBED_CLOUD_DEV_BOOTSTRAP_ENDPOINT_NAME[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";`.
    When you run the demo application on your device, only the first 15 characters are shown because of display limitations. The actual device endpoint name that you must always use is the **full value** above.
  3. Make sure JAVA_HOME points to the Java JDK:

    • Windows:

      set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_131
    • Linux:

      export JAVA_HOME=/usr/lib/java/jdk1.8.0_131
    • Mac: If /usr/libexec/java_home exists:

      export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
  4. Make sure ANDROID_HOME points to the Android SDK (for information about Android SDK download, installation and supported versions, see Working environment requirements):

    • Windows:

      set ANDROID_HOME=C:\Users\<user>\AppData\Local\Android\Sdk
    • Linux:

      export ANDROID_HOME=/usr/lib/android/sdk
    • Mac:

      export ANDROID_HOME= ~/Library/Android/sdk/

      Note: During the installation process, the Android installer tells you where the SDK is.

  5. Navigate to arm-sda-android:

    cd arm-sda-android
  6. Run the following command:

    gradlew clean build -x test -x check

    The Android application file is arm-sda-android/app/build/outputs/apk/debug/app-debug.apk.

Install the APK on the Android device

There are multiple ways to install applications on an Android device. We suggest:

  1. Enable Unknown sources in the settings of your Android device. This is typically under Lock screen and security.
  2. Connect the Android device to the PC using a USB cable. On a Mac, the Android device does not show up automatically as a USB mass storage device; therefore, you must install an application to copy files from your Mac to the Android device.
  3. Copy the APK file (arm-sda-android/app/build/outputs/apk/debug/app-debug.apk) to your Android device.
  4. If you have a previous version of the APK on your Android device, uninstall it.
  5. On your Android device, use a file manager to find the file you just copied, and click to install it.