简体   繁体   English

在android错误中使用数据绑定:package *。* .databinding不存在

[英]Using data-binding in android error: package *.*.databinding does not exist

I'm trying to implement data-binding in android app. 我正在尝试在Android应用程序中实现数据绑定。 This is the link I'm following to set it up. 是我正在建立的链接。 Even after doing all the necessary implements, I'm getting the following error in gradle-build: 即使在完成所有必要的实现之后,我在gradle-build中遇到以下错误:

error: package com.example.satpracticeapp.databinding does not exist. 错误:包com.example.satpracticeapp.databinding不存在。

(This package is what I'm importing in my MainActivity.java file) I tried this (the data-binding compiler), but it didn't work. (这个包是我在MainActivity.java文件中导入的)我试过这个 (数据绑定编译器),但它没有用。

The problem is I've already successfully tried a hello-world app using data-binding and it works. 问题是我已经使用数据绑定成功尝试了一个hello-world应用程序并且它可以工作。 But, when I try to implement it in an app I made a few weeks ago, I get the error I mentioned above. 但是,当我尝试在几周前制作的应用程序中实现它时,我得到了上面提到的错误。 Searching for the solutions, I copy-pasted the gradle files from my successful hello world app to my old app - that too didn't work out. 在搜索解决方案时,我将gradle文件从我成功的hello world应用程序复制粘贴到我的旧应用程序 - 这也没有成功。

Here is my app level build.gradle 这是我的app level build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.satpracticeapp"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.0'
}

And here's the buildscript of the project level build.gradle file: 这是项目级build.gradle文件的buildscript:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

Here are the links to the minimal version of the three files (if it's needed) 以下是三个文件的最小版本的链接(如果需要)

  1. MainActivity.java MainActivity.java
  2. ViewModel.java ViewModel.java
  3. activity_main.xml activity_main.xml中

After much hair-pulling, I couldn't figure out the solution and getting the same build error again and again. 经过多次拉扯之后,我无法找到解决方案并一次又一次地获得相同的构建错误。 So, as a temporary solution, I'm trying to copy-paste my classes and layouts in the working hello world project. 因此,作为临时解决方案,我正在尝试在工作hello world项目中复制粘贴我的类和布局。 What am I missing? 我错过了什么?

EDIT: 编辑:

After a few hours of pointless searching, I went back to my code. 经过几个小时的毫无意义的搜索,我回到了我的代码。 Checked it word by word and found a typing mistake at the name of a binding variable in the xml file. 逐字检查,发现xml文件中绑定变量名称的输入错误。 Everything works fine now! 现在一切正常!

I had the same issue, turned out to be a duplicate symbol declaration in one of my *.java classes. 我有同样的问题,结果是我的一个* .java类中的重复符号声明。 It's shown in the Gradle console but it was kinda hidden among the databinding errors. 它显示在Gradle控制台中,但有点隐藏在数据绑定错误中。 i had about 72 data binding errors and this duplicate symbol error was in the middle so it's easy to miss. 我有大约72个数据绑定错误,这个重复的符号错误在中间,所以很容易错过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM