【问题标题】:Cannot find symbol DataBindingComponent on Android Studio 3.3 Canary 3 Kotlin project在 Android Studio 3.3 Canary 3 Kotlin 项目中找不到符号 DataBindingComponent
【发布时间】:2019-01-06 11:25:48
【问题描述】:

我刚刚在启用 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>

这是我的错误

【问题讨论】:

    标签: android android-studio data-binding kotlin


    【解决方案1】:

    我认为这是 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也许你会发现一些可疑的东西

    【讨论】:

      猜你喜欢
      • 2018-11-08
      • 1970-01-01
      • 1970-01-01
      • 2019-01-13
      • 1970-01-01
      • 2022-01-02
      • 2020-07-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多