Gradle插件更新并迁移到注释处理器后,Android数据绑定构建失败 [英] Android Databinding build fail after Gradle plugin update with migration to annotationProcessor

查看:262
本文介绍了Gradle插件更新并迁移到注释处理器后,Android数据绑定构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 要在我的Android Studio版本中支持即时运行,我需要将我的Gradle插件从版本2.2.3升级到2.3.3
  • 我知道我应该迁移到anationationProcessor ,然后我相信我正确地遵循了该指南
  • 这样做后, Android DataBinding代码生成失败
  • To support Instant Run in my version of Android Studio, I needed to upgrade my Gradle plugin from version 2.2.3 to 2.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依赖项更改为其新格式
  • Make sure you are on the Android Gradle 2.2 plugin or newer
  • Remove the android-apt plugin from your build scripts
  • Change all apt, androidTestApt and testApt dependencies to their new format

这应该是成功构建项目所需的全部.但是它没有建立.

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
  • C:\Users...\FooAdapter.java
    • error: package com.example.app.databinding does not exist
    • error: cannot find symbol class 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集.
  • 我确实增加了输出构建错误的限制,如所讨论的
  • 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:

  1. build.gradle DiffChecker链接
  2. app/build.gradle DiffChecker链接
  1. build.gradle DiffChecker link
  2. app/build.gradle DiffChecker link

此外,作为快速概述,下面列出了一些更有趣"的插件&项目使用的库:

Also, as a quick overview, here is the list of some of the "more interesting" plugins & libraries used by the project:

  • 科特琳
  • Android数据绑定
  • 领域
  • 改造
  • 匕首
  • 黄油刀(我知道...)
  • 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,用annotationProcessor替换apt就足够了,我根本不会遇到这个问题.

I assume that without Kotlin, replacing apt with annotationProcessor would be enough and I wouldn't have ran into this issue at all.

批注需要同时由annotationProcessorkapt 处理,这似乎是Kotlin自己的批注处理器.

Annotations need to be processed by both annotationProcessor and kapt, 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
  • annotationProcessor 'com.example.my.library:x.y.z
  • kapt 'com.example.my.library:x.y.z

这篇关于Gradle插件更新并迁移到注释处理器后,Android数据绑定构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆