Docker image for Qt Android builds
I have a small mobile app that I work on from time to time. It is OSS and using Qt. One of the more annoying parts is the creation of the android package(s) for others to testing. This seems like a really nice task for a CI system. Automatic building and running some unit tests for the desktop platform is already done by using the service from travis.com. But for Qt on Android I didn’t find a nice docker image on a quick search. And I did not want to install Qt and Android SDK/NDK all the time. But gitlab.com provides a docker registry as well. I decided to mirror the project on gitlab and and use the registry there. So what I needed was a project to contain the docker image for Qt Android.
As it works pretty nicely you might want to use it as well, or create your own docker image using this example.
The project for the image is here: https://gitlab.com/vikingsoftware/qt5.12.4androiddocker
This image contains everything to build and app with Qt for Android for 32 and 64 bit.
So what’s needed to for that image, and how can it be used?
Three steps are needed:
- Create the configuration/scripts to build a docker
- Build the docker image and store it in the registy
- Use the image from the registry in the app CI
Create the configuration/scripts to build a docker
First you need a Dockerfile, that is used as configuration for you image. It is based on Ubuntu 18.04, and installs Java OpenJDK 8, Android SDK and Android NDK 19c. The SDK is used to install Android platform 28 and 17, as well as the build tools. Finally Qt is installed by calling a small script file. The Qt online installer is used with a configuration script to install Qt 5.12.4 for Android 32/64 bit provided by the Qt company.
Build the docker image and store it in the registy
The next step is to build the docker image. For this, the CI system provided by gitlab is used. All that’s needed is to add a proper .gitlab-ci.yml. This contains the commands to build the image and place it in the container registry of that project. Using this CI method also means, that the image is updated every time you edit the repository. For example for upgrading to a newer version of Qt. Be aware, that the build itself takes about 30 minutes.
Use the image from the registry in the app CI
So what’s left is to use that docker image. The basic steps are described in the project’s README.md file. Set some environment variables. Select the qmake for 32 bit (android_armv7) or 64 bit (android_arm64_v8a). Run make to build it. Install it. And as a last step run androiddeployqt which is provided by Qt.
This all needs to be done in the CI of the app.
In addition in my project I use protected variables in my app repository settings, so I can pass the android keystore file and password to androiddeployqt. So a signed .apk is created to be directly used for the Google app store.