Qt 5.14, Android multi ABI, and CMake
Starting with Qt for Android version 5.14 will distribute multi ABI prebuilt binaries, as we learned from the AAB Support in Qt for Android blog entry.
QMake has been updated to handle the multi ABI scenario as mentioned at Qt for Android better than ever before. But what about CMake?
CMake is known for building one configuration at a time, that's true for single configuration generators (Makefiles / Ninja), or multi-configuration generators (Visual Studio / Xcode). However, by using ExternalProject one can build the same project multiple times with different configurations in one go.
Qt 5.14 has gotten support for this scenario, however it didn't make it into Qt 5.14 beta 2! The Android plugin in Qt Creator has been also updated. The Qt 5.14 release should contain all the necessary changes to create / build / deploy Qt Android applications using CMake.
Let's say we created a Qt Quick CMake project, if we go to the Build Settings we can see in the CMake variable list the following:
One can select which ABI gets to be built by clicking the corresponding ANDROID_BUILD_ABI_<abi> check boxes.
From command line, the CMake project will also get the apk and aab targets, which can be used to generate the corresponding Android package.
CMake 3rd party packages
Qt 5.14 will come with a multi ABI installation, but what about 3rd party packages?
The CMake ecosystem has a few packages managers e.g. conan, vcpkg, Hunter. All of the packages managers have some dependencies, and need some sort of external configuration. The amount of configuration gets more complicated when you have to support the multiple ABIs of Android!
With Hunter, since it only depends on CMake, I was able to get the setup down to few lines lines of CMake code, which works with the new Qt for Android multi ABI setup.
In order to get dlib for my project all I have to do in my CMake code is:
# Setting up dlib as an external package
FetchContent_Declare(SetupHunter GIT_REPOSITORY https://github.com/cpp-pm/gate)
# Using the dlib package
target_link_libraries(myapp PRIVATE dlib::dlib)
The initial configuration will take some time, since dlib has giflib, Jpeg, PNG, sqlite3, ZLIB as dependencies, which will get compiled with the current compiler / ABI. But once cached for a certain configuration, the CMake configuration / build would be as fast as with other pre-built library.
Subscribe to our newsletter
Try Qt 6.5 Now!
Download the latest release here: www.qt.io/download.
Qt 6.5 is the latest Long-Term-Support release with all you need for C++ cross-platform app development.
Qt World Summit 2023: Berlin awaits!
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.