Dagger2注入生成的类

时间:2018-04-24 08:52:36

标签: java android kotlin dagger-2

我创建了自己的注释处理器库,为用户生成一个类。但是在使用Dagger2提供这些类时我遇到了错误。

以下是错误消息:

error: cannot find symbol

private Provider<NonExistentClass> provideUserDataProvider;
                   ^
  symbol:   class NonExistentClass
  location: class DaggerAppComponent

有人能解释我如何使用Dagger2注入生成的类吗?

1 个答案:

答案 0 :(得分:1)

默认情况下,Kotlin注释处理器用NonExistentClass替换每个未知符号。

这可能并不适合所有用例。您可以通过将Kapt correctErrorTypes选项设置为true来禁用此行为。

请参阅:http://kotlinlang.org/docs/reference/kapt.html#non-existent-type-correction

它应该可以解决您的问题。