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?
Kotlin Android Extensions is deprecated, which means that using Kotlin synthetics for view binding is no longer supported.
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.
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 .
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With