AndroidX 迁移后找不到 DataBindingComponent 符号

6

在将整个项目迁移到AndroidX后,我无法再次编译它。

我遇到了100个以下错误:

e: M:\tmp\EverywhereLauncher\app\generated\data_binding_base_class_source_out\devWithoutTestWithAccessibilityDebug\dataBindingGenBaseClassesDevWithoutTestWithAccessibilityDebug\out\com\my\app\databinding\ActivityMainBinding.java:52: error: cannot find symbol
      @Nullable ViewGroup root, boolean attachToRoot, @Nullable DataBindingComponent component) {
                                                                ^
  symbol:   class DataBindingComponent
  location: class ActivityMainBinding

我不知道该从哪里继续。

我现在有两个问题。

  • 我只看到了100个错误
  • 所有错误都是相同的,可能隐藏了真正的错误

我尝试过:

  • I have following in my projects build.gradle to increase the number of printed errors to 10000:

    gradle.projectsEvaluated {
            tasks.withType(JavaCompile) {
                options.compilerArgs << "-Xmaxerrs" << "10000"
            }
        }
    

    This always worked but in this case it does not increase the errors that are printed

你有什么想法接下来能做什么?

附加信息

  • I use following

    android.enableJetifier=true
    android.useAndroidX=true
    
  • I use android studio 3.2, with kotlin 1.2.61 and 3.3.0-alpha01 gradle build tools

  • I use the 3.3.0-alpha01 gradle build tools because I also use evernote com.evernote:android-state which does not otherwise - problem is explained here: https://github.com/evernote/android-state/issues/56

2
可能相关:https://dev59.com/u1QK5IYBdhLWcg3wF8B6#52489036 - Martin Zeitler
非常感谢,这并没有解决我的问题,但我尝试了旧的数据绑定,这减少了错误,并且因此我能够找到真正的罪魁祸首。 - prom85
2个回答

5

解决方案 - 增加记录错误

过去,在项目的build.gradle文件中,以下内容已经足够:

gradle.projectsEvaluated {
    tasks.withType(JavaCompile.class) {
        options.compilerArgs << "-Xmaxerrs" << "10000"
    }
}

使用Kotlin,以下内容将会有所帮助:
afterEvaluate {
    if (project.plugins.hasPlugin("kotlin-kapt")) {
        kapt {
            javacOptions {
                option("-Xmaxerrs", 10000)
            }
        }
    }
}

真正的问题

在我的情况下,我将一个Java类转换为Kotlin,并添加了以下字段:

@Arg
Integer someValue;

转换器创建以下内容:
@Arg
internal var someValue: Int? = null

问题:
使用注释时,internal无法正常工作,因此失败了,但日志仅显示数据绑定错误...
示例项目build.gradle

https://gist.github.com/MFlisar/eca8ae6c2e6a619913ab05d503a4368f


如何精确地使用 afterEvaluate? - LunaVulpo
2
你需要将它放入你的项目 build.gradle 文件中,我在这里创建了一个基本示例 gist:https://gist.github.com/MFlisar/eca8ae6c2e6a619913ab05d503a4368f - prom85

1

我在更新到androidx后也遇到了这个bug,尝试了几篇stackoverflow文章中提到的所有方法,最终升级gradle插件3.3.0-beta03解决了问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接