FutterError: Androidx Compatibility Issues

Execution failed for task ‘:app:preDebugBuild’.

Android dependency ‘androidx.core:core’ has different version for the compile (1.0.0) and runtime (1.0.1) classpath. You should manually set the same version via DependencyResolution

Android code uses Android.support library to ensure backward compatibility with older versions. Currently the library has stopped maintenance support, and replaced AndroidX, AndroidX has some additional features and functions of the old library and want to pass, but the two sets of libraries are not compatible, so the error. The future will be for AndroidX-based, Android Support Library is no longer recommended, and will slowly cease to maintain. In addition, starting from Android Studio 3.4.2, the new project has been forced to check the use AndroidX architecture.

Launching lib/main.dart on Redmi Note 7 Pro in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) classpath. You should manually set the same version via DependencyResolution

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s
Finished with error: Gradle task assembleDebug failed with exit code 1

Solution

Currently there are two main online solutions, the first is to avoid the use AndroidX plug-ins, avoid using AndroidX, obviously this will make a lot of compromises, definitely not the best way. Another is integrated AndroidX, in fact, not simply in this way, by the time I first AS do not know why there is no success, manually, then very troublesome, but also prone to error, which may be less suitable for larger old project.
For my problem I found a solution, add the following block of code at the project level build.gradle file will be able to solve the problem

subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.android.support'
                        && !details.requested.name.contains('multidex') ) {
                    details.useVersion "27.1.1"
                }
                if (details.requested.group == 'androidx.core'
                        && !details.requested.name.contains('androidx') ) {
                    details.useVersion "1.0.1"
                }
               }
            }
        }
    }

Complete Code build.gradle

buildscript {
    ext.kotlin_version = '1.3.0'
   repositories {
//        google()
//        jcenter()
        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' }
       google()
   }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

    subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.android.support'
                        && !details.requested.name.contains('multidex') ) {
                    details.useVersion "27.1.1"
                }
                if (details.requested.group == 'androidx.core'
                        && !details.requested.name.contains('androidx') ) {
                    details.useVersion "1.0.2"
                }
                if (details.requested.group == 'androidx.appcompat'
                        && !details.requested.name.contains('androidx') ) {
                    details.useVersion "1.0.2"
                }
            }
        }
    }
}

allprojects {
    repositories {
//        google()
//        jcenter()
        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' }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Published 24 original articles · won praise 5 · Views 3942

Guess you like

Origin blog.csdn.net/qq_41345281/article/details/102630710