简体   繁体   English

数据绑定未获得“标识符必须具有XML文件中的用户定义类型”错误

[英]data binding not getting “Identifiers must have user defined types from the XML file” error

I'm learning android data binding. 我正在学习android数据绑定。 The problem I'm facing is that in case of errors related to data binding with my current setup I'm getting very general error messages which give no clue of what and where has happened exactly instead of very specific ones that were mentioned in some topics on data binding ( for instance ). 我面临的问题是,在与当前设置的数据绑定相关的错误的情况下,我会收到非常笼统的错误消息,这些消息无法准确说明发生了什么事情和发生在哪里,而不是某些主题中提到的非常具体的消息关于数据绑定( 例如 )。

Consider following layout: 考虑以下布局:

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">
    <data>
        <!--<import type="android.view.View"/>-->
        <!--<import type="android.text.TextUtils"/>-->
        <variable
            name="movie"
            type="us.kostenko.architecturecomponentstmdb.details.model.Movie" />
    </data>
    <TextView
        <!-- ... -->
        android:text="@{TextUtils.isEmpty(movie.release_date) ? @string/empty_date : movie.release_date}"/>
</layout>

Note that imports are commented out on purpose to trigger an error. 请注意,导入被故意注释掉以触发错误。

I expected to get something like Identifiers must have user defined types from the XML file. TextUtils is missing it 我希望得到类似Identifiers must have user defined types from the XML file. TextUtils is missing it Identifiers must have user defined types from the XML file. TextUtils is missing it error. Identifiers must have user defined types from the XML file. TextUtils is missing it错误。 But the error I'm getting is very general one: 但是我得到的错误是非常普遍的错误:

    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:kaptDebugKotlin'.
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.gradle.api.GradleException: Compilation error. See log for more details
    at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:16)
    at org.jetbrains.kotlin.gradle.internal.KaptWithKotlincTask.compile(KaptWithKotlincTask.kt:79)

I suspect there's something wrong with my setup. 我怀疑我的设置有问题。 I'm using Android studio 3.1.4. 我正在使用Android Studio 3.1.4。

Here's my build.gradle 这是我的build.gradle

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-kapt'
    apply plugin: 'kotlin-android-extensions'
    android {
    //...
        dataBinding { enabled = true }
    }

    dependencies {
        // ...
        kapt "com.android.databinding:compiler:3.1.4"
    }

And the project level one: 和项目一级:

buildscript {
ext.kotlin_version = '1.2.70'
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

Any ideas what I'm missing here? 有什么想法我在这里想念的吗?

Here is mine, that is working fine, gives appropriate error, there is not too much difference. 这是我的,工作正常,给出适当的错误,没有太大的区别。 Try this... 尝试这个...

app-level build.gradle 应用程序级build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 28
    }
    dataBinding {
        enabled = true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
    mavenCentral()
}

project-level build.gradle 项目级build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

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

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

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

相关问题 Android数据绑定 - 错误:(119,29)标识符必须具有XML文件中的用户定义类型。 main_radio_subscribe缺少它 - Android Data binding - Error:(119, 29) Identifiers must have user defined types from the XML file. main_radio_subscribe is missing it 标识符必须具有XML文件中的用户定义类型,并带有observablefield的数据绑定 - Identifiers must have user defined types from the XML file, databinding with observablefield 查看android数据绑定一定有标签错误 - View must have a tag error in android data binding 绑定来自 XML 文件的格式化字符串,数据绑定无法正常工作 - Binding formatted strings from XML file with data binding not working correctly Android-从Web上的XML文件获取数据 - Android - Getting data from XML file on the web Android数据绑定XML错误 - Android Data Binding XML Error android:从xml文件获取数据 - android : getting data from xml file 从XML解析数据时出现错误 - Getting error in parsing data from XML 出现错误错误:res / menu / mainMenu.xml:无效的文件名:必须仅包含[a-z0-9_。] - getting error Error:res/menu/mainMenu.xml:invalid file name:must contain only[a-z0-9_.] 使用Android O的“android:fontFamily”时出现错误“文件名必须以.xml结尾”? - Getting error “file name must end with .xml” while using the “android:fontFamily” of Android O?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM