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

Java 数据绑定插件使用旧版本的支持库,java,android,android-studio,gradle,android-databinding,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 versi

我在将支持库更新到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的support v4,这导致了冲突


有人能帮忙吗?

将此添加到您的
依赖项中
结束:

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

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

确定。我自己找到了解决办法: 在应用程序模块中添加以下内容(不在库或任何其他模块中):


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

此问题不是由数据绑定引起的,因为它不使用任何依赖项。只需执行“构建->清理项目”或“构建->重建项目”。@HemantParmar:不,它不工作。这个答案可能会帮助您:您使用的是Android Studio 3.x还是Android Studio 2.x?我认为我们更新了数据绑定,以使用AS 3的较新依赖项。0@GeorgeMount:简而言之。
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}"
        }
}