gpt4 book ai didi

android - 使用 dagger2 时未生成 DataBindingComponent

转载 作者:IT老高 更新时间:2023-10-28 13:38:58 26 4
gpt4 key购买 nike

编译我的应用程序时,我在所有生成的 WhatFragmentOrActivityBinding 类上都收到以下错误:

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

DataBindingComponent 类似乎没有生成。

查看 DataBindingComponent 的文档,我们看到:

If using Dagger 2, the developer should extend this interface and annotate the extended interface as a Component.

我确实在使用 Dagger 2,所以我怀疑这可能是相关的。我自己尝试过这样做,但无济于事,并且无法在互联网上找到它。这是我尝试过的:

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

但是,由于我已经遇到了找不到符号错误,因此永远不会生成 DaggerBindingComponent 类。这似乎是一个先有鸡还是先有蛋的问题,所以我不确定这是否能解决我的问题。

DataBindingComponent 似乎负责处理 BindingAdapter。我有一些用于绑定(bind) ImageView src 属性的自定义绑定(bind)适配器,但即使注释掉这些适配器也无济于事,所以我不确定它们是否相关。

我尝试从应用程序中完全删除 Dagger,但问题并没有消失。不知道还能尝试什么

u_u

最佳答案

几天前我遇到了同样的问题,我正在使用产品 flavor ,其中一个(我目前正在研究的那个)无法访问所需的类,这导致所有绑定(bind)类都失败,我在每个 Activity 或 Fragment 绑定(bind)类上都遇到了多个错误。

我也在使用 Dagger2,但我的一个模块无法访问类 (CustomBroadcastReceiver)

@Module
abstract class BroadcasReceiverModule {

@ContributesAndroidInjector
internal abstract fun contributePhoneStateBroadcastReceiver(): CustomBroadcastReceiver
}

在构建过程之后从未显示此错误,BroadcastReceiverModule 是我的“主要”资源的一部分,但它不是我正在处理的 CustomBroadcastReceiver 不存在的 flavor 所必需的

即使它不是必需的,它仍然会产生一堆错误,在我从“主要”资源中删除 BroadcastReceiverModule 并将其仅放置在实际需要的风格上后消失了

关于android - 使用 dagger2 时未生成 DataBindingComponent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50527819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com