Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 744
ADev Avatar asked Jan 10 '17 11:01

ADev


People also ask

Is data binding deprecated in Android?

Kotlin Android Extensions is deprecated, which means that using Kotlin synthetics for view binding is no longer supported.

What is DataBindingUtil in Android?

DataBindingUtil.setContentView(this, R.layout.activity_main) DataBindingUtil is a Utility class to create ViewDataBinding from layouts. A binding class is generated for each layout file. The default naming convention used for the generated class is based on the name of the layout file.

How do I enable kotlin DataBinding?

Installing the required dependencies Launch Android studio and create a new project. Once the project is ready, go to the Gradle scripts folder and open build. gradle (module: app) . Add buildFeatures and set databinding to true .


1 Answers

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'
like image 180
Uli Avatar answered Oct 17 '22 06:10

Uli