在 Android Studio 3.3 Canary 3 Kotlin 项目中找不到 DataBindingComponent 符号。

4

我刚刚在启用 Kotlin 的 Android Studio 3.3 Canary 3 上创建了一个新项目。然后,我也启用了数据绑定,但是出现了一个错误,显示无法找到 DataBindingComponent 类。

以下是我的 gradle 文件:

buildscript {
    apply from: 'versions.gradle'
    addRepos(repositories)
    dependencies {
        classpath deps.android_gradle_plugin
        classpath deps.kotlin.plugin
        classpath deps.kotlin.allopen
        classpath deps.navigation.safe_args_plugin
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
    repositories {
        google()
    }
}

allprojects {
    addRepos(repositories)
}


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

我的模块 gradle 文件:

 apply plugin: 'com.android.application'

    apply plugin: 'kotlin-android'

    apply plugin: 'kotlin-android-extensions'

    apply plugin: 'kotlin-kapt'

    apply plugin: 'androidx.navigation.safeargs'


    android {
        compileSdkVersion build_versions.target_sdk
        buildToolsVersion build_versions.build_tools
        defaultConfig {
            applicationId "arca.advanced.mg.com.myapplication"
            minSdkVersion build_versions.min_sdk
            targetSdkVersion build_versions.target_sdk
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
        dataBinding {
            enabled = true
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }

    dependencies {
        implementation deps.support.app_compat
        implementation deps.support.recyclerview
        implementation deps.support.cardview
        implementation deps.support.design
        implementation deps.support.legacy
        implementation deps.navigation.fragment_ktx
        implementation deps.room.runtime
        implementation deps.lifecycle.runtime
        implementation deps.lifecycle.extensions
        implementation deps.lifecycle.java8
        implementation deps.retrofit.runtime
        implementation deps.retrofit.gson
        implementation deps.glide.runtime

        implementation deps.dagger.runtime
        implementation deps.dagger.android
        implementation deps.dagger.android_support
        implementation deps.constraint_layout
        implementation deps.kotlin.stdlib

        implementation deps.timber
        implementation deps.rx.java
        implementation deps.rx.android

        kapt deps.dagger.android_support_compiler
        kapt deps.dagger.compiler
        kapt deps.room.compiler
        kapt deps.lifecycle.compiler
    }

我的片段文件
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

        <variable
            name="viewModel"
            type="arca.advanced.mg.com.arca.ui.splash.SplashViewModel" />

    </data>


    <RelativeLayout
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">

        <ImageView
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_centerInParent="true"
            android:src="@mipmap/ic_launcher" />
    </RelativeLayout>

</layout>

以下是我的错误信息:

在这里输入图片描述


注:本文中的html标签已被保留。
1个回答

0

我认为这是kapt冲突。

如果可能的话,尝试关闭Dagger并检查来自Room的错误,如下所示:

Fields annotated with @Relation cannot be constructor parameters. These values are fetched after the object is constructed.

Cannot find setter for field.

Cannot figure out how to save this field into database.

如果这并没有帮助,尝试逐个关闭kapt的libs,并仔细检查错误日志。
使用./gradlew app:dependencies检查传递依赖项,可能与androidx有关的问题。
还要检查gradlew app:dependencies --configuration kapt,也许你会发现一些可疑的东西。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接