Android 在模块中声明子组件引发编译器错误
我用的是匕首2.24 我有一个子组件:Android 在模块中声明子组件引发编译器错误,android,dagger-2,Android,Dagger 2,我用的是匕首2.24 我有一个子组件: @Subcomponent(modules = MyModule.class) public interface MySubComponent { void inject(MyApplication app); } 由于我的子组件仅由特定模块的类使用,因此,我尝试通过以下方式在该模块类中声明我的子组件: //Compiler error: An annotation argument must be a compile-time constant
@Subcomponent(modules = MyModule.class)
public interface MySubComponent {
void inject(MyApplication app);
}
由于我的子组件仅由特定模块的类使用,因此,我尝试通过以下方式在该模块类中声明我的子组件:
//Compiler error: An annotation argument must be a compile-time constant
@Module(subcomponents = MySubComponent.class)
abstract class MyModule {
...
}
当我执行上述操作时,编译器会抱怨“注释参数必须是编译时常量”。为什么? 模块和子组件之间存在循环依赖关系 因为我的子组件仅由特定模块的类使用[…] 您必须从
MyModule
中删除subcomponents=MySubComponent.class
如果您只想为
MySubcomponent
定义一些依赖项,那么您的主模块(不是MyModule
)应该在其子组件中列出MySubcomponent
,并且,正如您所做的那样,您必须在子组件的模块中列出MyModule
。通过这种方式,MyModule
的依赖关系将仅提供给MySubcomponent
您的模块和子组件之间存在循环依赖关系
因为我的子组件仅由特定模块的类使用[…]
您必须从MyModule
中删除subcomponents=MySubComponent.class
如果您只想为
MySubcomponent
定义一些依赖项,那么您的主模块(不是MyModule
)应该在其子组件中列出MySubcomponent
,并且,正如您所做的那样,您必须在子组件的模块中列出MyModule
。这样,MyModule
的依赖关系将仅提供给MySubcomponent
您可以共享MyModule
的内容吗?顺便说一句,你写了两次MyModule
,但我猜它们在两个代码块中是不同的,对吗?它们指的是相同的MyModule
类。你能分享MyModule
的内容吗?顺便说一句,你写了两次MyModule
,但我猜它们在两个代码块中是不同的,对吧?它们指的是相同的MyModule
类。