Qt 6.2 for Android

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:

  • Fixes to importing QML modules and the possibility for adding multiple QML root paths that androiddeployqt can use to look for QML modules:
    set_property(TARGET name APPEND PROPERTY QT_QML_ROOT_PATH ${qml_path_1})
    ...
    set_property(TARGET name APPEND PROPERTY QT_QML_ROOT_PATH ${qml_path_2})
  • Documentation improvement for publishing Android App Bundles with single ABI, see Publishing to Google Play.
  • Qt apps now provide information about who launched the app from getReferrer().
  • Support QDesktopService handlers on Android which allows working with Android App Links for example.
  • Fixed Vulkan feature detection and build for Android with CMake.
  • QCDebug() and its variants can now correctly use the provided category as a tag under Android logcat, as opposed to the previous behavior where the tag was always set to the application name.

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.


Blog Topics:

Comments