【问题标题】:Unable to resolve error of gradle version when migrating to AndroidX迁移到 AndroidX 时无法解决 gradle 版本错误
【发布时间】:2019-11-07 21:41:54
【问题描述】:

当我尝试将自己的项目迁移到 AndroidX 时,错误消息出现在错误对话框中:

The gradle plugin version in your project build.gradle file needs to be set to at least com.android.tools.build:gradle:3.2.0 in order to migrate to AndroidX.

然后我在互联网上搜索了这个错误。发现一个站点说classpath 'com.android.tools.build:gradle:3.2.0' 必须添加到build.gradle。因此,我将这一行添加到 build.gradle 中,如下所示:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:support-core-utils:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

然而,同样的错误发生了。我错过了什么吗?

【问题讨论】:

    标签: android build.gradle androidx


    【解决方案1】:

    检查您的项目级别(非模块)的build.grade

    并更改android的版本gradle plugin

    buildscript {
        ...
    
        dependencies {
            ...
            classpath 'com.android.tools.build:gradle:3.4.1' // it should be more than 3.2.0
        }
    }
    

    【讨论】:

    • 这是正确的答案。该网站太不清楚了,它从未告诉我更改项目级别的第一...不过,谢谢!
    • 不是gradle版本。是android gradle插件的版本
    猜你喜欢
    • 2019-06-27
    • 2019-01-18
    • 1970-01-01
    • 2019-03-23
    • 2019-07-08
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    • 2019-11-29
    相关资源
    最近更新 更多