Dagger cannot create object graph although it can produce dot file

前端 未结 4 2160
盖世英雄少女心
盖世英雄少女心 2021-02-06 12:50

I\'m struggling with the setup of Dagger (1.0.1), in a existing application. It was configured to use ProGuard but I disabled it for this test with -dontobfuscate.<

4条回答
  •  庸人自扰
    2021-02-06 13:21

    Dagger doesn't require @Inject to be on a class to be passed into graph.inject(myActivity) because some activities may not have any injections to make. However, these seem like upstream dependencies, which means that they need to be provided to ComponentInfo, and therefore need to be provisioned by Dagger. It cannot do this if it cannot create these classes, and it can't do so if these are not annotated, unless it provides them via a @Provides method.

    So, you either need to create an @Module-annotated class which returns these types from @Provides-annotated methods, or you need to add @Inject to their constructor.

    -keep class * extends dagger.internal.Binding
    

    That said, in this case, are you using proguard in "release" mode? And not proguarding in debug mode? If so, I suspect Proguard to be stripping away annotations. You'll need to do some variant of:

    -keep class javax.inject.** { *; }
    

    ... to ensure that Proguard doesn't remove the annotations.

提交回复
热议问题