简体   繁体   中英

Dynamically include dagger2 modules

I have dagger component MainComponent , which is dependent on another module: LocalModule or PrdModule . 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.

Thanks jsamol, different source sets solved my problem. It was exactly what I was looking for!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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