Android data binding dependency conflict with the support library

有些话、适合烂在心里 提交于 2020-01-02 00:13:11

问题


I'm trying to set up data binding in my Android project like so:

dataBinding {
    enabled = true
}

However, when I add a support library dependency, lint complains:

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 25.1.0, 21.0.3. Examples include 'com.android.support:animated-vector-drawable:25.1.0' and 'com.android.support:support-v4:21.0.3'

When I run ./gradlew app:dependencies, I get the following:

...
+--- com.android.support:appcompat-v7:25.1.0
|    +--- com.android.support:support-annotations:25.1.0
|    +--- com.android.support:support-v4:25.1.0
|    |    +--- com.android.support:support-compat:25.1.0 (*)
|    |    +--- com.android.support:support-media-compat:25.1.0
|    |    |    +--- com.android.support:support-annotations:25.1.0
|    |    |    \--- com.android.support:support-compat:25.1.0 (*)
|    |    +--- com.android.support:support-core-utils:25.1.0
|    |    |    +--- com.android.support:support-annotations:25.1.0
|    |    |    \--- com.android.support:support-compat:25.1.0 (*)
|    |    +--- com.android.support:support-core-ui:25.1.0 (*)
|    |    \--- com.android.support:support-fragment:25.1.0
|    |         +--- com.android.support:support-compat:25.1.0 (*)
|    |         +--- com.android.support:support-media-compat:25.1.0 (*)
|    |         +--- com.android.support:support-core-ui:25.1.0 (*)
|    |         \--- com.android.support:support-core-utils:25.1.0 (*)
|    +--- com.android.support:support-vector-drawable:25.1.0
|    |    +--- com.android.support:support-annotations:25.1.0
|    |    \--- com.android.support:support-compat:25.1.0 (*)
|    \--- com.android.support:animated-vector-drawable:25.1.0
|         \--- com.android.support:support-vector-drawable:25.1.0 (*)
+--- com.android.databinding:library:1.3.1
|    +--- com.android.support:support-v4:21.0.3 -> 25.1.0 (*)
|    \--- com.android.databinding:baseLibrary:2.3.0-dev -> 2.3.0-beta1
...

Any ideas on how to stop link from complaining without disabling it?


回答1:


There is a defect logged for this, which resulted in a more helpful error message: https://issuetracker.google.com/issues/37128971

The solution is to add an explicit dependency on support-v4 in your build.gradle for the support library version that you're using, so if you are using support library 25.1.0:

compile 'com.android.support:support-v4:25.1.0'

As @gopalanrc suggests, starting with Android Gradle Plugin 3.0.0 you should typically use the following instead:

implementation 'com.android.support:support-v4:25.1.0'



回答2:


If you are using gradle 3.0 or greater, add it as below.

implementation 'com.android.support:support-v4:<the_version>'


来源:https://stackoverflow.com/questions/41568032/android-data-binding-dependency-conflict-with-the-support-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!