Docker Image for Qt Development and Continuous Integration for Linux and Android


Sometimes I need to have specific versions of Qt to build apps and run CI tasks. In this article I introduced what I used for this purpose: a multi-arch docker image containing a build of Qt to build Qt apps on arm64 or amd64 and run the app itself (useful to run unit tests for instance). I’ve been using these images to run builds and unit tests with GitLab and Jenkins on a Raspberry Pi and on a amd64 Linux desktop systems.

Building these images requires time, so I’m always looking for existing alternatives. If you know, please comment!

Android

I often also need containers to build Qt apps for Android, at least for armv7 and arm64. Instead of manually creating these images, I though I could simply add scripts to my existing project docker-qt to include the Android build.

So, for versions >= 6.4.1, I also started to include a build of Qt for Android armv7 and armv8.

NOTE: only the amd64 image contains the builds for Android, which means you cannot currently crossbuild for Android from a arm64 container.

With these images it is possible to build a Qt app for Android and get the final apk or aab package. Images include the Android NDK, the Android SDK and all the typical dev tools.

Qt Builds

Qt builds in all images are located in /opt:

$ docker run -it --rm carlonluca/qt-dev:6.4.2 "ls -l /opt"
total 20
drwxr-xr-x 14 root root 4096 Jan  7 15:44 Qt-amd64-6.4.2
drwxr-xr-x 15 root root 4096 Jan  8 00:22 Qt-and-armv7a-6.4.2
drwxr-xr-x 15 root root 4096 Jan  8 00:47 Qt-and-armv8a-6.4.2
drwxr-xr-x 13 root root 4096 Jan  7 17:04 Qt-arm64-6.4.2
drwxr-xr-x  7 root root 4096 Jan  8 10:30 android-sdk

All the binaries you need are included in these directories, like qmake, qt-cmake, androiddeployqt etc…

Example

A typical usage for these images is running CI in GitLab:

Test_linux:
  stage: test_linux
  image:
    name: "carlonluca/qt-dev:6.4.2"
    entrypoint: [""]
  script:
    - mkdir build
    - cd build
    - /opt/Qt-amd64-6.4.2/bin/qt-cmake ..
    - make

Test_android:
  stage: test_android
  image:
    name: "carlonluca/qt-dev:6.4.2"
    entrypoint: [""]
  script:
    - mkdir build
    - cd build
    - /opt/Qt-and-armv7a-6.4.2/bin/qt-cmake ..
    - make
    - test -f ./android-build/build/outputs/apk/debug/android-build-debug.apk

It is also possible to build aab packages by using the androiddeployqt binary, included in the build.

Building the Images

I don’t exactly know how many images I’ll build and how often, but you can build the images by yourself by using a proper builder. See the GitHub repo docker-qt for the appropriate scripts.

Links

Docker hub of qt-builder: https://hub.docker.com/r/carlonluca/qt-builder.
Docker hub of qt-dev: https://hub.docker.com/r/carlonluca/qt-dev.

GitHub repo: https://github.com/carlonluca/docker-qt.

7 thoughts on “Docker Image for Qt Development and Continuous Integration for Linux and Android”

  1. Hi!
    Very nice project, I have just found it.
    I need a little help, I have tried some images:
    # docker pull carlonluca/qt-dev:6.8.2
    # docker pull carlonluca/qt-dev:5.15.10-lts-lgpl
    # docker pull carlonluca/qt-dev:6.5.3

    I did 2 test apps: one with .pro (for qmake) and another with CMakeLists.txt (for cmake)

    I’m trying to crosscompile for arm64, but I can’t succeed:

    root@c526700c1b6b:/src/test_cmake/build# /opt/Qt-amd64-6.5.3/bin/qt-cmake ..
    — The CXX compiler identification is unknown
    CMake Error at CMakeLists.txt:3 (project):
    The CMAKE_CXX_COMPILER:

    /usr/bin/aarch64-linux-gnu-g++

    is not a full path to an existing compiler tool.

    Tell CMake where to find the compiler by setting either the environment
    variable “CXX” or the CMake cache entry CMAKE_CXX_COMPILER to the full path
    to the compiler, or to the compiler name if it is in the PATH.

    — Configuring incomplete, errors occurred!
    See also “/src/test_cmake/build/CMakeFiles/CMakeOutput.log”.
    See also “/src/test_cmake/build/CMakeFiles/CMakeError.log”.

    I wasn’t able to find the aarch64-linux-gnu-g++ compiler. Then I installed but it also fails.

    Using qmake, it looks like qmake is for arm64:

    root@cfc9db52d56d:~# file /opt/Qt-arm64-6.5.3/bin/qmake
    /opt/Qt-arm64-6.5.3/bin/qmake: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=404f4feb8d2c3719f77bb654cf06340b2d034687, for GNU/Linux 3.7.0, not stripped

    Any suggestions?

    1. Hello,
      the image is multiarch, which means you can run the container on x64 and arm64. On x64 it can build for x64 and 4 Android archs. Running the container on arm64, you can build for arm64. Crossbuilding from x64 to Ubuntu arm64 is not probably something I took into consideration.

      However, during the build procedure of the image, I do crossbuild Qt from x64 to arm64, and it may work for crossbuilding. What you are looking for is probably /opt/Qt-arm64-6.8.0/bin/host-qmake. That is a x64 executable. I tested it and it did not seem to build properly though, but you may have more luck. You’ll have to install crossbuilding tools and libraries though.

  2. Hi Luca,

    Am I understanding the purpose of the QT dev image is that I could copy the sources of an app I have written with QT 5 into this image and execute the build of my sources in this container?

    Just trying to figure out if the QT Dev (x86-64) would be a QT5 compilation environment for my application.

    Thank you!

    1. Hello,
      yes, that is the point. You choose the version you need from the list of available images, you copy your sources into the container (or you mount a volume) and you build your app.
      This is typically useful in CI systems like Jenkins or GitLab, where you want your sources to be compiled and tested frequently to get notified in case of failures. The artifacts can then be extracted and distributed (like in Google Play for instance).

      1. Hi and thanks for responding Luca. I am looking to try this out. What I want to do first is to run the QT-Dev from docker-compose and like you say, mount a volume to the container that has my source and execute the build of the source in the container (only need for qt-dev:5.15.2 / x86_64). Does this sound like a valid approach? I am just trying to figure out what the proper arguments would be to run the container.

        1. If you want to do it manually of course, that is a reasonable approach. Something like docker run -it -v /host_path:/container_path carlonluca/qt-dev:5.15.2 bash. You are ready to go.

Leave a Reply

Your email address will not be published. Required fields are marked *