Qt 6.9-安卓更新

Qt 6.9 - Android Updates

Qt 6.9-安卓更新

December 17, 2024 by Assam Boudjelthia | Comments

​2024年12月17日,阿萨姆·布杰尔蒂亚发表|评论

Qt 6.9 brings some useful new features to improve the development process for developers targeting the Android platform. Keep in mind that the following list is not exhaustive of all changes around Qt for Android, and some other features might get their own blog.

Qt 6.9带来了一些有用的新功能,以改善针对Android平台的开发人员的开发过程。请记住,以下列表并不详尽地列出围绕Qt for Android的所有更改,其他一些功能可能会有自己的博客。

Support for Uncompressed Native Libraries

支持未压缩的本地库

Android 6 and above produces uncompressed native libraries that are only part of the APK by default. However, Qt had this behavior explicitly disabled with the following setting under build.gradle:

Android 6及更高版本生成未压缩的本机库,默认情况下这些库只是APK的一部分。但是,Qt在build.gradle下通过以下设置明确禁用了此行为:

android {
...
   packagingOptions.jniLibs.useLegacyPackaging true
 ...
}

Or via the now deprecated extractNativeLibs manifest flag, because Qt didn't support loading libraries directly from the APK. With this release, such support for reading and loading shared libraries directly from the APK without having them extracted to disk but rather, map those shared libraries to memory. Qt apps and APIs such as QLibrary and QPluginLoader should work the same as before and iterate libraries under the native libraries' directory.

或者通过现已弃用的extractNativeLibs清单标志,因为Qt不支持直接从APK加载库。在此版本中,支持直接从APK读取和加载共享库,而无需将其提取到磁盘,而是将这些共享库映射到内存。Qt应用程序和API(如QLibrary和QPluginLoader)应与以前一样工作,并在本机库目录下迭代库。

There are few things to consider when this mode is enabled (it's enabled by default on 6.9+). For example, QCoreApplication::applicationDirPath() would now return a path that points to a shared library filename that's inside the app's APK, usually in the form:

​启用此模式时需要考虑的事情很少(默认情况下在6.9+上启用)。例如,QCoreApplication::applicationDirPath()现在将返回一个路径,该路径指向应用程序APK中的共享库文件名,通常采用以下形式:

/data/data/package-path/base.apk!/lib/arm64-v8a/libmyapp_arm64_v8a.so

Paths returned by similar API calls might have previously returned a writable path, after this however, the returned paths won't be writable.

类似的API调用返回的路径以前可能返回了一个可写路径,但在此之后,返回的路径将不可写。

Enabling this might increase slightly the total size of produced APKs, but saves on disk space after installation and also on update sizes from the Play Store and slightly faster startups. For more information, see Improvements for smaller app downloads on Google Play.

​启用此功能可能会略微增加生产的APK的总大小,但可以节省安装后的磁盘空间,以及Play商店的更新大小和稍快的启动速度。有关更多信息,请参阅Google Play上较小应用程序下载的改进。

Apps with the older way using compressed libraries still work as before if the relevant flag is explicitly enabled as mentioned above.

如果如上所述明确启用了相关标志,则使用压缩库的旧方式的应用程序仍然可以像以前一样工作。

New Command-Line App/Test Runner

新命令行应用程序/测试运行器

When developing for Android, you're expected for the most part to be using an IDE that handles the build and deployment and running the app. That process doesn't need to be that complicated, because of that we've added wrapper scripts that handle that job for you. Especially, on CI environments or if you're one of the people who can get by using a lightweight code editor and a terminal for development, this can be quite handy for you. All you need to do is build your project's APK and run the app as follows:

在为Android开发时,在很大程度上需要使用一个IDE来处理构建和部署以及运行应用程序。这个过程不需要那么复杂,因为我们添加了处理该作业的包装器脚本。特别是在CI环境中,或者如果可以使用轻量级代码编辑器和开发终端的人之一,这非常方便。需要做的就是构建项目的APK并按如下方式运行应用程序:

cd build
qt-cmake -S .. -B . -GNinja
cmake --build . --target apk
MY_ENV_VAR=value ./my_app --install --my_arg value

This last command would handle all the underlying adb commands behind the scenes by installing the app to the device, starting it and printing the logcat of the app, making it a more seamless experience and hassle free. For Windows, the runner has the .bat file extension.

最后一个命令将通过将应用程序安装到设备上、启动它并打印应用程序的日志来处理幕后的所有底层adb命令,使其成为一种更无缝的体验和无忧的体验。对于Windows,运行程序具有.bat文件扩展名。

You can pass environment variables directly from your shell so they end up being passed to the app's runtime on the device. The same applies for command line arguments, where arguments not reserved by the runner are passed as app's arguments. For all parameters that the wrapper accepts, call it with --help.

可以直接从shell传递环境变量,这样它们最终会被传递到设备上的应用程序运行时。这同样适用于命令行参数,其中运行器未保留的参数作为应用程序的参数传递。对于包装器接受的所有参数,请使用--help调用它。

The same applies for auto tests, you would be able to simply do the following:

这同样适用于自动测试,可以简单地执行以下操作:

cd build
QTEST_FUNCTION_TIMEOUT=900000 ./tst_android test_case_1

And that would simply handle everything with androidtestrunner under the hood. In this case, you don't need to manually issue the APK build command because androidtestrunner takes care of that.

这只需在引擎盖下使用androidestrunner即可处理所有事情。在这种情况下,不需要手动发出APK构建命令,因为androidestrunner会处理这个问题。

CMake Android APIs

We keep improving the integration of Android builds with CMake to make it easier to manage and maintain Android-specific requirements. Here’s what’s new:

我们不断改进Android构建与CMake的集成,使其更容易管理和维护Android特定的需求。以下是最新消息:

Add App Permissions
添加应用程序权限

Managing permissions for Android apps often requires manual edits to the AndroidManifest.xml. The new qt_add_android_permission() function removes this hassle by letting you declare permissions directly within your CMakeLists file. This function still allows auto inclusion of Qt modules' managed permissions. This approach simplifies project management, making it more straightforward by keeping project configurations in one place.

​管理Android应用程序的权限通常需要手动编辑AndroidManifest.xml。新的qt_add_android_permission()函数允许直接在CMakeLists文件中声明权限,从而消除了这一麻烦。此功能仍然允许自动包含Qt模块的托管权限。这种方法简化了项目管理,通过将项目配置保存在一个地方使其更加简单。

Setting an App's Name and Icon

设置应用程序的名称和图标

Setting the app's name is now as simple as specifying it with QT_ANDROID_APP_NAME in your CMake configuration. No more manual setting of the app's name in the AndroidManifest.xml file. Similarly, you can now define your app's icon drawable/mipmap in your project's CMake configuration with QT_ANDROID_APP_ICON. This expects the icon drawables to be under the appropriate Android resource directory hierarchy and the use of QT_ANDROID_PACKAGE_SOURCE_DIR.

​现在,设置应用程序的名称就像在CMake配置中使用QT_ANDROID_APP_NAME指定它一样简单。无需在AndroidManifest.xml文件中手动设置应用程序的名称。同样,现在可以在项目的CMake配置中使用QT_ANDROID_APP_ICON定义应用程序的图标可绘制/mipmap。这要求图标可绘制内容位于适当的Android资源目录层次结构下,并使用QT_ANDROID_PACKAGE_SOURCE_DIR。

Setting Java/Kotlin Compile SDK Level
设置Java/Kotlin编译SDK级别

The new property QT_ANDROID_COMPILE_SDK_VERSION allows you to specify the Android SDK version for compiling Java code. With this property, you can ensure your project is always built against the desired API level.

​新属性QT_ANDROID_COMPILE_SDK_VERSION允许指定用于编译Java代码的ANDROID SDK版本。使用此属性,可以确保您的项目始终是根据所需的API级别构建的。

Improved Background Event Management

改进的后台事件管理

Background processes, particularly those involving UI updates, can be a source of performance bottlenecks if not managed properly. To address this, now it's possible for developers to set a maximum limit for queued background UI events by setting the new environment variable QT_ANDROID_BACKGROUND_ACTIONS_QUEUE_SIZE.

​如果管理不当,后台进程,特别是那些涉及UI更新的进程,可能会成为性能瓶颈的来源。为了解决这个问题,现在开发人员可以通过设置新的环境变量QT_ANDRitBACKGROUND_ATIONS_QUEUE_SIZE来为排队的后台UI事件设置最大限制。

This enhancement prevents potential memory overload caused by an excessive number of tasks waiting in the queue. By defining a limit, developers can ensure smoother performance and prevent lagging or unresponsive behavior in their apps.

此增强功能可防止因队列中等待的任务数量过多而导致的潜在内存过载。通过定义限制,开发人员可以确保更流畅的性能,并防止应用程序中的滞后或无响应行为。


That's all from me this time! As always, we continue to improve Qt for Android, and we welcome your feedback and suggestions on this blog post or over bugreports.qt.io.

​这次全是我的!与往常一样,我们将继续改进适用于Android的Qt,我们欢迎在本文或bugreports.Qt.io上提供反馈和建议。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值