Search by Tags

How to Setup Android Build Environment Using Docker

 
Applicable for

Article updated at 20 Sep 2019
Subscribe for this article updates

Introduction

Building Android from source for the first time can be a tough task, depending on how much knowledge you have about it. For instance, if you look at the Android documentation on Establishing a Build Environment, dependencies are only solved for specific versions of Ubuntu LTS up to 14.04 (as of September 2019).

Using Docker to build Android is a fast and easy way to have a development environment set up. This article is a collection of remarks on how setup a build environment for building the Android Evaluation BSPs provided by Kynetics, validated only for their release of Android 9.0.0 (Pie) for the Toradex Apalis iMX8QM V1.0B. The build steps are bundled with the Kynetics source-code, therefore the actual build instructions are omitted.

There are probably several ways to build Android using different Docker containers as base. This article only describes one of them.

This article complies to the Typographic Conventions for Torizon Documentation, even though it isn't a Torizon-specific article.

Prerequisites

Build a Docker Image

Build a Docker image with all the pre-requisites for the Android cross-compilation. Below is presented a sample Dockerfile in a collapsible section:

Sample Dockerfile

To build the Docker image:

$ docker build -t android-build-env .

Download the Android Source-code

Follow the instructions provided in the document Kynetics Android BSP - Getting Started Guide that comes with the Kynetics source-code bundle.

Run a Docker Container

Run an instance of the Docker image. Bind-mount the directory where the Android source-code bundle is in your computer to /android-build. See the example below:

cd <path to directory where you download the Kynetics source-code bundle >
$ docker run --rm -it -v ${PWD}:/android-build android-build-env bash

A Bash session inside the container will start in your current shell.

Build Android

Follow the build instructions provided in the document Kynetics Android BSP - Getting Started Guide that comes with the Kynetics source-code bundle.