-
Notifications
You must be signed in to change notification settings - Fork 9
multiple <android:name=""> for instant app #1
Comments
Yes, this is an issue with this project right now. I have been trying to solve this, here are my findings. Dagger 2 can work with multi-feature modules without any problem with this setup. The problem is having different application classes in each feature module causes a conflict in app and instantapp modules. Application classes work fine on their own (in instant-app mode there is only one application class per module/app). We can not choose some feature's application class for app module because we have to inject second feature's dependencies as well. Even if we set (or write a new) application class for the app module, we can not do this for instantapp module, because it does not contain any code. To sum up: So right now I'm not sure how to organize application classes for Instant Apps. Ps: I created a question on StackOverflow. |
Hi, thank you for your reply, I have a solution which uses your example of dagger2 for a feature module called app, this has the manifest file with "android:name=.MyApplication"
In activity I call DaggerProvider.getFeatureComponent(applicationContext).inject(this); I use kotlin in my project, if you would like me to make a pull request let me know. |
Thanks for your help, I really appreciate it! I started this project with Dagger.Android in mind, but apparently we cannot have seperate application classes for each feature modules (as ManmeetP states here). We can only have instant and installed Application classes. Having Dagger.Android in Activity classes instead of Application is pretty much straight Dagger. So I started trying to solve this issue by moving injection codes into Activity classes. I also removed the Dagger.Android and use just good-old Dagger. So I injected dependencies as you suggested. But I don't like the idea of keeping a static reference of Dagger components, therefore I didn't add DaggerProvider. I created a new feature called AutoComplete, it's empty now but I could inject the Presenter and ViewState in AutoCompleteActivity without any problem. If you like to see the diff, take a look at here. |
I agree having static reference is not ideal, i think putting it in base class was good idea. The tricky part with instant apps is you have to consider both situations i.e. Your repository was great help when learning about creating and configuring instant app. And with this update it will help others when they look for solution on how to setup instant app with multiple feature modules and Dagger2. Thanks |
Hi I have been looking at how you have structured you instant app for dagger2.
I have a question about using dagger2 for multiple features, in your example you have
a feature module called 'query'. In the manifest file for that feature you have the following:
android:name=".QueryApplication"
in tag.
What happens if you have another feature module, is it possible to add dagger2 to the new feature module?
When I try setting "android:name=.SecondFeatureModule" in the new feature module manifest file, I get a compilation error saying AndroidManifest.xml file cannot have duplicate attributes i.e 'android:name=' is being added twice
Do you have any suggestions for resolving this?
Or does your example only work if you have 1 feature module for instant app?
Would you need to setup dagger2 differently if you had multiple feature modules?
The text was updated successfully, but these errors were encountered: