简体   繁体   中英

Android data binding dependency conflict with the support library

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?

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'

如果您使用的是gradle 3.0或更高版本,请按以下方式添加。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM