Compiling Qt Android app with Docker

Docker+Qt+Android

Compiling a Qt app for Android requires several dependencies, you need to install Qt, the Android SDK, the Android NDK, ant and so on. If your app uses other Google SDKs you need to install them. Using Docker could simplify the whole setting a lot.

While looking into Continuous Integration for our apps, I found this almost perfect docker container, so I thought I should share it here. This container contains Qt 5.4, the Android SDK and NDK. It almost perfect for my purpose but it lacks some aditionnal SDKs such as the Google Play SDK, so I created one with the SDKs I needed: https://hub.docker.com/r/lasconic/qt/

How to

With a clean Ubuntu 14.04 server

$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
$ sudo sh -c 'echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" >> /etc/apt/sources.list.d/docker.list'
$ sudo apt-get update
$ sudo apt-get -qq install linux-image-extra-$(uname -r)
$ sudo apt-get -qq install docker-engine
  • Get your project source

  • Launch the container with an interactive shell and your source mounted in a volume. Of course, we could run a build script instead of compiling the project manually.

$ sudo docker pull lasconic/qt:5.4-android
$ sudo docker run -i -t -v /home/ubuntu/myqtproject:/source lasconic/qt:5.4-android
  • Compile your project (I use gradle, not ant) and create an APK
mkdir ~/build  
cd ~/build  
qmake -r /source/myproject.pro  
make -j2  
mkdir ~/dist  
make install INSTALL_ROOT=~/dist  
androiddeployqt --input android-libmyproject.so-deployment-settings.json --output ~/dist --name myapp --deployment bundled --gradle --release  

From there, you can upload the APK to Google Play. I use the "Gradle Play Publisher" plugin.