4

I just created a new project on Android Studio 3.3 Canary 3 with Kotlin enabled. Then I also enabled data binding, but I'm getting an error saying that it could not find the DataBindingComponent class.

Here is my gradle file

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
}

My module gradle file:

 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
    }

my fragment file

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

and here is my error

enter image description here

fish40
  • 5,738
  • 17
  • 50
  • 69

1 Answers1

0

I think it's kapt conflict.

Try to turn off Dagger if it's possible and check errors from Room like this:

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.

If it will not help, try to turn off libs with kapt's one by one and check the error log carefully.

Check with ./gradlew app:dependencies transitive dependencies, maybe problems with androidx.

Also check gradlew app:dependencies --configuration kapt maybe you will find something suspicious

Konstantin Kuznetsov
  • 1,188
  • 10
  • 13