在 Gradle 插件更新并迁移到 annotationProcessor 后,Android 数据绑定构建失败 [英] Android Databinding build fail after Gradle plugin update with migration to annotationProcessor
问题描述
- 为了在我的 Android Studio 版本中支持 Instant Run,我需要将我的 Gradle 插件从版本
2.2.3
升级到2.3.3
- 我知道我应该迁移到 annoationProcessor 并且我相信我已经正确地遵循了该指南
- 这样做后,Android DataBinding 代码生成失败
- To support Instant Run in my version of Android Studio, I needed to upgrade my Gradle plugin from version
2.2.3
to2.3.3
- I'm aware I'm supposed to migrate to annoationProcessor and I believe I've followed that guide correctly
- after doing so, the Android DataBinding code generation fails
之前链接的迁移指南指出,我只需要
The migration guide linked earlier states that all I need is to
- 确保您使用的是 Android Gradle 2.2 插件或更新版本
- 从您的构建脚本中删除 android-apt 插件
- 将所有 apt、androidTestApt 和 testApt 依赖项更改为新格式
这应该是成功构建项目所需的全部内容.但它没有构建.
This should be all that's needed to successfully build the project. Yet it doesn't build.
Gradle 构建在 12 秒 481 毫秒内完成了 101 个错误和 23 个警告
Gradle build finished with 101 error(s) and 23 warning(s) in 12s 481ms
所有错误都遵循相同的模式:
All of the errors follow the same pattern:
- C:\Users...\FooAdapter.java
- 错误:包
com.example.app.databinding
不存在 - 错误:找不到符号类
ItemFooBinding
可以在构建控制台中找到一条有趣的消息:
An interesting message can be found in the build console:
警告:以下选项未被任何处理器识别:'[android.databinding.minApi, android.databinding.enableDebugLogs, android.databinding.sdkDir, android.databinding.bindingBuildFolder, android.databinding.enableForTests, android.databinding.modulePackage, android.databinding.generationalFileOutDir, android.databinding.xmlOutDir, android.databinding.artifactType, android.databinding.printEncodedErrors, android.databinding.isTestVariant]'
Warning:The following options were not recognized by any processor: '[android.databinding.minApi, android.databinding.enableDebugLogs, android.databinding.sdkDir, android.databinding.bindingBuildFolder, android.databinding.enableForTests, android.databinding.modulePackage, android.databinding.generationalFileOutDir, android.databinding.xmlOutDir, android.databinding.artifactType, android.databinding.printEncodedErrors, android.databinding.isTestVariant]'
我想指出...
- 我认为我在某些 XML 文件中没有错误、绑定表达式或命名问题.当我使用旧的 gradle 插件版本(以及所有其他源文件是最新的)切换回 Git 分支时,相同的源集和 XML 构建
- 我确实增加了所讨论的输出构建错误的限制 此处,虽然这现在似乎并不相关,因为正如您所看到的,我目前只有"101 个错误.:)
- I presume I don't have an error in some XML file, binding expression or a naming issue. The same set of sources and XML build when I switch back to the Git branch with the old gradle plugin version (and all of the other source files up-to-date)
- I did increase the limit of output build errors as discussed here, although this doesn't seem to be relevant right now, since as you can see, I currently have "only" 101 errors. :)
以下差异显示了我如何修改我的 gradle 文件:
The following diffs show how I've modified my gradle files:
build.gradle
DiffChecker 链接app/build.gradle
DiffChecker 链接
此外,作为一个快速概览,这里列出了一些更有趣"的插件 &项目使用的库:
Also, as a quick overview, here is the list of some of the "more interesting" plugins & libraries used by the project:
- 科特林
- Android 数据绑定
- 领域
- 改造
- 匕首
- ButterKnife(我知道...)
- Multidex 支持库
有没有人知道可能是什么问题?任何帮助或想法将不胜感激!
Does anyone have a clue what could be the issue? Any help or idea will be greatly apprecitated!
推荐答案
看来这一切都归结为我使用 Kotlin 的项目.实际上我们是混合使用的:一些类使用普通的旧 Java,而另一些类是用 Kotlin 编写的.不完整的迁移.:)
It seems it all comes down to my project using Kotlin. Actually we have it mixed: some classes use plain old Java while others are written in Kotlin. An incomplete migration. :)
我认为如果没有 Kotlin,将
apt
替换为annotationProcessor
就足够了,我根本不会遇到这个问题.I assume that without Kotlin, replacing
apt
withannotationProcessor
would be enough and I wouldn't have ran into this issue at all.注解需要同时被
annotationProcessor
和kapt
处理,好像是Kotlin自带的注解处理器.Annotations need to be processed by both
annotationProcessor
andkapt
, which seems to be Kotlin's own annotation processor.对于每个使用注解的 Gradle 依赖项,您应该在应用级
build.gradle
中两者:For each Gradle dependency that uses annotations, you should have both of the following in your app-level
build.gradle
:annotationProcessor 'com.example.my.library:x.y.z
kapt 'com.example.my.library:x.y.z
这篇关于在 Gradle 插件更新并迁移到 annotationProcessor 后,Android 数据绑定构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 错误:包