在搭建环境时开始感觉还挺顺利的,从 Qt 配置的环境里面看并没有什么问题,可真正编译程序的时候发现全是错误。
最开始的时候安装了 JDK21 最新版本,然后根据 JDK21 安装 ndk, build-tools, Platform-Tools 和 Gradle,但是不管这么搞都会有编译错误。然后在换成 JDK20,依然不行,最后换到 JDK18 的时候终于可以了。
需要注意的是还需要搭配正确的 gradle 版本和 gradle 插件版本。
Qt 配置信息如图所示。
gradle:7.4.2
为 Gradle 插件版本。dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
}
distributionUrl=gradle-7.5.1-bin.zip
FAILURE: Build failed with an exception.
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/7.5.1/userguide/gradle_daemon.html
Process command line: D:\software\Java\jdk-18.0.2.101-hotspot\bin\java.exe --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country=CN -Duser.language=zh -Duser.variant -cp C:\Users\Administrator\.gradle\wrapper\dists\gradle-7.5.1-bin\ertkw1ldykftus49ntdszylsr\gradle-7.5.1\lib\gradle-launcher-7.5.1.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.5.1
Please read the following process output to find out more:
-----------------------
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Building the android package failed!
-- For more information, run this command with --verbose.
11:33:40: 进程"D:\software\Qt\5.15.2\android\bin\androiddeployqt.exe"退出,退出代码 14 。
Error while building/deploying project Android3 (kit: Android Qt 5.15.2 Clang Multi-Abi)
When executing step "Build Android APK"
解决方法:
org.gradle.jvmargs=-Xmx1024m