如何在Android Studio中使用最新的gradle版本 [英] How to use the latest gradle version in Android Studio

查看:209
本文介绍了如何在Android Studio中使用最新的gradle版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到Gradle的发布了2.12版本,并且根据发行说明,脚本应该编译到20%更快。我想在Android Studio中升级到该版本。



我使用v1.5.1,并在设置中选择了使用默认的gradle wrapper选项,这意味着不是每个项目都使用本地gradle install,而是为每个项目使用特定的gradle版本。使用的版本是在 build.gradle 文件中定义的版本。例子:

  buildscript {
repositories {
jcenter()
}
依赖关系{
classpath'com.android.tools.build:gradle:1.5.0'

//注意:不要在这里放置应用程序依赖关系;它们属于单个模块build.gradle文件
//

$ b code


现在,如果我改变它:

  classpath'com.android.tools.build:gradle:2.12 '

然后Android Studio无法找到该版本并引发错误。显然,AS试图首先在本地缓存中找到二进制文件(Android Studio / gradle / m2repository),然后尝试从bintray下载它:

  https://jcenter.bintray.com/com/android/tools/build/gradle/2.12/gradle-2.12.jar 

浏览发布的版本,它看起来像上一个版本这里有v2.1.0-alpha1。




  • 为什么v2.12不在bintray呢?它与Android Studio不兼容吗?

  • 如果它兼容,是否有办法下载它并在每个项目的基础上使用本地安装? (我不想在版本控制中破坏较旧的项目)


解决方案

com.android.tools.build:gradle 是Android的Gradle插件。它与gradle distribution不一样。在这里查看gradle android插件的发布/版本信息: https:// bintray。 com / android / android-tools / com.android.tools.build.gradle / view



要更改插件使用的gradle版本,请编辑file:

 < Project> /gradle/wrapper/gradle-wrapper.properties 



并将此行更改为您想要的gradle verison:

  distributionUrl = http \://services.gradle.org/distributions/gradle-2.12-all.zip 

然后重建您的项目。



请记住,您正在使用的android插件版本可能未经过此全新gradle版本的测试并可能导致意想不到的问题。


I've just noticed Gradle has released version 2.12 and according to the release notes the scripts should compile up to 20% faster. I'd like to upgrade to that version in Android Studio.

I'm using v1.5.1 and in the settings I've selected the "Use default gradle wrapper" option, which means that instead of using a local gradle install for every project, a specific gradle version will be used for each project. The version used is the one defined in the build.gradle file. Example:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

Now if I change that to this:

classpath 'com.android.tools.build:gradle:2.12'

then Android Studio can't find that version and throws an error. Apparently AS tries to find the binaries in a local cache first (Android Studio/gradle/m2repository) and then it tries to download it from bintray:

https://jcenter.bintray.com/com/android/tools/build/gradle/2.12/gradle-2.12.jar

Browsing the published builds it looks like the last version available here is v2.1.0-alpha1.

  • Why is v2.12 not in bintray yet? Is it not compatible with Android Studio?
  • If it were compatible, is there a way to download it and use a local install in a per-project basis? (I don't want to break older projects already in version control)

解决方案

com.android.tools.build:gradle is android's plugin for gradle. It is not the same as gradle distribution. See here for release/version information of gradle android plugin: https://bintray.com/android/android-tools/com.android.tools.build.gradle/view

To change the gradle version that the plugin uses, edit the file:

<Project>/gradle/wrapper/gradle-wrapper.properties

and change this line to the gradle verison you want:

distributionUrl=http\://services.gradle.org/distributions/gradle-2.12-all.zip

Then rebuild your project.

Do keep in mind that the android plugin version you're using may not have been tested with this brand new gradle version and could potential cause unexpected issues.

这篇关于如何在Android Studio中使用最新的gradle版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆