简体   繁体   English

使用dagger2时未生成DataBindingComponent

[英]DataBindingComponent not being generated when using dagger2

When compiling my app, I get the following error on all of my generated WhateverFragmentOrActivityBinding classes: 在编译我的应用程序时,我在所有生成的WhateverFragmentOrActivityBinding类上收到以下错误:

error: cannot find symbol
  protected WhateverFragmentOrActivityBinding(DataBindingComponent _bindingComponent, View _root,
                                         ^
  symbol:   class DataBindingComponent
  location: class WhateverFragmentOrActivityBinding

The DataBindingComponent class does not seem to be generated. 似乎没有生成DataBindingComponent类。

Having a look at the documentation for DataBindingComponent we see: 看一下DataBindingComponent的文档,我们看到:

If using Dagger 2, the developer should extend this interface and annotate the extended interface as a Component. 如果使用Dagger 2,开发人员应扩展此接口并将扩展接口注释为Component。

I am indeed using Dagger 2, so I suspect that this might be relevant. 我确实使用Dagger 2,所以我怀疑这可能是相关的。 I've tried to do this myself, to no avail, and could not find it implemented on the internet. 我自己试图这样做,无济于事,无法在互联网上找到它。 This is what I've tried: 这就是我尝试过的:

@Component(dependencies = [AppComponent::class], modules = [(AppModule::class), (AndroidInjectionModule::class), (ActivityBuilderModule::class)])
interface BindingComponent : DataBindingComponent

However the DaggerBindingComponent class is never generated because of the cannot find symbol errors that I already had. 但是,从未生成DaggerBindingComponent类,因为找不到我已经拥有的符号错误。 This seems like a chicken and egg issue, so I don't feel confident that this is the solution to my issue. 这似乎是鸡和鸡蛋的问题,所以我不相信这是我的问题的解决方案。

The DataBindingComponent seems to be responsible for handling BindingAdapters. DataBindingComponent似乎负责处理BindingAdapters。 I have some custom binding adapters for binding an ImageView src property, but even commenting out these adapters does not help, so I'm not sure if they are related. 我有一些自定义绑定适配器用于绑定ImageView src属性,但即使注释掉这些适配器也无济于事,所以我不确定它们是否相关。

I tried removing Dagger from the app completely and the issue did not go away. 我尝试完全从应用程序中删除Dagger,问题没有消失。 Not sure what else to try 不知道还有什么可以尝试

u_u u_u

I was having this same issue a couple days ago, I was using product flavors and one of them (the one that I was currently working on) did not have access to a class needed, this caused ALL of binding classes to fail, I was getting multiple errors on every Activity or Fragment binding classes. 几天前我遇到了同样的问题,我正在使用产品风格,其中一个(我目前正在处理的那个)没有访问所需的类,这导致所有绑定类失败,我是在每个Activity或Fragment绑定类上获得多个错误。

I was also using Dagger2 and one of my modules did not have access to a class (CustomBroadcastReceiver) 我也使用Dagger2,我的一个模块没有访问类(CustomBroadcastReceiver)

@Module
abstract class BroadcasReceiverModule {

    @ContributesAndroidInjector
    internal abstract fun contributePhoneStateBroadcastReceiver(): CustomBroadcastReceiver
}

this error was never shown after the build process, BroadcastReceiverModule was part of my "main" resources but it was not required for the flavor I was working on where CustomBroadcastReceiver did not exist 在构建过程之后,这个错误从未显示过,BroadcastReceiverModule是我的“主要”资源的一部分,但我不知道CustomBroadcastReceiver不存在的那种风格。

even though it was not required it still generated a bunch of errors that disapeared after I removed BroadcastReceiverModule from "main" resources and placed it only on the flavors that it was actually required 即使它不是必需的,它仍然会产生一堆错误,这些错误在我从“主”资源中删除BroadcastReceiverModule之后就消失了,并且只将它放在实际需要它的味道上

I was having the same error messages. 我有相同的错误消息。

Then I found that Studio was showing errors when DataBinding is used/built, also build output was not showing more than 100 lines of errors by default so: 然后我发现Studio 使用/构建DataBinding时显示错误,默认情况下构建输出也没有显示超过100行错误,因此:

https://github.com/google/dagger/issues/306 https://github.com/google/dagger/issues/306

Added this to build.gradle: 将此添加到build.gradle:

gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xmaxerrs" << "500" // or whatever number you want
    }
}

Then I found the actual error: 然后我发现了实际的错误:

https://github.com/google/dagger/issues/1245 https://github.com/google/dagger/issues/1245

https://issuetracker.google.com/issues/115738511 https://issuetracker.google.com/issues/115738511

Solution for me was to downgrade Dagger 2.19 to Dagger 2.16. 我的解决方案是 Dagger 2.19 降级为Dagger 2.16。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM