ERROR: Gradle version 2.2 is required. Current version is 5.1.1

23 阅读1分钟

在github看一些开源项目时,由于grdle版本太低,并且Android studio支持gradle最低版本4.8以上,编译运行经常需要修改gralde版本,或者使用本地已缓存的gradle版本(提升编译速度和性能)。

常遇到:ERROR: Gradle version 2.2 is required. Current version is xxx的问题。

根本原因是: gradle版本和插件版本不兼容导致的,修改方法参考以下对照方法修改即可:

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+          5.1.1+

project工程build.gradle文件中按照上面对照关系修改为正确兼容版本即可: classpath 'com.android.tools.build:gradle:3.2.1'

另外提升编译速度的修改:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven {
            url 'http://maven.aliyun.com/nexus/content/groups/public' }

//        jcenter()
//        maven {
//            url 'https://maven.google.com/'
//            name 'Google'
//        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven {
            url 'http://maven.aliyun.com/nexus/content/groups/public' }
//        jcenter()
//        maven {
//            url 'https://maven.google.com/'
//            name 'Google'
//        }
    }
}