Unresolved reference: buildFeatures in Android multi module project

848 views Asked by At

Working on a multi-module project, i have the following setup:-

  • android studio = 4.1.3
  • AGP = "4.1.3"
  • kotlin gradle plugin = "1.4.32"
  • using gradle.kts for all my gradle build files

In my (app) module build.gradle.kts i have enabled DataBinding and ViewBinding and everything thing works great:-

android{

    /* compileSdkVersion, buildToolsVersion etc...*/

     buildFeatures {
        dataBinding = true
        viewBinding = true
    }

}

I am using a common Dependencies.kt class in my buildSrc directory is inject dependencies into modules, also using a Plugins.kt class in my buildSrc directory to supply plugins like "com.android.application" and "kapt" etc... to all modules.

In my :modules:rxandroid, build.gradle.kts is like below:

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)

    ...

}

When building the project the follwing error message is thrown to the console log:

Unresolved reference: buildFeatures

And the screenshot for details:-

Error Message

1

There are 1 answers

0
XuSing On

android.dataBinding.isEnabled = true