1
votes

Hey everyone how do we enable databinding in android_plugin_version = '3.4.0' ? as my android studio I install the latest version and I receive another error when downgrading the android_plugin_version = '3.4.0' to 3.2.xx.

Project gradle

buildscript {
ext {
    kotlin_version = '1.3.31'
    android_plugin_version = '3.4.0'
}
repositories {
    google()
    jcenter()
    maven { url 'https://maven.google.com' }
}
dependencies {
    classpath "com.android.tools.build:gradle:$android_plugin_version"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  }
}

allprojects {
repositories {
    google()
    jcenter()
    mavenCentral()
 }
}

Module

 apply plugin: 'com.android.application'

 apply plugin: 'kotlin-android'

 apply plugin: 'kotlin-android-extensions'

 apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
    applicationId "xxx.xxx.com"
    minSdkVersion 21
    targetSdkVersion 28
    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
}

kapt {
    generateStubs = true
  }
}

dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
   implementation 'com.android.support:appcompat-v7:28.0.0'
   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'

   kapt "com.android.databinding:compiler:$android_plugin_version"
}

Syncing has no problem but when running it, I received this error

Could not find com.android.databinding:compiler:3.4.0.
Searched in the following locations:

-

https://dl.google.com/dl/android/maven2/com/android/databinding/compiler/3.4.0/compiler-3.4.0.pom - https://dl.google.com/dl/android/maven2/com/android/databinding/compiler/3.4.0/compiler-3.4.0.jar - https://jcenter.bintray.com/com/android/databinding/compiler/3.4.0/compiler-3.4.0.pom - https://jcenter.bintray.com/com/android/databinding/compiler/3.4.0/compiler-3.4.0.jar - https://repo.maven.apache.org/maven2/com/android/databinding/compiler/3.4.0/compiler-3.4.0.pom - https://repo.maven.apache.org/maven2/com/android/databinding/compiler/3.4.0/compiler-3.4.0.jar

4

4 Answers

6
votes

You are using wrong version of the Databinding Compiler. For latest version, you can check sites like mvnrepository. For now latest version is 3.4.0. Here, you are passing wrong version:

 kapt "com.android.databinding:compiler:$android_plugin_version"

Instead, use this:

kapt "com.android.databinding:compiler:3.4.0"

UPDATE

In Android studio 3.3 and above you do not need to add annotation processor kapt "com.android.databinding:compiler:$android_plugin_version". Just set dataBinding.enabled = true in your module gradle file or like this:

android {
    ...
    dataBinding {
        enabled = true
    }
}
1
votes

I simply remove the kapt "com.android.databinding:compiler$android_plugin_version" and it works the ActivityMainBinding appear in my MainActivity

Gradle App

    apply plugin: 'com.android.application'

     apply plugin: 'kotlin-android'

     apply plugin: 'kotlin-android-extensions'

     apply plugin: 'kotlin-kapt'

     android {
        compileSdkVersion 28
        defaultConfig {
        applicationId "xxx.xx.com"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dataBinding {
        enabled = true
    }
}

kapt {
    correctErrorTypes = true
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    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'
}
0
votes

go to file>>setting>>Gradle>>android studio and check embedded maven

0
votes

update gradle plugin.

It worked for me