android - 更新到 com.android.tools.build :gradle:3. 4.1 -> jRuntimeException : android. databinding.tool.util.LoggedErrorException:发现数据绑定(bind)错误

标签 android exception android-gradle-3.0

安卓工作室 3.4.1。

在我的 android 项目中的 build.gradle 中:

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

buildscript {
    ext.ANDROIDX_TEST = '1.2.0-alpha05'
    ext.ESPRESSO_VERSION = '3.2.0-alpha02'
    ext.KOTLIN_VERSION = '1.3.40'
    ext.KOTLIN_COROUTINE_VERSION = '1.2.1'
    ext.RETROFIT_VERSION = '2.6.0'


    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        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 {
        google()
        jcenter()
    }
}

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

这里是 app/build.gradle:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation('com.crashlytics.sdk.android:crashlytics:2.7.0@aar') { transitive = true; }

    implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha04'
    implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha06'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
    implementation "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION"
    implementation "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION"
    implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'

    implementation 'com.yuyh.json:jsonviewer:1.0.6'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION"
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha01'
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$KOTLIN_COROUTINE_VERSION"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLIN_COROUTINE_VERSION"

    implementation project(':common')

    androidTestCompile 'com.azimolabs.conditionwatcher:conditionwatcher:0.2'

    // Espresso framework
    androidTestImplementation "androidx.test.espresso:espresso-core:$ESPRESSO_VERSION"
    androidTestImplementation "androidx.test.espresso:espresso-intents:$ESPRESSO_VERSION"
    androidTestImplementation "androidx.test.espresso:espresso-contrib:$ESPRESSO_VERSION"

    androidTestImplementation "androidx.test:rules:$ANDROIDX_TEST"
    androidTestImplementation "androidx.test:runner:$ANDROIDX_TEST"
    // UI Automator framework
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
    androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.8.0'

    testImplementation 'junit:junit:4.12'
}

并且项目成功构建并运行。 但更新后:

 classpath 'com.android.tools.build:gradle:3.4.1'

构建时出现错误:

java.lang.RuntimeException: android.databinding.tool.util.LoggedErrorException: Found data binding errors.
****/ data binding error ****msg:Missing import expression although it is registered
file:D:\dev\myproject\android\MP\app\src\main\res\layout\wallet_list_item.xml
****\ data binding error ****
****/ data binding error ****msg:Missing import expression although it is registered
file:D:\dev\myproject\android\MP\app\src\main\res\layout\trader_list_item.xml
****\ data binding error ****
****/ data binding error ****msg:Missing import expression although it is registered
file:D:\dev\myproject\android\MP\app\src\main\res\layout\trader_details_activity.xml
****\ data binding error ****
****/ data binding error ****msg:Missing import expression although it is registered
file:D:\dev\myproject\android\MP\app\src\main\res\layout\wallet_details_activity.xml
****\ data binding error ****

    at com.sun.tools.javac.main.Main.compile(Main.java:553)
    at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
    at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)

这里wallet_list_item.xml

<?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="java.lang.Boolean" />

        <import type="com.myprojecttm.android.util.CommonUtil" />

        <variable
            name="handler"
            type="com.myprojecttm.android.ui.adapter.WalletListItemAdapter" />

        <variable
            name="item"
            type="com.myprojecttm.android.model.Wallet" />

    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/walletContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="@{() -> handler.onClickItemDetails(item)}"
        app:inTrade="@{item.inTrade}">
...

最佳答案

尝试删除 <import type="java.lang.Boolean" /> .如果您从 java.lang 导入了任何包,没有必要,因为它已经自动导入。

关于android - 更新到 com.android.tools.build :gradle:3. 4.1 -> jRuntimeException : android. databinding.tool.util.LoggedErrorException:发现数据绑定(bind)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56805853/

相关文章:

android - Kotlin:使用用 Java 编写的库时无法访问 lambda 函数内的代码

android - 如何在android中将多个图像组合成一个图像?

python - 使用 OpenStack Nova 异常

java - 用户界面 :repeat inside a ui:repeat and LazyInitException

python - 处理 Python 中可能同时出现的错误

android - 在 Android Studio 3.0 中使用 Precondition.checkNotNull() 会产生 lint 错误

android - 可以将 FileOutputStream 转换为字节数组吗?

android - 在 Kotlin 中使用 @Parcelize 注释的 NoSuchMethodError

android - 使用Android SDK 28 Proguard更新Gradle插件3失败

android - 将 gradle-tool 更新到 3.1.0-beta3 或 3.2.0-alpha03 后出现新错误