Android 成長(zhǎng)在于積累和分享
前言
每次更新完 Android Studio 大概都會(huì)遇到需要升級(jí)Gradle的問題。每次改完Gradle版本后,還要對(duì)應(yīng)改插件版本,這里記錄下對(duì)應(yīng)關(guān)系與官網(wǎng)地址。
Gradle 版本配置位置
可以在 Android Studio 的 File > Project Structure > Project 菜單中指定 Gradle 版本,也可以通過在 gradle/wrapper/gradle-wrapper.properties 文件中修改 Gradle 分發(fā)引用來指定。
-
File > Project Structure > Project
image.png
- 在gradle-wrapper.properties文件中修改distributionUrl字段
distributionUrl=https://services.gradle.org/distributions/gradle-7.3-bin.zip
Gradle 插件版本配置位置
project對(duì)應(yīng)的 build.gradle 文件中或者在 File > Project Structure > Project 中設(shè)置
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
注意
使用 Android Gradle 插件 7.0 構(gòu)建應(yīng)用時(shí),現(xiàn)在需要 JDK 11 才能運(yùn)行 Gradle。Android Studio Arctic Fox 捆綁了 JDK 11,并將 Gradle 配置為默認(rèn)使用 JDK 11,這意味著大多數(shù) Android Studio 用戶不需要對(duì)項(xiàng)目進(jìn)行任何配置更改。
Gradle 對(duì)應(yīng)版本
| 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 - 3.5 |
| 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.3 | 4.10.1+ |
| 3.4.0 - 3.4.3 | 5.1.1+ |
| 3.5.0 - 3.5.4 | 5.4.1+ |
| 3.6.0 - 3.6.4 | 5.6.4+ |
| 4.0.0+ | 6.1.1+ |
| 4.1.0+ | 6.5+ |
| 4.2.0+ | 6.7.1+ |
| 7.0 | 7.0+ |
參考文獻(xiàn)
Android Gradle 插件版本說明(https://developer.android.google.cn/studio/releases/gradle-plugin)
