Niju
Niju

Reputation: 41

Could not find method dataBinding() for arguments on project ':app' of type org.gradle.api.Project

I am getting "Could not find method dataBinding() for arguments on project ':app' of type org.gradle.api.Project." while adding databinding{enable = true} to app gradle file. Didnt find any solution in stackflow.

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.example.ex1"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dataBinding{
    enabled = true
}



dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Upvotes: 4

Views: 2686

Answers (3)

Khaled Saifullah
Khaled Saifullah

Reputation: 2289

You must use the dataBinding section inside the the android section like the following

android {
    ...
    dataBinding {
        enabled true
    }
}

Upvotes: 3

Ksenia Krasotina
Ksenia Krasotina

Reputation: 31

See the link: https://developer.android.com/topic/libraries/data-binding/start

You should set the following:

dataBinding {
enabled = true }

inside the android section, before the closing brace. So it will fix the problem :)

Upvotes: 3

CommonsWare
CommonsWare

Reputation: 1007634

As I wrote in a comment, the databinding closure goes inside the android closure. Your current build.gradle file has it outside the android closure.

So, switch to:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.example.ex1"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    dataBinding{
        enabled = true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Upvotes: 0

Related Questions