[英]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.