17

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!

Community
  • 1
  • 1
Javan
  • 183
  • 2
  • 10
  • I have a similar problem with android.databinding.PropertyChangeRegistry. It gives me an error in the import statement and I cannot compile the project. When I revert back to Build Tools 2.2.3, it works. I think there is something wrong with data binding on 2.3. – petrnohejl Mar 03 '17 at 19:45
  • Do you see any other error? – George Mount Mar 04 '17 at 03:44
  • Also, do you have anything else different in your configuration, such as apt? – George Mount Mar 05 '17 at 03:12
  • @GeorgeMount hi I'll paste more error log later, thank you for your reply, thanks – Javan Mar 05 '17 at 08:42
  • @George Mount , I have added some error log ; I guess there is something wrong with gradle or data binding , because in branch todo-databind of poject [googlesamples/android-architecture](https : //github#com/googlesamples/android-architecture ) which belong to google also build failed like below . – Javan Mar 05 '17 at 11:39

7 Answers7

14

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'
}
Josh Bowden
  • 5,735
  • 2
  • 25
  • 36
  • It worked for me when in addition to this change , I also downgraded gradle version to 2.3.0 dependencies { classpath 'com.android.tools.build:gradle:2.3.0' } – Tushar Sep 07 '17 at 09:14
  • @Tushar thanks, I've updated the answer to makes sure of that you're using the same gradle version – Josh Bowden Mar 16 '18 at 17:04
2

The problem comes in a warning that is difficult to see amongst all of the errors:

Warning:Using incompatible plugins for the annotation processing: android-apt. This may result in an unexpected behavior.

If you remove apt, data binding works.

George Mount
  • 20,708
  • 2
  • 73
  • 61
  • 1
    add `apt 'com.android.databinding:compiler:2.3.0'` to build.gradle. and now every thing is ok, instant run works. be the version of data binding compiler which cause the error ? – Javan Mar 06 '17 at 03:44
2

I have also faced the same issue. I was using ButterKnife and Dagger!!

Solved as follow

1) Remove from app level gradle file:

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

2) Remove from project level gradle file:

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

3) And simply change "apt to annotationProcessor" as following dependencies:

 apt 'com.jakewharton:butterknife-compiler:8.5.1',
 apt "com.google.dagger:dagger-compiler:2.5"

To:

annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1',
annotationProcessor "com.google.dagger:dagger-compiler:2.5"
raghu
  • 671
  • 5
  • 16
1

Data binding also broke for us following the update to Android Studio v2.3. The GoLang Bind plugin became unable to generate library .aar files

Our problem was resolved via a combination of GoMobile version "+eb90329 Mar 7 2017" update and GoBind plugin revert to version "0.2.6" (although the current version is "0.2.8")

Update GoMobile:

  $ go get -u -x golang.org/x/mobile/cmd/gomobile
  $ gomobile init -x

Revert GoBind plugin in build.gradle:

  plugins {
    id "org.golang.mobile.bind" version "0.2.6"
  }

This solution is working on systems with go version 1.7.1 and 1.8 as well as Android Studio versions 2.1.2, 2.2.3, and 2.3.

David Manpearl
  • 12,362
  • 8
  • 55
  • 72
0

Two things Revert back your gradel-wrapper.properties distributionUrl to "https://services.gradle.org/distributions/gradle-2.14.1-all.zip" Change the gradle version classpath to previous version "'com.android.tools.build:gradle:2.2.3'"

P.S. Instant run will stop working on ADT with older gradle version.

  • Hi @Sa-Zad Prasla, Revert back my gradle version is work, but not the best solution, Thank you for you reply. – Javan Mar 04 '17 at 13:34
0

I too recently downloaded the latest version of android studio 2.3.3, because I was getting the same error in version 2.2.3 i.e Error:Failed to resolve: com.android.databinding:compiler:2.2.3 ,even in the latest version, I was getting the same error,I checked the project structure, In the File>Project Structure>Project , the Android Plugin version was still 2.2.3, I changed it to 2.3.3 and the build is successful and everything is working smoothly.

-2

I solved this problem by changing my version of gradle to:

classpath 'com.android.tools.build:gradle:3.0.1'

Since I am using Android Studio 3.0.1

Sam
  • 86,580
  • 20
  • 181
  • 179