环境
问题 1
Value '/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home' given for org.gradle.java.home Gradle property is invalid (Java home supplied is invalid)
复制代码
解决
Gradle 的 java 环境变量与系统JAVA_HOME
不一致。
终端输入:/usr/libexec/java_home -V
,查看 java 路径。
yechao@yechaoa ~ % /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.131.11 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_131 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
复制代码
或是 mac 下,打开访达,然后打开 user 目录,command+shift+.
显示隐藏文件夹,找到.bash_profile
文件,查看或配置 java 环境
# java home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
export PATH=${PATH}:${JAVA_HOME}/bin
export PATH=${PATH}:${JAVA_HOME}/jre/bin
复制代码
然后打开项目中的gradle.properties
文件,查看org.gradle.java.home
参数是否一致,改为一致即可。
#org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
复制代码
注意:以上路径改为自己的 java 路径。
问题 2
Method 'buildStarted' from class 'BuildTraceListener' does not override method from its superclass or interfaces but is annotated with @Override.
复制代码
解决
Gradle 7.0 移除了BuildListener.buildStarted(Gradle)
,直接删除buildStarted
方法即可。
改用BuildListener.beforeSettings(Settings)
代替。
问题 3
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
AGP 7.0 必须使用 Java 11.
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
Gradle settings
复制代码
解决
直接点击 Gradle settings
选择 android studio 11 的版本,重新编译即可。
注意: AGP 的 java 版本跟项目的版本可以不一致。
也可以修改 build.gradle 中的配置为以下:
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
复制代码
只要你的项目支持即可。
问题 4
DSL element 'dexOptions' is obsolete and should be removed.
It will be removed in version 8.0 of the Android Gradle plugin.
Using it has no effect, and the AndroidGradle plugin optimizes dexing automatically.
复制代码
解决
dexOptions
已经过时,会在AGP8.0
移除,并且 AGP 会自动帮我们优化,所以,直接在 build.gradle 中移除 dexOptions 即可。
问题 5
The specified Android SDK Build Tools version (30.0.1) is ignored, as it is below the minimum supported version (30.0.2) for Android Gradle Plugin 7.0.2.
Android SDK Build Tools 30.0.2 will be used.
To suppress this warning, remove "buildToolsVersion '30.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
Remove Build Tools version and sync project
Affected Modules: app
复制代码
解决
buildToolsVersion
30.0.1 被忽略了,主要是因为低于 AGP7.0.2 所要求的的最低版本 30.0.2,所以会使用 30.0.2 的版本,而且后续 AGP 也会应用一个对应的默认
的版本,直接移除 buildToolsVersion 即可。
问题 6
Project property 'kotlin.parallel.tasks.in.project' is deprecated.
By default it depends on Gradle parallel project execution option value.
复制代码
解决
kotlin.parallel.tasks.in.project
弃用了,是kotlin 1.5.20
版本中的变更,使用org.gradle.parallel
就够了,所以直接删除 kotlin.parallel.tasks.in.project 即可。
其他
还有一些代码上的警告,按照提示解决即可。
Github
参考
评论