【问题标题】:Issue with data binding with gradle 3.2.1gradle 3.2.1 的数据绑定问题
【发布时间】:2018-10-16 11:40:28
【问题描述】:

当我将 android studios 3.2.0 更新到 3.2.1 时。我使用了数据绑定,当运行项目时显示这样的错误,如果我错了请建议我。

Could not find com.android.databinding:compiler:3.2.1.
Searched in the following locations:
file:/C:/Users/Taufiq/AppData/Local/Android/Sdk/extras/m2repository/com/android/databinding/compiler/3.2.1/compiler-3.2.1.pom
file:/C:/Users/Taufiq/AppData/Local/Android/Sdk/extras/m2repository/com/android/databinding/compiler/3.2.1/compiler-3.2.1.jar
file:/C:/Users/Taufiq/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/databinding/compiler/3.2.1/compiler-3.2.1.pom
file:/C:/Users/Taufiq/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/databinding/compiler/3.2.1/compiler-3.2.1.jar
file:/C:/Users/Taufiq/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/databinding/compiler/3.2.1/compiler-3.2.1.pom
file:/C:/Users/Taufiq/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/databinding/compiler/3.2.1/compiler-3.2.1.jar
https://repo.maven.apache.org/maven2/com/android/databinding/compiler/3.2.1/compiler-3.2.1.pom
https://repo.maven.apache.org/maven2/com/android/databinding/compiler/3.2.1/compiler-3.2.1.jar
https://jcenter.bintray.com/com/android/databinding/compiler/3.2.1/compiler-3.2.1.pom
https://jcenter.bintray.com/com/android/databinding/compiler/3.2.1/compiler-3.2.1.jar     
https://dl.google.com/dl/android/maven2/com/android/databinding/compiler/3.2.1/compiler-3.2.1.jar

要求: 项目:应用程序

项目.gradle

buildscript {
    ext{
        kotlin_version = '1.2.71'
        gradle_version = '3.2.1'
    }
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        google()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.2.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenCentral()
        jcenter()
        maven { url 'https://maven.google.com' }
        maven { url "https://jitpack.io" }
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.taufik.kotlinbindingtest"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    kapt "com.android.databinding:compiler:$gradle_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}

如果我错了,请建议我。

【问题讨论】:

  • 从 android studio 的设置中禁用 gradle 离线工作。
  • @Jeel Vankhede 我已经禁用了离线工作。
  • 使用 android.databinding.enableV2=true 而不是 dataBinding { enabled = true } 并删除隐式 annotationProcessor。
  • 当添加 android.databinding.enableV2=true 时,它会显示像这样的错误 Could not get unknown property 'databinding' for object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.
  • 我知道了,请从 app.gradle 中删除这个 kapt "com.android.databinding:compiler:$gradle_version"

标签: android android-databinding


【解决方案1】:

我寻找了很多解决方案,最后我发现问题出在一个依赖项中,所以我从 app.gradle 中删除了这个 kapt "com.android.databinding:compiler:$gradle_version" 并且项目成功运行。

【讨论】:

  • 这工作谢谢。有人可以解释一下吗!
  • 我也必须删除 apply plugin: 'kotlin-kapt' 行。
  • apply plugin: 'kotlin-kapt' 但是当你删除这个插件时,你也不能使用bindingAdapter比如BR
【解决方案2】:

答案很简单:

只需在 gradle 应用程序中添加这些行

//Data binding
dataBinding.enabled = true

删除这两行:

 apply plugin: 'kotlin-kapt'
 kapt "com.android.databinding:compiler:$gradle_version"

【讨论】:

    【解决方案3】:

    从 Android Studio 3.2 开始,不再需要此 kapt 插件。

    但是,如果没有此插件,则在编译时出现任何错误时的错误消息都是神秘的。 因此,现在看来唯一的选择是将您的 Gradle 版本降级到 3.1.4。

    感谢http://mobiledevhub.com/2018/01/05/android-two-way-databinding/的文章

    【讨论】:

      猜你喜欢
      • 2019-04-24
      • 2017-12-16
      • 2011-01-17
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多