I am breaking up my project into different Android Studio modules. At the base, I have a headless modules with core
business logic. Down the module dependency tree, I have an app
modules that encompasses the Android Application.
In the core logic, I am using dependency injection for things like logging/error handling. In my core
module, there is a good amount of code that leverages the interface I am trying to log to, so I am using an EntryPoint to provide the Logging class.
In the app
module, I have the “real” logging code that will handle sending info to the server. So I really want to “inject” THAT implementation when I build the entire project so that all the code gets the real one.
I have searched and read a number of articles on Dagger2, modules, binding, and componenents but I have not found a way to allow the the core module to compile my core
module (outside of using Optional) while using my real implementation in the application.
In a perfect world, I can see two solutions:
- Try to ignore the dependency injection in the
core
module knowing it will be provided in theapp
module. I saw a library prop in Dagger 1 that appeared to do this. - Provide a dummy implementation of the interface in the
core
module and then swap it out in theapp
module for the real implementation when I build the apk. I think this MIGHT be possible with subcomponents but haven’t had luck…
Any help would be really appreciated!