Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to resolve error of gradle version when migrating to AndroidX

When I tried to migrate my own project to AndroidX, the error message appeared on a error dialog:

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.

Then I googled this error on the Internet. A site was found that it said classpath 'com.android.tools.build:gradle:3.2.0' has to be added to the build.gradle. Therefore, I added the line to the build.gradle like this:

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()
    }
}

However, the same error happened. Am I missing something?

like image 284
Sunny Leung Avatar asked Jun 26 '19 02:06

Sunny Leung


People also ask

How do I move to AndroidX?

From Android Studio version 3.2 and above access the "Refactor > Migrate to AndroidX..." menu. It will instantly migrate your source code. This will work in most cases. Still, in some situations you may need to use a more technical way of updating your project.

How do I upgrade Android gradle to latest version?

You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or update your Gradle version using the command line. The preferred way is to use the Gradle Wrapper command line tool, which updates the gradlew scripts. The following example sets the Gradle version to 7.5.


1 Answers

Check your build.grade of Project level ( Not Module )

And change the version of the android gradle plugin:

buildscript {
    ...

    dependencies {
        ...
        classpath 'com.android.tools.build:gradle:3.4.1' // it should be more than 3.2.0
    }
}
like image 157
c-an Avatar answered Nov 05 '22 02:11

c-an