用 cordova 把网页转成 安卓 APP 执行
cordova build android
报错
xxxxx\cordova>cordova build android
Checking Java JDK and Android SDK versions
ANDROID_HOME=xxxxx\commandlinetools-win-11076708_latest\cmdline-tools (recommended setting)
ANDROID_SDK_ROOT=undefined (DEPRECATED)
Using Android SDK: xxxxx\commandlinetools-win-11076708_latest\cmdline-tools
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
FAILURE: Build failed with an exception.
* What went wrong:
BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 66
> Unsupported class file major version 66
* 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.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.7/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 3s
Command failed with exit code 1: xxxxx\gradle-8.7-bin\gradle-8.7\bin\gradle.BAT -p xxxxx\cordova\platforms\android wrapper -b xxxxx\cordova\platforms\android\wrapper.gradle
从错误信息来看,这个问题通常是由于编译代码的Java版本与Gradle运行的Java版本不匹配导致的。
出错信息中提到 “Unsupported class file major version 66”,这个版本对应的是 Java 20。
确保使用的 Gradle 版本支持代码编译时使用的 Java 版本。
Gradle 8.7 最高支持到 Java 19, 如果要使用 Java 20,你需要升级到 Gradle 9.0 或更高版本。
我本地是 8.7 版本的 Gradle (当前官网默认版本)
我选择降低本地的 JDK 的版本,这里有华为的镜像
https://repo.huaweicloud.com/java/jdk/
我选 jdk13 了,诸位自己选版本,然后把 bin 目录添加到环境变量中
(UPDATE: 注意,我踩了好多坑,还是安装 JDK17 吧)