DataBinding not working after Upgrade Android Studio 2.3

Javan picture Javan · Mar 3, 2017 · Viewed 8.3k times · Source

DataBinding worked very well in my project, But after upgrade Android Studio 2.3 today . Run 'app' failed because following error :

Error:(15, 40) Error: package com.javan.myrecorder.databinding not exist.
import com.javan.myrecorder.databinding.FragmentEventsBinding;
:app:compileMockDebugJavaWithJavac FAILED

I just upgrade android studio and didn't change anything. all plugin is latest! Now my question is, why occurs this error and how could I solve it? any help is welcome!

English is not my mother tongue; please excuse any errors on my part.


EDIT1

Like android project googlesamples/android-architecture

  • git checkout todo-databinding
  • and then run ./gradlew assembleDebug to build, build failed because of following error:

complete log of build


EDIT2 I have fixed this problem by following Data Binding broke after upgrade to Gradle 2.3.

in build.gradle(app) add

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

..balabala

dependencies {
    apt 'com.android.databinding:compiler:2.3.0'
}

some file in my project:

gradle-wrapper.properties

#Mon Mar 06 10:59:04 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

@petrnohejl @George Mount @Sa-Zad Prasla, Thanks!

Answer

Josh Bowden picture Josh Bowden · Mar 17, 2017

android-apt and hence using apt has been deprecated since Android Studio 2.2.
Following the android-apt migration guide, instead add the following to your build.gradle:

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.0' // use same gradle version!
    annotationProcessor 'com.android.databinding:compiler:2.3.0'
}

If you are using Kolin, instead use:

apply plugin: 'kotlin-kapt'

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.0' // use same gradle version!
    kapt 'com.android.databinding:compiler:2.3.0'
}