question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@ContributesAndroidInjector: No injector factory bound for Class

See original GitHub issue

Dagger 2.11-rc2 Android Studio 2.4 preview7 classpath ‘com.android.tools.build:gradle:2.4.0-alpha7’ compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }

When using @ContributesAndroidInjector, I get a runtime exception:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thepacific.clean/com.thepacific.clean.MainActivity}: java.lang.IllegalArgumentException: No injector factory bound for Class<com.thepacific.clean.MainActivity>
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2758)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2817)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1549)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:156)
        at android.app.ActivityThread.main(ActivityThread.java:6440)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:746)
Caused by: java.lang.IllegalArgumentException: No injector factory bound for Class<com.thepacific.clean.MainActivity>
        at com.thepacific.dagger.DispatchingAndroidInjector.inject(DispatchingAndroidInjector.java:110)
        at com.thepacific.dagger.AndroidInjection.inject(AndroidInjection.java:64)
        at com.thepacific.mvp.DaggerRxActivity.onCreate(DaggerRxActivity.java:20)
        at com.thepacific.clean.MainActivity.onCreate(MainActivity.java:11)
        at android.app.Activity.performCreate(Activity.java:6773)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1195)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2711)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2817) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1549) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:156) 
        at android.app.ActivityThread.main(ActivityThread.java:6440) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:746) 
public class App extends DaggerApplication{
    @Override
    protected AndroidInjector<? extends DaggerApplication> applicationInjector() {
        return DaggerAppComponent.builder().create(this);
    }
}

@Module
public abstract class AppModule {
  @Binds
  public abstract Application app(App app);
}

@Component(modules = {AppModule.class, AppBinder.class, AndroidInjectionModule.class})
@Singleton
public interface AppComponent extends AndroidInjector<App> {
    @Component.Builder
    abstract class Builder extends AndroidInjector.Builder<App> {
    }
}

@Module
public abstract class AppBinder {
    @ContributesAndroidInjector
    public abstract MainActivity mainActivity();
}

public class MainActivity extends DaggerAppCompatActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:8

github_iconTop GitHub Comments

18reactions
nvinayshettycommented, Oct 29, 2018

could somebody explain to me what was wrong here, and how to fix this issue? I’m trying to use the dagger in a Gradle multi-module project and getting the same exception

1reaction
streetsofbostoncommented, Feb 25, 2019

I see. That makes sense. Thanks! However, it is not immediately clear that ContributesAndroidInjector uses a map which prevents Dagger from promising to generate compile-time errors if something is amiss in this case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IllegalArgumentException: No injector factory bound for Class ...
This annotation must be applied to an abstract method in a Module that returns a concrete Android framework type.” i.e. Activity / Fragment,...
Read more >
[Solved]-No injector factory bound for Class<>-kotlin
So basically the @ContributesAndroidInjector will generate that subcomponent thing you are doing manually. Since your case matches the Daggers documentation on ...
Read more >
Dagger tips: elegantly handle your Activities and Fragments ...
IllegalArgumentException: No injector factory bound for Class ... just create a simple module with @ContributesAndroidInjector annotation.
Read more >
Java – Dagger2: no injector factory bound for fragment – iTecNote
I'm trying to convert a project that I'm building to use the dagger-android API for the DI framework, but I'm running into a...
Read more >
java.lang.illegalargumentexception: no injector was found for ...
IllegalArgumentException: No injector factory bound for Class<com.package. ... ContributesAndroidInjector Generates an AndroidInjector for the return type ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found