我正在尝试在我的Android项目中设置数据绑定,如下所示:
dataBinding { enabled = true }
但是,当我添加支持库依赖项时,lint会抱怨:
所有com.android.support库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃).发现版本25.1.0,21.0.3.示例包括'com.android.support:animated-vector-drawable:25.1.0'和'com.android.support:support-v4:21.0.3'
当我跑步时./gradlew app:dependencies
,我得到以下内容:
... +--- 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 ...
关于如何在不禁用的情况下停止抱怨链接的任何想法?
为此记录了一个缺陷,从而产生了更有用的错误消息:https://issuetracker.google.com/issues/37128971
解决方案是在build.gradle中为support-v4添加对您正在使用的支持库版本的显式依赖,因此如果您使用的是支持库25.1.0:
compile 'com.android.support:support-v4:25.1.0'
正如@gopalanrc建议的那样,从Android Gradle Plugin 3.0.0开始,您通常应该使用以下代码:
implementation 'com.android.support:support-v4:25.1.0'