简体   繁体   English

动态包含 dagger2 模块

[英]Dynamically include dagger2 modules

I have dagger component MainComponent , which is dependent on another module: LocalModule or PrdModule .我有匕首组件MainComponent ,它依赖于另一个模块: LocalModulePrdModule I would like to dynamically include one of the modules based on some flag.我想动态包含基于某个标志的模块之一。 Quick example:快速示例:

In code it looks like this:在代码中它看起来像这样:

@Component(modules = [LocalModule::class])
interface MainComponent

However, if I'm building my app for customer, then I must change it manually to:但是,如果我正在为客户构建我的应用程序,那么我必须手动将其更改为:

@Component(modules = [PrdModule::class])
interface MainComponent

What I would like to have is something like this:我想要的是这样的:

@Component(modules = [if(someFlag) {LocalModule::class} else {PrdModule::class}])
interface MainComponent

It'd be nice if I could set this flag in gradle's build options.如果我可以在 gradle 的构建选项中设置这个标志,那就太好了。

Thanks jsamol, different source sets solved my problem.谢谢jsamol,不同的源集解决了我的问题。 It was exactly what I was looking for!这正是我要找的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM