From time to time, the need for reproducible builds arises. To ensure this, every software involved in the build process must have the same version. A way to achieve such a result is to use a standard Docker image. I will describe the process of building the Androdi GPSLogger app.

Before beginning the build you need to download and install Docker. In this link, by clicking in the left sidebar, you will find all the detailed instructions to install Docker on your platform.

After the installation is complete you can type this command

docker -- version

If everything is installed and running you will get a message like

Docker version 27.3.1, build cel2230

For this tutorial, I used Docker Desktop for Windows but you can use Docker on a different platform. (Linux uses ‘ and windows likes”)

To get our base environment, based on Ubuntu 22.04 OS, we will use a well-known Docker image, it’s called the mingc Android build box.

To get the image we type the following command at the command prompt.

docker pull mingc/android-build-box:latest

This command tells to Docker to retrieve the mingc/android-build-box image from the online Docker Hub, “latest” is a “tag” and instructs Docker to pull the latest version available. If you check on the hub image page you will find that it is possible to have different pulls based on the “tag”, different tags correspond to different software releases. This tutorial is based on the “latest” image.

After the command is issued the image will be downloaded to your system in a few minutes. Now we are ready to start playing with Docker.

For your convenience, you can download now DockerTutorialScript.sh bash script that contains the commands to run inside our Docker container. Copy the script to your document folder, in my case “Documenti”.

From now on we will work with two command consoles. We change the path of the console on the right by typing cd Documenti (or cd to where you downloaded DockerTutorialScript.sh),

Type this command in the left console

docker run -v "Basic":/project -it mingc/android-build-box bash -l

This command instructs Docker to create a container for mingc/android-build-box image with a volume called Basic, furthermore, it specifies an iterative session with -l switch.

On the right console we issue the command

docker cp ./DockerTutorialScript.sh mingc/android-build-box bash:/project/DockerTutorialScript.sh

This command copies the downloaded script to the container, project folder. We need the file so we can run a series of commands into the Docker container. Let’s have a look at the script file

At line 2 we decide to exit the script at the first error (command exit code not equal to zero breaks the script). Line 3 retrieves the latest release of GPSLogger code from the official Github repo. Line 4 change the current directory to GPSLogger. Line 5 launches the Gradle build. Line 6 generates an example key to sign the generated apk. Line 7 go to the folder where is stored the generated apk. Line 8 ensure that apk (that is a zip file) is, broadly speaking, correctly compressed/formated. Line 9 and line 10 provide apksigner installation. Line 10 sign the just build apk file.

So to complete the build and sign the apk type the following command into the left console

bash DockerTutorialScript.sh

The script will download and install all the necessary files

During the execution you will be asked for information, it is necessary to create a new key to sign the apk. If during a second script run you want to use your .jks release key remove line 6 and copy your file to the container, check/change the path in line 11.

With the same procedure, you can build your Android app within a Docker container. Remember that you can customize the Docker image with tags, that is handy.