Qt Environment for Android

Welcome to Connection Quest‘s first post in our grand adventure, using Qt in Android.
An adventure where two worlds collide, fast and featureful framework Qt with versatile and ever expanding Android platform.
During our quests, we will show you different aspects of how to use this tool to create fast, elegant and modern apps in Android.
You ask us, is this post for me?
It is, if you are:
- C++ developer wanting to make some Android apps
- Qt enthusiast who wants to try deploying to Android platform
- Want to play with new technologies and use powerful Qt framework to tinker on Android
But let’s be honest, who doesn’t want to play with new, interesting technologies?
In this Quest, we will show you how to start!
Prerequisites
To set up Qt for Android development enviroment, following tools are needed:
Java Development Kit ( OpenJDK or Java SE Development Kit) – used for developing Java applications and applets
Android Software Development Kit – used for Android application development
Android Native Development Kit – allows to use C or C++ code with Android
If you already have any of them installed, jump straight to the next one.
1 Java Development Kit
Java Development Kit enables us to develop Java aplications.
It is a Qt/Android requirement, but will also allows us to use it for some nice features from Android Java libraries (check out our post Java Native Interface with Qt).
Choose one of the two solutions to install JDK:
1.1 OpenJDK
At the time of writing, versions 6 to 8 are recommended by official Qt website. Versions higher than 8 might cause issues. https://doc.qt.io/qt-5/android-getting-started.html
In order to find out more about the installation, visit the page https://openjdk.java.net/install/index.html.
For openSUSE install from the official repository:
zypper sudo addrepo https://download.opensuse.org/repositories/openSUSE:Factory/standard/openSUSE:Factory.repo zypper sudo refresh zypper sudo install java-1_8_0-openjdk
For Debian based distribution (Ubuntu and Linux Mint) install from the official repository:
sudo apt-get install openjdk-8-jre
1.2 Java SE Development Kit
If you prefer to use Oracle’s propietary development kit, download and install Java SE Development Kit.
After the product is chosen based on the architecture and download is finished, move to the directory where the file is located and unpack the files with the following commands:
sudo tar -xzf ./jdk-8u251-linux-x64.tar.gz sudo chown -R root:root jdk1.8.0_251 sudo mv ./jdk1.8.0_251 /usr/lib64 sudo ln -s -T /usr/lib64/jdk1.8.0_251 /usr/lib64/jdk_Oracle
The commands above:
- untar the files
- fix the permissions and move the jdk to /usr/
- create a symbolic link to /usr/lib64/jdk1.X.X_XX/ (this will be important later for updating).
JDK is installed now and located in /usr/lib64/jdk1.X.X_XX/ .
2 Android Development Kit
Choose one of the two solutions in order to install Android Development Kits:
2.2 Using sdkmanager command line tool
If you will not develop Android Java/Kotlin apps, or you don’t care about graphical installation interfaces,we recommend the second method (sdkmanager). Otherwise, Android Studio will allow you to developer Android apps in other supported languages.
2.1 Android Studio
To get SDK tools, install Android Studio first.
Install Android Studio from the official page or use this script https://www.hiroom2.com/2018/06/27/opensuse-15-android-studio-3-1-en/ .
When the installation is done, open Android Studio.
Now, choose Tools -> SDK Manager from the menu. The following window is opened.
Accept terms and conditions in order to install SDK Tools and SDK Platforms.
Choose Android SDK Build-Tools, Android SDK Platform-Tools, NDK (in the image above) and at least one SDK Platform (in the image below) and install it.
When the installation is done, the packages and tools are located in Android SDK location (/home/username/Android/Sdk).
2.2 SDKManager Comand Line Tool
If you do not want to use Android Studio, but still want to install sdk tools, visit Android Studio page. There, navigate to Download -> Command Line Tools Only and choose package for the operating system.
After the download, unzip the files and move all files to /home/username/. Make new directory and name it as you wish (I named it cmdline-tools). Make sure you are positioned in the directory /home/usrename/cmdline-tools/tools/bin. Now,install the packages.
As a reminder, necessary packages are: Android SDK Build-Tools, Android SDK Platform-Tools, NDK and at least one SDK Platform.
The following commands to install the packages are:
./sdkmanager ”platform-tools” ./sdkmanager ”build-tools;XX.Y.Z” ./sdkmanager ”ndk-bundle” ./sdkmanager ”platforms;android-XX”
where XX.Y.Z and XX are required versions.
For example
./sdkmanager ”platforms;android-30” ./sdkmanager ”build-tools;29.0.2”.
With –sdk_root=PATH you can specify the directory where you want to store these packages.
./sdkmanager --sdk_root=/home/username/cmdline-tools/sdk ”ndk-bundle”
3 Setup Qt for Android
After the installation of all prerequisites, we are ready to setup Qt for Android.
But, what is Qt for Android? Is it any different than your everyday Qt?
Qt for Android is a set of tools combining Qt Android version, cross-compiling environment, debugger and interface to ADB.
What does Qt for Android provide us?
- Automatization
- Build process
- Preparing main activity in Java
- Gradle integration
- Packaging process
- Preparing APK
- Integrating libs for Qt
- Build process
- Optimatization
- Using and packaging only needed libraries
- Access to Android extras
- GUI in Qt widgets or QML
- Graphical interface in Material style with Qt Quick Controls
- Use available sensors, Bluetooth and NFC
- Develop parts in Java to access Android API directly
So, do you want an easy access to all these goodies?
Let’s start with preparing the environment.
To setup Qt for Android, install the Android component by running the Qt Maintenance tool. It is located in your Qt directory.
After you log in, choose the option Add or Remove components.
Next, check all the boxes of the desired Qt for Android. For example, we required Qt for Android 5.13.2 for x86_64, ARM64-v8a and ARMv7 architecture.

Press Next and after these components are installed, open Qt Creator. Then open Tools -> Options -> Kits.
No Android Kits are currently available, but in Kits -> Qt Versions we should see auto-detected Android components.
To configure Android device build and deploy process, open Tools -> Options -> Devices -> Android.
To setup the needed packages, browse the correct location of directories.
Qt Creator should now recognize Android settings. To confirm successful setup, open Tools -> Options -> Kits again. There should be listed Android kits (depending on installed components). You should also be able to findcompilers and debuggers for Android auto-detected.
This means Qt Creator is ready to build applications for Android.

Now you are ready to create Android applications in Qt.
3.1 How to create a new Qt Android project?
As usual, go to File -> New File or Project. Choose your desired project template. Choose qmake as your build system and your minimal required Qt version.
Now, you will be presented with available kits. Select Android for the required architecture and complete the project setup. If you do not want to also try an existing Qt project, skip next paragraph.
3.2 How to use an existing Qt project?
You can use already existing Qt projects as Qt Android projects simply by changing project kits. Open your desired project. Go to tab Projects (left sidebar). You can find a list of Build & Run options. Choose Android as your project kit.
How to deploy your app?
Connect your device to USB.
Press run. Now, the build process will comence.
After application is built, it will be packaged into APK.
You should see a new window displayed, asking to which device it should be deployed.
Choose your device and enjoy your application on Android.
Congratulations, your quest for Qt Android environment has been completed!
Follow our new adventures in Android land with Qt, coming soon!
Useful links:
Qt for Android (official): https://doc.qt.io/qt-5/android.html
Anatomy of a Qt 5 for Android applications (official): https://www.qt.io/blog/2013/07/23/anatomy-of-a-qt-5-for-android-application
Command Line Tools (official): https://developer.android.com/studio/command-line
Native debugging on Android with Qt Creator: https://fw4spl-org.github.io/fw4spl-blog/2015/07/27/Native-debugging-on-Android-with-QtCreator.html