在一个多模块项目上工作,我有以下设置: -
- 安卓工作室 = 4.1.3
- AGP = "4.1.3"
- kotlin gradle 插件 = "1.4.32"
- 对我所有的 gradle 构建文件使用 gradle.kts
在我的(应用程序)模块build.gradle.kts
中,我启用了 DataBinding 和 ViewBinding,一切都很好:-
android{
/* compileSdkVersion, buildToolsVersion etc...*/
buildFeatures {
dataBinding = true
viewBinding = true
}
}
我Dependencies.kt
在 buildSrc 目录中使用了一个通用类,将依赖项注入到模块中,还使用Plugins.kt
我的 buildSrc 目录中的一个类为所有模块提供“com.android.application”和“kapt”等插件。
在我的:modules:rxandroid
,build.gradle.kts
如下所示:
plugins {
/* defined in Plugins.kt*/
androidLibrary()
kotlinAndroid()
kotlinKapt()
}
android {
compileSdkVersion(AndroidSDK.compileSdk)
buildToolsVersion(AndroidSDK.buildTools)
defaultConfig {
minSdkVersion(DefaultConfig.minSdk)
targetSdkVersion(DefaultConfig.targetSdk)
}
/*
compilation error kicks in here, if the below block is removed eveyrthing works fine
but of ocurs i can't used either ViewBinding or DataBinding
*/
buildFeatures {
dataBinding = true
viewBinding = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
// For Kotlin projects
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
testImplementation(TestLibs.junit)
/* defined in Dependencies.kt*/
androidTestImplementation(TestLibs.runner)
androidTestImplementation(TestLibs.espresso)
implementation (KotlinLibs.kotlin_lib)
implementation (KotlinLibs.kotlin_coroutines_core)
implementation (KotlinLibs.kotlin_coroutine_android)
implementation (KotlinLibs.kotlin_viewmodel_ktx)
implementation (AndroidX.android_app_compat)
implementation (AndroidX.android_constrain_layout)
implementation (AndroidX.android_recyclerview)
implementation (AndroidX.android_lifecycle_extensions)
implementation (AndroidX.android_core_ktx)
implementation (AndroidX.lifecycle_runtime_ktx)
...
}
构建项目时,控制台日志中会出现以下错误消息:
Unresolved reference: buildFeatures
以及详细信息的屏幕截图:-