当前位置: 首页 > 知识库问答 >
问题:

gradle 3.2.1数据绑定问题

万博涛
2023-03-14

当我将android Studio 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

要求:项目:应用

项目格拉德尔

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
}

应用程序。格拉德尔

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'

}

如果我错了,请建议我。

共有3个答案

濮君植
2023-03-14

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

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

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

徐翔
2023-03-14

答案很简单:

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

//Data binding
dataBinding.enabled = true

并删除这两行:

 apply plugin: 'kotlin-kapt'
 kapt "com.android.databinding:compiler:$gradle_version"
谢俊力
2023-03-14

我寻找了许多解决方案,最后发现问题出在一个依赖项上,所以我从应用程序中删除了这个com.android.databinding:compiler:$gradle\u version“。gradle和project成功运行。

 类似资料:
  • 我尝试将属性和一些数据绑定到模板,但下面的代码不起作用。我需要的是呈现n个模板的数量取决于printedForms对象的数量,并在每个模板中实现来自适当对象的数据。请告诉我我的代码有什么问题。 注意:控制台中有如下警告:[Vue warn]:计算表达式“printedForm.docNumber”时出错:TypeError:无法读取未定义(在组件中找到)的属性“docNumber”) 我的VueJ

  • 数据绑定 JXML 中的动态数据来自于该 Page 的 data字段。 简单绑定 数据绑定使用 Mustache 语法(双大括号)将变量包起来,可以作用于以下: 页面内容 <view> hello {{ name }} </view> Page({ data: { name: 'cortana' } }) 组件属性(需要在双引号之内) <view id="{{id}}"> </

  • attr绑定是用来为html元素绑定属性值的,这种绑定非常有用,例如我们需要想一个元素添加title属性,或者为img标签添加src属性。 示例代码: //.W片段 <a bind-attr="{ href: url, title: details }"> Report </a> //js片段 this.url=justep.Bind.observable("year-end.html"),

  • submit绑定只能用在form元素中,当form提交的时候被触发,并且默认阻止form的提交。因此我们通常在submit的处理函数中以ajax的方式提交form表单。 示例代码: //.W片段 <form bind-submit="doSomething"> ... form contents go here ... <button type="submit">Submit</butt

  • with绑定用来创建一个绑定上下文,在子元素内的所有绑定都在这个上下文中进行。 示例代码: //.W片段 <h1 bind-text="city"> </h1> <p bind-with="coords"> Latitude: <span bind-text="latitude"> </span>, Longitude: <span bind-text="longitude"> </span

  • foreach绑定用来处理数组,通常用来将一个数组绑定到一个列表或者table中。在foreach绑定中,我们可以使用if、with等嵌套绑定。 示例代码: //.W片段 <table> <thead> <tr><th>First name</th><th>Last name</th></tr> </thead> <tbody bind-foreach="people"> <tr>