Android|Android Studio Arctic Fox | 2020.3.1、Gradle 7.0升级记录
环境
- Android Studio Arctic Fox | 2020.3.1
- Gradle、AGP 7.0
- Kotlin 1.5.31
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.
【Android|Android Studio Arctic Fox | 2020.3.1、Gradle 7.0升级记录】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
- https://github.com/yechaoa/wanandroid_jetpack
- Android Studio release notes
- Upgrading your build from Gradle 6.x to the latest
- What’s new in Kotlin 1.5.20
推荐阅读
- android第三方框架(五)ButterKnife
- Android中的AES加密-下
- 带有Hilt的Android上的依赖注入
- android|android studio中ndk的使用
- Android事件传递源码分析
- RxJava|RxJava 在Android项目中的使用(一)
- Android7.0|Android7.0 第三方应用无法访问私有库
- 深入理解|深入理解 Android 9.0 Crash 机制(二)
- android防止连续点击的简单实现(kotlin)
- Android|Android install 多个设备时指定设备