Qt构建Android 11 APK报错:Unsupported class file major version 65
问题描述
按Qt 6 Android官方入门步骤操作后,遇到以下问题:
- 「构建并部署示例到模拟器」环节无法自动生成Android套件,手动创建套件、配置
JAVA_HOME均无效;删除%LOCALAPPDATA%\QtProject\QtCreator\cache\CachedStores文件夹后,重启Qt Creator自动生成了默认Android套件。 - 构建Android APK时失败,核心错误日志如下:
Generating Android Package Input file: C:/Users/.../builds/build-ANDROID-qt-Android_Qt_6_5_3_64_bit-Debug/app/android-qt-deployment-settings.json Output directory: C:/Users/.../builds/build-ANDROID-qt-Android_Qt_6_5_3_64_bit-Debug/app/android-build/ Application binary: ... Android build platform: android-31 Install to device: No Warning: QML import could not be resolved in any of the import paths: QtQuick.Controls.Windows Warning: QML import could not be resolved in any of the import paths: QtQuick.Controls.macOS Warning: QML import could not be resolved in any of the import paths: QtQuick.Controls.iOS FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring root project 'android-build'. > Could not open cp_proj generic class cache for build file 'C:\Users\...\builds\build-ANDROID-qt-Android_Qt_6_5_3_64_bit-Debug\app\android-build\build.gradle' (C:\Users\...\.gradle\caches\8.0\scripts\et9...). > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 65 * 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 BUILD FAILED in 5s Building the android package failed! -- For more information, run this command with --verbose. 09:00:30: The process "C:\Qt\6.5.3\mingw_64\bin\androiddeployqt.exe" exited with code 14. Error while building/deploying project ... (kit: Android Qt 6.5.3 64-bit) When executing step "Build Android APK"
- 疑惑:构建时调用的是
mingw_64下的androiddeployqt.exe,而非android_x86_64版本。
解决方案
1. 修复「Unsupported class file major version 65」核心错误
Class file major version 65对应Java 21,但Qt 6.5.3配套的Gradle版本不支持该Java版本,需调整为兼容版本:
- 安装Java 17(Qt 6.x Android开发推荐的LTS版本);
- 修改系统环境变量
JAVA_HOME,指向Java 17的安装目录; - 重启Qt Creator,在「工具→选项→设备→Android」中确认Java路径已更新为Java 17;
- 删除
C:\Users\<你的用户名>\.gradle\caches文件夹,清除旧Gradle缓存。
2. 消除QML平台控件导入警告
这些警告因项目引用了Windows/macOS/iOS专属控件模块,Android环境不支持导致:
- 打开项目QML文件,移除
QtQuick.Controls.Windows、QtQuick.Controls.macOS、QtQuick.Controls.iOS的导入语句; - 统一使用跨平台的
QtQuick.Controls模块,确保UI在Android上正常渲染。
3. 关于androiddeployqt.exe路径的说明
mingw_64下的androiddeployqt.exe是运行在Windows主机上的打包工具,负责处理Android应用的打包流程,使用该版本是正常的;android_x86_64版本是针对Android平台编译的二进制文件,无法在Windows系统上运行,无需替换。
4. 验证Android套件配置
确保套件配置完全正确:
- 在「工具→选项→设备→Android」中,确认SDK、NDK、JDK路径均指向兼容版本(SDK建议选android-33及以上,NDK使用Qt Creator自动匹配的版本);
- 打开「工具→选项→构建和运行→套件」,检查Android套件的「编译器」「调试器」「Qt版本」已正确关联。
内容的提问来源于stack exchange,提问作者Arthur Caccavo
相关产品推荐
相关产品推荐

