Flutter & AndroidX 不兼容 如何手动设置依赖
Flutter & AndroidX incompatibility How to set a dependency manually
由于 AndroidX 不兼容,我在编译时遇到错误:
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
我在 -> this post <- 之后添加了一些代码 build.gradle
allprojects {
configurations.all {
resolutionStrategy.force"androidx.vectordrawable:vectordrawable:1.0.0",
}
repositories {
google()
jcenter()
}
下一个 运行 给了我另一个错误
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
我试着添加这个
"androidx.vectordrawable:vectordrawable:1.0.0","androidx.core:core:1.0.0",
但我可能做错了,因为我得到了经典 "unexpected bla bla bla"
有什么建议吗?
提前致谢
[edit] 我也试过这个老把戏,但没用
(还根据需要降级软件包 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"
}
}
}
}
现在 returns 一个不同的错误
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
- 在 android/gradle/wrapper/gradle-wrapper.properties 中更改以 distributionUrl 开头的行,如下所示:distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip
2.In android/build.gradle, 替换:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
来自
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:
在android{下,确保compileSdkVersion和targetSdkVersion至少为28。
5.Replace 所有已弃用的库与 AndroidX 等效项。例如,如果您使用默认的 .gradle 文件,请进行以下更改:
在android/app/build.gradle
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
来自
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
最后在dependencies下替换
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
来自
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
您需要将此指示与最新版本的...一起使用:)
1) 在
android/gradle/wrapper/gradle-wrapper.properties
用最新的 gradle 替换以 distributionUrl 开头的行:
> distributionUrl = https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
2) 在
android/build.gradle
您需要更换:
> dependencies {
> classpath 'com.android.tools.build:**gradle:x.x.x**' }
和
dependencies { classpath 'com.android.tools.build:**gradle:3.5.0**' }
3) 在 android/gradle.properties 中粘贴此
android.enableJetifier=true android.useAndroidX=true
4) 在android/app/build.gradle中:确保compileSdkVersion和targetSdkVersion 至少有 28 个``
最重要的在这里:
在 android/app/build.gradle 中:替换
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
与`
> testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
`
替换
> androidTestImplementation 'com.android.support.test:runner:x.x.x'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:x.x.x'
和
> androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
始终确保新添加的依赖项与您的 gradle 版本相匹配,
您可能需要升级或降级依赖项以匹配您的 gradle 版本,但最重要的是,建议使用最新的 gradle 版本并将其与最新的插件依赖项匹配以避免这些错误。
由于 AndroidX 不兼容,我在编译时遇到错误:
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
我在 -> this post <- 之后添加了一些代码 build.gradle
allprojects {
configurations.all {
resolutionStrategy.force"androidx.vectordrawable:vectordrawable:1.0.0",
}
repositories {
google()
jcenter()
}
下一个 运行 给了我另一个错误
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
我试着添加这个
"androidx.vectordrawable:vectordrawable:1.0.0","androidx.core:core:1.0.0",
但我可能做错了,因为我得到了经典 "unexpected bla bla bla"
有什么建议吗?
提前致谢
[edit] 我也试过这个老把戏,但没用 (还根据需要降级软件包 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"
}
}
}
}
现在 returns 一个不同的错误
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
- 在 android/gradle/wrapper/gradle-wrapper.properties 中更改以 distributionUrl 开头的行,如下所示:distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip
2.In android/build.gradle, 替换:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
来自
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:
在android{下,确保compileSdkVersion和targetSdkVersion至少为28。
5.Replace 所有已弃用的库与 AndroidX 等效项。例如,如果您使用默认的 .gradle 文件,请进行以下更改:
在android/app/build.gradle
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
来自
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
最后在dependencies下替换
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
来自
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
您需要将此指示与最新版本的...一起使用:)
1) 在
android/gradle/wrapper/gradle-wrapper.properties
用最新的 gradle 替换以 distributionUrl 开头的行:
> distributionUrl = https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
2) 在
android/build.gradle
您需要更换:
> dependencies {
> classpath 'com.android.tools.build:**gradle:x.x.x**' }
和
dependencies { classpath 'com.android.tools.build:**gradle:3.5.0**' }
3) 在 android/gradle.properties 中粘贴此
android.enableJetifier=true android.useAndroidX=true
4) 在android/app/build.gradle中:确保compileSdkVersion和targetSdkVersion 至少有 28 个``
最重要的在这里: 在 android/app/build.gradle 中:替换
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
与`
> testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
`
替换
> androidTestImplementation 'com.android.support.test:runner:x.x.x'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:x.x.x'
和
> androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
始终确保新添加的依赖项与您的 gradle 版本相匹配, 您可能需要升级或降级依赖项以匹配您的 gradle 版本,但最重要的是,建议使用最新的 gradle 版本并将其与最新的插件依赖项匹配以避免这些错误。