DataBinding(库必须使用完全相同的版本规范)

时间:2018-01-05 12:48:43

标签: android data-binding android-support-library

摇篮:

buildscript {
ext.kotlin_version = '1.2.10'
repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

=========================

ext {
support_version = '27.0.2'
dagger_version = '2.14.1'
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    //support
    implementation "com.android.support:appcompat-v7:$support_version"
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    //rx
    implementation 'io.reactivex.rxjava2:rxjava:2.1.8'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    //test
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    //Dagger 2
    implementation "com.google.dagger:dagger:$dagger_version"
    kapt "com.google.dagger:dagger-compiler:$dagger_version"
    provided 'org.glassfish:javax.annotation:10.0-b28'
}

它对我有用,但是如果我启用DataBinding:

dataBinding {
    enabled = true
}

我收到了警告com.android.support:appcompat-v7:

所有com.android.support库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到的版本27.0.2,21.0.3。示例包括com.android.support:animated-vector-drawable:27.0.2和com.android.support:support-v4:21.0.3 more ...(Ctrl + F1)

并在ContextCompat中丢失方法checkSelfPermission:

ContextCompat.checkSelfPermission(context, android.Manifest.permission.READ_SMS)

未解决的参考:checkSelfPermission

Gradle file

为什么启用DataBinding会导致这种影响?

1 个答案:

答案 0 :(得分:6)

  

为什么启用DataBinding会导致这种影响?

在幕后,dataBinding { enabled = true }为支持生成的数据绑定代码的运行时库添加了一些依赖项:

  • com.android.databinding:adapters
  • com.android.databinding:baseLibrary
  • com.android.databinding:library

这些依赖项目前依赖于support-v4(21.0.3)的版本。反过来,这会触发您看到的构建错误,因为Google正在尝试强制所有支持库工件都在同一版本上。

FWIW,我提交了an issue来修复数据绑定框架。我希望它能在宇宙热死之前的某个时候得到修复。

解决方法是在support-v4添加您自己的依赖项:

implementation "com.android.support:support-v4:$support_version"

这将导致Gradle拉入您所请求的版本,这比数据绑定正在寻找的版本更新,因此Gradle假定它没问题。事实上,它可能可以,但到目前为止,在我的工作中,我没有遇到任何问题。

相关问题