天使漫步IT工作室天使漫步IT工作室

android studio 3.1 升级后的坑 - mac升级gradle方法汇总

升级完android studio 3.1后

每一次升级android studio都会或多或少的出现一些问题,这一次出现的问题包括:

不然你编译的时候会发现以下错误:

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
   > Minimum supported Gradle version is 4.4. Current version is 4.1. If using the gradle wrapper, try editing the distributionUrl in /Users/landsnail/Documents/gemdale/gdhlwandroid/decorate/gradle/wrapper/gradle-wrapper.properties to gradle-4.4-all.zip

解决的办法步骤

  • 1.将工程下面的wrapper/gradle-wrapper.properties 中的gradle版本改为:gradle-4.4-all.zip
  • 2.升级当前编译工具的Gradle版本,值得提出来的是,虽然利用brew(我的是mac电脑)也可以帮你升级,但是不会帮你更改默认的Gradle_Home指向,其实是一个固定的文件夹:current 软连接到 目标Gradle 版本中。而利用sdkman方式,会帮你处理好软连接的问题。

根据Gradle官方给出的方法(Gradle.org升级方法汇总),给出示例如下:

先使用brew install gradle
Error: gradle 4.2.1 is already installed
To upgrade to 4.6, run `brew upgrade gradle`
landsnail:decorate landsnail$ brew upgrade gradle
==> Upgrading 1 outdated package, with result:
gradle 4.2.1 -> 4.6
==> Upgrading gradle 
==> Downloading https://services.gradle.org/distributions/gradle-4.6-all.zip
==> Downloading from https://downloads.gradle.org/distributions/gradle-4.6-all.zip
######                                                                     8.5%

============================以上为利用brew安装升级Gradle============================

利用sdkman 来升级 及升级过程
==== BROADCAST =================================================================
* 05/04/18: Springboot 2.0.1.RELEASE released on SDKMAN! #springboot
* 05/04/18: Springboot 1.5.11.RELEASE released on SDKMAN! #springboot
* 04/04/18: Grails 3.3.4 released on SDKMAN! #grailsfw
================================================================================

Upgrade:
gradle (3.3, 2.14.1, 3.4.1, 3.0, 4.1, 2.4 < 4.6)

Upgrade candidate(s) and set latest version(s) as default? (Y/n): y

Downloading: gradle 4.6

In progress...

##################################################                        70.3%

Installing: gradle 4.6
Done installing!


Setting gradle 4.6 as default.


ATTENTION: A new version of SDKMAN is available...

The current version is 5.6.3+299, but you have 5.5.12+269.

Would you like to upgrade now? (Y/n)y

Updating SDKMAN...
######################################################################## 100.0%
/Users/landsnail/.sdkman/bin/sdkman-init.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-init.sh -> /Users/landsnail/.sdkman/bin/sdkman-init.sh
/Users/landsnail/.sdkman/src/sdkman-availability.sh
/Users/landsnail/.sdkman/src/sdkman-broadcast.sh
/Users/landsnail/.sdkman/src/sdkman-current.sh
/Users/landsnail/.sdkman/src/sdkman-default.sh
/Users/landsnail/.sdkman/src/sdkman-env-helpers.sh
/Users/landsnail/.sdkman/src/sdkman-flush.sh
/Users/landsnail/.sdkman/src/sdkman-help.sh
/Users/landsnail/.sdkman/src/sdkman-install.sh
/Users/landsnail/.sdkman/src/sdkman-list.sh
/Users/landsnail/.sdkman/src/sdkman-main.sh
/Users/landsnail/.sdkman/src/sdkman-offline.sh
/Users/landsnail/.sdkman/src/sdkman-path-helpers.sh
/Users/landsnail/.sdkman/src/sdkman-selfupdate.sh
/Users/landsnail/.sdkman/src/sdkman-uninstall.sh
/Users/landsnail/.sdkman/src/sdkman-upgrade.sh
/Users/landsnail/.sdkman/src/sdkman-use.sh
/Users/landsnail/.sdkman/src/sdkman-utils.sh
/Users/landsnail/.sdkman/src/sdkman-version.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-availability.sh -> /Users/landsnail/.sdkman/src/sdkman-availability.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-broadcast.sh -> /Users/landsnail/.sdkman/src/sdkman-broadcast.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-cache.sh -> /Users/landsnail/.sdkman/src/sdkman-cache.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-current.sh -> /Users/landsnail/.sdkman/src/sdkman-current.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-default.sh -> /Users/landsnail/.sdkman/src/sdkman-default.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-env-helpers.sh -> /Users/landsnail/.sdkman/src/sdkman-env-helpers.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-flush.sh -> /Users/landsnail/.sdkman/src/sdkman-flush.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-help.sh -> /Users/landsnail/.sdkman/src/sdkman-help.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-install.sh -> /Users/landsnail/.sdkman/src/sdkman-install.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-list.sh -> /Users/landsnail/.sdkman/src/sdkman-list.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-main.sh -> /Users/landsnail/.sdkman/src/sdkman-main.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-offline.sh -> /Users/landsnail/.sdkman/src/sdkman-offline.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-path-helpers.sh -> /Users/landsnail/.sdkman/src/sdkman-path-helpers.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-selfupdate.sh -> /Users/landsnail/.sdkman/src/sdkman-selfupdate.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-uninstall.sh -> /Users/landsnail/.sdkman/src/sdkman-uninstall.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-update.sh -> /Users/landsnail/.sdkman/src/sdkman-update.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-upgrade.sh -> /Users/landsnail/.sdkman/src/sdkman-upgrade.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-use.sh -> /Users/landsnail/.sdkman/src/sdkman-use.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-utils.sh -> /Users/landsnail/.sdkman/src/sdkman-utils.sh
/Users/landsnail/.sdkman/tmp/stage/sdkman-version.sh -> /Users/landsnail/.sdkman/src/sdkman-version.sh
/Users/landsnail/.sdkman/tmp/out
/Users/landsnail/.sdkman/tmp/hook_post_gradle_4.6.sh
/Users/landsnail/.sdkman/tmp/hook_pre_gradle_4.6.sh
/Users/landsnail/.sdkman/tmp/sdkman-5.6.3+299.zip
/Users/landsnail/.sdkman/tmp/res-5.5.12+269.zip
/Users/landsnail/.sdkman/tmp/res-5.0.0+51.zip
/Users/landsnail/.sdkman/tmp
mkdir: created directory '/Users/landsnail/.sdkman/tmp'


Successfully upgraded SDKMAN!

Open a new terminal to start using SDKMAN 5.6.3+299.

To join our BETA channel, simply follow the instructions on:

   http://sdkman.io/install.html

Enjoy!!!

至此出现Enjoy字样后,Gradle 4.6升级完毕。在命令行中输入:gradle -v 来查看版本:

------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------

Build time:   2018-02-28 13:36:36 UTC
Revision:     8fa6ce7945b640e6168488e4417f9bb96e4ab46c

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM:          1.8.0_05 (Oracle Corporation 25.5-b02)
OS:           Mac OS X 10.13.4 x86_64

本站原创,欢迎转载,转载敬请标明出处:天使漫步IT工作室 » android studio 3.1 升级后的坑 - mac升级gradle方法汇总
添加新评论