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路径。
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)
代替。
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'
}
只要你的项目支持即可。
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即可。
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即可。
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即可。
还有一些代码上的警告,按照提示解决即可。