簡體   English   中英

數據綁定未獲得“標識符必須具有XML文件中的用戶定義類型”錯誤

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

我正在學習android數據綁定。 我面臨的問題是,在與當前設置的數據綁定相關的錯誤的情況下,我會收到非常籠統的錯誤消息,這些消息無法准確說明發生了什么事情和發生在哪里,而不是某些主題中提到的非常具體的消息關於數據綁定( 例如 )。

考慮以下布局:

<?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>

請注意,導入被故意注釋掉以觸發錯誤。

我希望得到類似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錯誤。 但是我得到的錯誤是非常普遍的錯誤:

    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)

我懷疑我的設置有問題。 我正在使用Android Studio 3.1.4。

這是我的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"
    }

和項目一級:

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"
}

有什么想法我在這里想念的嗎?

這是我的,工作正常,給出適當的錯誤,沒有太大的區別。 嘗試這個...

應用程序級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()
}

項目級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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM