Flutter & AndroidX incompatibility How to set a de

2019-08-22 01:43发布

问题:

I'm getting error(s) while compiling due to AndroidX incompatibility:

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

following -> this post <- I've added some code to build.gradle

allprojects {

configurations.all {
    resolutionStrategy.force"androidx.vectordrawable:vectordrawable:1.0.0",
}
repositories {
    google()
    jcenter()
}

next run gave me this other error

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

I tried to add this

"androidx.vectordrawable:vectordrawable:1.0.0","androidx.core:core:1.0.0",

but I'm probably doing it wrong, since I get the classical "unexpected bla bla bla"

any suggestion?

thanks in advance

[edit] i've tried this old trick as well, but didn't work (also downgrading the packages as required HERE)

rootProject.allprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'androidx.core') {
                details.useVersion "1.0.1"
            }
            if (details.requested.group == 'androidx.lifecycle') {
                details.useVersion "2.0.0"
            }
            if (details.requested.group == 'androidx.versionedparcelable') {
                details.useVersion "1.0.0"
            }
        }
    }
}

now returns a different error

Android dependency 'androidx.appcompat:appcompat' has different version for the compile (1.0.0) and runtime (1.0.2) classpath. You should manually set the same version via DependencyResolution

回答1:

  1. In android/gradle/wrapper/gradle-wrapper.properties change the line starting with distributionUrl like this: distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip

2.In android/build.gradle, replace:

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

by

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

3.In android/gradle.properties, append

android.enableJetifier=true
android.useAndroidX=true

4.In android/app/build.gradle:

Under android {, make sure compileSdkVersion and targetSdkVersion are at least 28.

5.Replace all deprecated libraries with the AndroidX equivalents. For instance, if you’re using the default .gradle files make the following changes:

In android/app/build.gradle

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

by

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Finally, under dependencies replace

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

by

androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'