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

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

问题描述

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

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.

我使用的是 v1.5.1 并且在设置中我选择了使用默认 gradle 包装器"选项,这意味着不是为每个项目使用本地 gradle 安装,而是每个项目都将使用特定的 gradle 版本项目.使用的版本是 build.gradle 文件中定义的版本.示例:

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'

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

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

浏览已发布的版本,这里的最新版本似乎是 v2.1.0-alpha1.

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

  • 为什么 v2.12 还没有在 bintray 中?与 Android Studio 不兼容吗?
  • 如果它兼容,有没有办法下载它并在每个项目的基础上使用本地安装?(我不想破坏已经在版本控制中的旧项目)

推荐答案

com.android.tools.build:gradle 是 android 的 gradle 插件.它与 gradle 分布不同.gradle android 插件的发布/版本信息见这里:https://maven.google.com/web/index.html?q=gradle#com.android.tools.build:gradle

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://maven.google.com/web/index.html?q=gradle#com.android.tools.build:gradle

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

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

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

并将这一行更改为您想要的 gradle 版本:

and change this line to the gradle verison you want:

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

然后重建您的项目.

请记住,您使用的 android 插件版本可能尚未使用这个全新的 gradle 版本进行测试,并且可能会导致意外问题.

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 gradle 插件到 2020 年 2 月与 Gradle 版本的兼容性

android gradle plugin to Gradle version compatibility as of Feb2020

Plugin version      Required Gradle version
--                  --
1.0.0 - 1.1.3       2.2.1 - 2.3
1.2.0 - 1.3.1       2.2.1 - 2.9
1.5.0               2.2.1 - 2.13
2.0.0 - 2.1.2       2.10 - 2.13
2.1.3 - 2.2.3       2.14.1+
2.3.0+              3.3+
3.0.0+              4.1+
3.1.0+              4.4+
3.2.0 - 3.2.1       4.6+
3.3.0 - 3.3.2       4.10.1+
3.4.0 - 3.4.1       5.1.1+
3.5.0 - 3.5.3       6.0.1+
3.6.0+              6.0.1+

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

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