当前位置:首页 » 《关注互联网》 » 正文

Android Studio Arctic Fox | 2020.3.1、Gradle 7.0升级记录_yechaoa

2 人参与  2022年01月24日 11:09  分类 : 《关注互联网》  评论

点击全文阅读


环境

  • Android Studio Arctic Fox | 2020.3.1
  • Gradle、AGP 7.0
  • Kotlin 1.5.31

问题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

  • 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

点击全文阅读


本文链接:http://zhangshiyu.com/post/33784.html

即可  版本  解决  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1