升级 Android Studio 2.3 后数据绑定不起作用
DataBinding 在我的项目中运行良好,但今天升级 Android Studio 2.3 后.运行'app'失败,因为以下错误:
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
我只是升级了 android studio 并没有改变任何东西.所有插件都是最新的!现在我的问题是,为什么会出现此错误,我该如何解决?欢迎任何帮助!
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.
编辑 1
喜欢 android 项目 googlesamples/android-architecture
Like android project googlesamples/android-architecture
-
git checkout todo-databinding
- 然后运行
./gradlew assembleDebug
编译,编译失败,错误如下:
-
git checkout todo-databinding
- and then run
./gradlew assembleDebug
to build, build failed because of following error:
EDIT2 我已经按照升级到 Gradle 2.3 后数据绑定中断.
EDIT2 I have fixed this problem by following Data Binding broke after upgrade to Gradle 2.3.
在build.gradle(app)
中添加
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,谢谢!
@petrnohejl @George Mount @Sa-Zad Prasla, Thanks!
android-apt
因此使用 apt
自 Android Studio 2.2 起已被弃用.
按照 android-apt 迁移指南,将以下内容添加到您的 build.gradle
:
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'
}
如果您使用的是 Kolin,请改用:
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'
}