Building an Android Instant App with Application Component from Dagger

后端 未结 2 793
臣服心动
臣服心动 2021-02-12 11:36

I\'m currently experimenting with InstantApps and would like to include dagger into my project.

I\'m facing an issue setting up an application AppComponent. My applicati

2条回答
  •  Happy的楠姐
    2021-02-12 12:10

    • Dagger2 is very much supported with Instant apps. You can create Component classes for each feature module and a corresponding Dagger provider class to expose the component class instance for each feature module.
    • Each module component class can declare inject methods for the classes contained only in that feature module.
    • In addition you can also have a Application component class in the base module for application wide injection.
    • The application component class can be instantiated in the Application class included in the base module and exposed to other feature modules via static method in the application class.

    Here is a sample code of Dagger2 injection with Instant apps to make things clearer. https://github.com/willowtreeapps/android-instant-apps-demo

提交回复
热议问题