Android dagger 2.11 : MainModule must be set
See original GitHub issueI am working in the new Android dagger 2.11 implemtnation; I am getting this error in runtime :
MainModule must be set.
I have one Activity with it’s presenter injected in mainModule + multiple fragments( bottom view tabs)
I added ArticlesFragment as an example.
MainModule.java
@Module public abstract class MainModule {
@FragmentScoped
@ContributesAndroidInjector(modules = ArticlesFragment.class) abstract ArticlesFragment articlesFragment();
@Provides
@ActivityScoped static String provideTaskId(MainActivity activity) {
return activity.getIntent().getStringExtra(""); }
@ActivityScoped
@Provides
public PresenterFactory<MainContract.Presenter> providePresenterFactory() { return MainPresenter::new; }
ActivityBindingModule.java : addded to the appComponent
@ActivityScoped @ContributesAndroidInjector(modules = MainModule.class)
abstract MainActivity mainActivity();
Issue Analytics
- State:
- Created 6 years ago
- Comments:9
Top Results From Across the Web
Module must be set dagger 2 - java - Stack Overflow
Dagger will automatically create Module for dependency graph if that Module has default constructor. If you use custom constructor then you ...
Read more >Dagger-Hilt in Detail - Full Course - YouTube
In this video you will learn the essential things about Dagger -Hilt.00:00 - Introduction & Dependencies02:11 - Application class03:57 ...
Read more >Using Dagger in multi-module apps - Android Developers
The app module is a good place to declare your application component (for example, ApplicationComponent in the image below) that can provide ...
Read more >Dagger 2.11 with Android - Medium
Dagger2 is a fully static, compile-time dependency injection framework for both Java and Android. It is an adaptation of an earlier version ...
Read more >DaggerMock - Bountysource
Created 2 years ago in fabioCollini/DaggerMock with 0 comments. The Gradle dependencies for Java in the README.md over Repository https://jitpack.io/ are wrong ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@alouanemed it’ll work if you just make it static. having an instance method means you have to have an instance of the module. If the provider-method is static then dagger can use it without requiring an instance of the module. So just changing it to
@ActivityScoped @Provides public static PresenterFactory<MainContract.Presenter> providePresenterFactory() { return MainPresenter::new; }
should work fine
Good to see this issue is resolved. This made me realize that there were only 2 places (1, 2) where I demonstrated how to use
@Provides
instead of@Binds
in abstract module classes. Furthermore, I didn’t at all discuss this in my article, which I’ll now update with these discussions.Thanks for bringing this up @alouanemed. Good eyes there @liminal!
UPDATE:
Someone asked me the same question. I answered the same issue with more in-depth explanations here: link