我刚刚在启用了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>
这是我的错误
答案 0 :(得分: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的库,并仔细检查错误日志。
检查./gradlew app:dependencies
的传递依赖项,也许是androidx出现问题。
还要检查gradlew app:dependencies --configuration kapt
,也许您会发现可疑的东西