Qt keeps aiming to make Android support better with each release. Qt 6.2 brings many improvements for Android in terms of new APIs, feature updates, and bug fixes. This blog post will walk you through the main changes for Android in Qt 6.2.
QtAndroid Namespace
Following on the work done for Qt Extras modules in Qt Extras Modules in Qt 6, some of the functionality provided by QtAndroid namespace in Qt 5 is now provided by QNativeInterface::QAndroidApplication. For example, the following snippet can be used to change the system UI visibility from Android's main UI thread:
#include <QCoreApplication>
QNativeInterface::QAndroidApplication::runOnAndroidMainThread([]() {
QJniObject activity = QNativeInterface::QAndroidApplication::context();
// Hide system ui elements or go full screen
activity.callObjectMethod("getWindow", "()Landroid/view/Window;")
.callObjectMethod("getDecorView", "()Landroid/view/View;")
.callMethod<void>("setSystemUiVisibility", "(I)V", 0xffffffff);
});
The previously available app permission request API was redesigned under QtCore. However, the API is not yet public until other platforms' implementations, apart from Android, are ready in subsequent Qt releases.
Clients that still rely on missing functionality or the permission API can include the private header <QtCore/private/qandroidextras_p.h> as a stopgap solution.
Android Manifest
The Android manifest is an important part of any Android app, it is used for various details about the app, from settings the app name, icons, to customized activities and services. In Qt 5, the manifest is used to handle part of the build and packaging management of Qt libraries and assets. That meant the manifest used to be relatively long and contains lots of meta-data that might have not been very clear whether it is build-system specific or it can be modified by the user. Now, all attributes that are meant for deployment management are hidden to keep the manifest lightweight and contain only user-specific meta-data. For information on the manifest, see Qt Android Manifest.
Related to this change, Ministro which was used with Qt 5 is now removed because it is no longer supported by recent Android versions. For that reason, the manifest file for apps using Qt 5, might need to make some changes. For more information, see Qt Manifest before 6.2 Release.
Non-SDK Android APIs
Android has been restricting access to various non-SDK APIs, among which, there are some APIs that Qt uses to extract native style information such as font sizes, colors, and formats, etc. The use of such APIs from Android 9 onward, can cause the style extraction to fail or throw warnings. Those style information is not using correct APIs. Apps using QML work correctly without warnings that might have been seen before. However, one limitation, for the time being, is that apps using Widgets and the native Android style might not have all the correct drawables. For that reason, it is recommended to use QML for mobile apps. For more information, see QTBUG-71590.
Android SDK Updates
Google Play Store has frequent updates to the requirements of the API level used in apps when publishing to the Store. Qt stays up to date with those requirements, thus the current default target SDK level is 30 (Android 11). The build tools and platform version used for building Qt is also set to 30.
Additionally, the Android Gradle plugin has been updated to version 4.1.3, which has support for <queries> in Android 11. Also, with this update, a bug in signing packages using newer Gradle plugin versions was fixed, where the packages are already aligned by Gradle.
Other Changes
Some other improvements and bug fixes for Qt Android include, but are not limited to:
Your Input
Feedback from users is always welcome! If you have any suggestions, requests, or bug reports, you can leave that here on the blog or at https://bugreports.qt.io.