Skip to content

[Android Things] Using a local version of Mraa to build Upm for Android Things

Nicolas Oliver edited this page Oct 11, 2017 · 4 revisions

This wiki is an step-by-step guide on how to modify the default Docker image that builds Upm for Android Things, in order to use a local version of Mraa.

Initial Setup

Note: for the example, this wiki will use some specific folders, you should change them to your proper folders to make this work.

The Docker image that builds Android Things has an Mraa repository in it. This Mraa repository is also built for Android Things, so Upm can just use that to build. But if for any reason you need to use a local version of Mraa to build Upm Android Things Packages, you can do:

  1. Clone the Mraa repository in i.e /home/user/mraa
$ cd /home/user
$ git clone https://github.com/intel-iot-devkit/mraa.git
$ cd mraa
  1. Build Mraa for Android Things
$ docker-compose run android

# After some time, mraa will be installed in /home/user/mraa/install
$ ls install/
bin  include  lib  share
  1. Clone the Upm repository in /home/user/upm
$ cd /home/user
$ git clone https://github.com/intel-iot-devkit/upm.git
$ cd upm
  1. Change docker-compose.yaml, mount your local Mraa repository into the container:
  android:
    extends: java
    image: inteliotdevkit/upm-android
    environment:
      - BUILDTESTS=OFF
    command: bash -c "./scripts/build-android.sh"
    volumes:
      # Using a global path
      - /home/user/mraa:/opt/mraa
      # You can also use a relative path
      # - ./../mraa:/opt/mraa
  1. Modify /home/user/mraa/install/lib/pkgconfig files to point to mraa install folder inside the container. This is mandatory to allow cmake to find mraa files:
# Go to Mraa repository
$ cd /home/user/mraa

# Modify install/lib/pkgconfig/mraa.pc
$ sudo sed -i 's$/usr/src/app/install$/opt/mraa/install$' install/lib/pkgconfig/mraa.pc 

# Modify install/lib/pkgconfig/mraajava.pc
$ sudo sed -i 's$/usr/src/app/install$/opt/mraa/install$' install/lib/pkgconfig/mraajava.pc

# In both files, prefix property should be /opt/mraa/install
# prefix=/opt/mraa/install
  1. Build Upm for Android Things
$ cd /home/user/upm
$ docker-compose run android

Updating Mraa code for upm builds

After you did the initial setup, you can keep building new versions of libmraa, and use it to re-build upm modules for Android Things.

This is a short example on how to achieve this:

  1. Modify a source file in Mraa repository
# Go to Mraa repository folder
$ cd /home/user/mraa

# Modify a file
$ nano CmakeLists.txt
  1. Execute Step 2, 5 and 6 from the Initial Setup

Building Docker images locally

If you don't want to use the Docker Images already published in Docker Hub, you can also build the images in your development host. This is useful when you need to make changes to the Docker build environment as well, like installing new versions of Android NDK or Android Things Native library. The step by step process to achieve this is:

  1. Clone inteliotdevkit/docker-image-builders repository:
$ cd /home/user
$ git clone https://github.com/intel-iot-devkit/docker-image-builders.git
  1. Do any modifications to the Dockerfiles for Base Docker Image, or the specific Android Docker Image:
$ cd /home/user/docker-image-builders

# Base Mraa Image
$ nano mraa/Dockerfile.base

# Base Upm Image
$ nano upm/Dockerfile.base

# Android Mraa Image
$ nano mraa/Dockerfile.android

# Android Upm Image
$ nano upm/Dockerfile.android
  1. Build the new image, including the updated configuration from step 2:
$ cd /home/user/docker-image-builders

# Build Mraa Images
$ docker-compose build mraa-base
$ docker-compose build mraa-android

# Build Upm Images
$ docker-compose build upm-base
$ docker-compose build upm-android

# You just need to build what you modify! it is not required to build everything from scratch. 
  1. Now you have the required Docker images in your local registry. You can use them to execute the Initial Setup or Updating Mraa code for upm builds process.
$ docker images 

REPOSITORY                      TAG                      IMAGE ID            CREATED             SIZE
inteliotdevkit/upm-base         latest                   ab8a76968e0b        seconds ago         1.726 GB
inteliotdevkit/upm-android      latest                   2b55de66d20f        seconds ago         4.418 GB
inteliotdevkit/mraa-base        latest                   75cb2d5f7c92        seconds ago         1.726 GB
inteliotdevkit/mraa-android     latest                   4bc00da25086        seconds ago         4.418 GB