问题描述
我有这些警告,但我不明白它们的意思。有人可以指出我的意思吗?
I have these warnings and I don't understand what they mean. Can someone point me to something?
对于我注入的类(其中有一个 component.inject(this)
语句)
For classes I inject into (where there is a component.inject(this)
statement)
Note: Generating a MembersInjector for [class] Prefer to run the dagger processor over that class instead.
对于我要注入的对象(用 @Inject $ c注释的构造函数$ c>)
For object I am injecting (constuctor annotated with @Inject
)
Note: Generating a Provider for [class]. Prefer to run the dagger processor over that class instead.
推荐答案
运行Dagger的注释处理器时,它会生成两种类型的类:
When Dagger's annotation processor runs, it generates two types of classes:
-
@Component
接口的实现 -
Provider
和MembersInjector
实现
每个
@Inject
的- Implementations of
@Component
interfaces Provider
andMembersInjector
implementations for each@Inject
'd type.
在生成 @Component
接口实现时,它会根据模块的配置方式,连接每个 Provider
和 MembersInjector
实现。如果您的组件或其中的任何模块引用的 @Inject
类型的没有编译的Dagger处理器,它仍将生成 Provider
或 MembersInjector
,但每个组件一次,而不是 @Inject
类。
While it's generating the @Component
interface implementation, it connects each of the Provider
and MembersInjector
implementations according to how your modules were configured. If your component or any of the modules therein refer to an @Inject
'd type that was compiled without the Dagger processor it will still generate the Provider
or MembersInjector
, but once for each component rather than once for the @Inject
'd class.
这不是真正的问题(因此不是警告或错误),但这确实意味着可能会使Dagger处理器为单个应用程序多次生成相同的类。如果它真的失控,可能会减慢编译速度,并占用更多的字节码。
This isn't really a problem (hence not a warning or error), but it does mean that can potentially have the Dagger processor generate the same classes many times for a single application. It might slow down compilation if and take up a bit more bytecode if it really gets out of hand.
简单的解决方法是确保您正在运行编译 @Inject
类型的类型以及组件时使用的Dagger注释处理器。
The easy fix is just to make sure that you're running the Dagger annotation processor when you compile your @Inject
'd types as well as your components.
这篇关于为[Class]生成一个MembersInjector。最好在该类上运行匕首处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!