数据绑定插件使用旧版本的支持库

时间:2018-01-30 09:27:30

标签: java android android-studio gradle android-databinding

将支持库更新为27.0.2后,我收到此错误。

Error:Execution failed for task ':app:preDebugBuild'.
> Android dependency 'com.android.support:support-v4' has different version for the compile (21.0.3) and runtime (27.0.2) classpath. You should manually set the same version via DependencyResolution

我的项目中启用了数据绑定。

dataBinding.enabled = true

当我跑步时

gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath

这就是我得到的:

+--- com.android.databinding:library:1.3.1
|    +--- com.android.support:support-v4:21.0.3
|    |    \--- com.android.support:support-annotations:21.0.3 -> 26.0.2
|    \--- com.android.databinding:baseLibrary:2.3.0-dev -> 3.0.1
+--- com.android.databinding:baseLibrary:3.0.1
+--- com.android.databinding:adapters:1.3.1
|    +--- com.android.databinding:library:1.3 -> 1.3.1 (*)
|    \--- com.android.databinding:baseLibrary:2.3.0-dev -> 3.0.1
+--- com.squareup.leakcanary:leakcanary-android:1.5.1
|    \--- com.squareup.leakcanary:leakcanary-analyzer:1.5.1
|         +--- com.squareup.haha:haha:2.0.3
|         \--- com.squareup.leakcanary:leakcanary-watcher:1.5.1
+--- project :general
|    +--- com.android.databinding:library:1.3.1 (*)
|    +--- com.android.databinding:baseLibrary:3.0.1
|    \--- com.android.databinding:adapters:1.3.1 (*)
+--- com.jakewharton:butterknife:8.8.1
|    \--- com.jakewharton:butterknife-annotations:8.8.1
+--- com.github.bumptech.glide:glide:4.2.0
|    +--- com.github.bumptech.glide:gifdecoder:4.2.0
|    |    \--- com.android.support:support-annotations:26.0.2
|    +--- com.github.bumptech.glide:disklrucache:4.2.0
|    \--- com.github.bumptech.glide:annotations:4.2.0
\--- com.github.apl-devs:appintro:v4.2.2

这清楚地表明Android数据绑定库正在使用版本为21.0.3的支持v4,这会导致冲突。

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:2)

将此添加到您的dependencies关闭:

  implementation "com.android.support:support-v4:26.0.2"

这将导致Gradle升级support-v4依赖项以匹配其余的支持库工件。

答案 1 :(得分:1)

确定。我自己找到解决方案: 在您的应用模块中添加以下内容(不在库或任何其他模块中):

android {
...
    configurations.all {
            resolutionStrategy.force "com.android.support:support-v4:${supportLib}"
            resolutionStrategy.force "com.android.support:appcompat-v7:${supportLib}"
            resolutionStrategy.force "com.android.support:design:${supportLib}"
            resolutionStrategy.force "com.android.support:recyclerview-v7:${supportLib}"
            resolutionStrategy.force "android.arch.lifecycle:runtime:${lifecycleExtensions}"
        }
}

它将强制gradle使用更新的依赖项并解决冲突错误。