dagger 2 not generating component class

dagger not generating component kotlin
dagger generated class
dagger 2 constructor injection
dagger inject in application class
daggerappcomponent not found
android kotlin dagger 2
dependency injection in android with dagger 2 free download
dagger best practices

I tried to use dagger 2 for the first time in one of my apps. Im getting error at dagger component class as the class did not get generated. please help me to get it work.

Link to my app https://github.com/kantigaricharan/Zolo

This the Error

    02:45:55.663 [ERROR] [system.err] /Users/vamsikrishna/Downloads/Zolo/app/src/main/java/com/example/saicharan/zolo/dagger/component/AppComponent.java:17: error: com.example.saicharan.zolo.dashboard.DashboardInteractorImpl cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method.
02:45:55.663 [ERROR] [system.err]     void inject(MyApp myApp);
02:45:55.663 [ERROR] [system.err]          ^
02:45:55.663 [ERROR] [system.err]       com.example.saicharan.zolo.dashboard.DashboardInteractorImpl is injected at
02:45:55.663 [ERROR] [system.err]           com.example.saicharan.zolo.MyApp.dashboardInteractor
02:45:55.664 [ERROR] [system.err]       com.example.saicharan.zolo.MyApp is injected at
02:45:55.664 [ERROR] [system.err]           com.example.saicharan.zolo.dagger.component.AppComponent.inject(myApp)
02:45:55.722 [ERROR] [system.err] 1 error

This is my Component class in dagger

   @Singleton @Component(modules = AppModule.class)
public interface AppComponent {
    void inject(MyApp myApp);
    void inject(DashboardInteractorImpl dashboardInteractorImpl);
}

This is module

    @Module
public class AppModule {
    private final MyApp myApp;
    public AppModule(MyApp myApp){this.myApp=myApp;}

    @Provides @Singleton
    Context providesApplicationContext(){
        return myApp;
    }
    @Provides @Singleton
    SessionManagement getSession(Context context){
        return  new SessionManagement(myApp);
    }
    @Provides @Singleton
    DatabaseHelper getDhelper(Context context){
        return new DatabaseHelper(myApp);
    }
}

Application class

    public class MyApp extends Application {

    protected AppComponent appComponent;
    private static MyApp instance;
    @Inject
    DashboardInteractorImpl dashboardInteractor;

    public static MyApp getInstance() {
        return instance;
    }

    public static Context getContext(){
       // return (MyApp) context.getApplicationContext();
          return instance.getApplicationContext();
    }

    @Override
    public void onCreate() {
        instance = this;
        super.onCreate();
        appComponent = DaggerAppComponent
                .builder()
                .appModule(new AppModule(this))
                .build();
        appComponent.inject(this);
    }
    public AppComponent getAppComponent(){
        return appComponent;
    }
}

DasboardInteractorImpl

   public class DashboardInteractorImpl implements DashboardInteractor {

    private final DatabaseHelper dHelper;
    private final SessionManagement sManager;
    DashboardPresenterImpl mDashboardPresenter;

    public DashboardInteractorImpl(DashboardPresenterImpl mDashboardPresenter){
        this.mDashboardPresenter=mDashboardPresenter;

        dHelper = new DatabaseHelper(MyApp.getContext());
        sManager= new SessionManagement(MyApp.getContext());
    }
     //SOME LOGIC HERE..
}

Can i know what went wrong with my app?


When you want Dagger 2 to provide a class for you, make sure you annotate the constructor with an @Inject annotation:

@Inject
public DashboardInteractorImpl(DashboardPresenterImpl mDashboardPresenter){
    this.mDashboardPresenter=mDashboardPresenter;

    dHelper = new DatabaseHelper(MyApp.getContext());
    sManager= new SessionManagement(MyApp.getContext());
}

Also, get rid of the line for injecting in your app:

@Singleton @Component(modules = AppModule.class)
public interface AppComponent {
   void inject(MyApp myApp);

   //delete the line below:
   //void inject(DashboardInteractorImpl dashboardInteractorImpl);
}

You will also need to make sure that Dagger 2 can provide DashboardPresenterImpl either by annotating the constructor for the presenter with @Inject or by writing a @Provides method inside a module.

Dagger 2 not generating component in Android test project after , Dagger 2 not generating component in Android test project after upgrading package com.example.kotlindaggerunittest class TestApplication  Dagger 2 does not generate the component class (Android, Kotlin)


Try using following modification

// Component
@Singleton @Component(modules = AppModule.class)
public interface AppComponent {
    void inject(MyApp myApp);

    DashboardInteractorImpl getDashboardInteractorImpl();
}

// Module
@Module 
public class AppModule { 
    private final MyApp myApp;
    public AppModule(MyApp myApp){this.myApp=myApp;}

    @Provides @Singleton 
    Context providesApplicationContext(){
        return myApp;
    } 
    @Provides @Singleton 
    SessionManagement getSession(Context context){
        return  new SessionManagement(context);
    } 
    @Provides @Singleton 
    DatabaseHelper getDhelper(Context context){
        return new DatabaseHelper(context);
    } 
}

// Application
public class MyApp extends Application {

    protected AppComponent appComponent;
    private static MyApp instance;
    @Inject 
    DashboardInteractorImpl dashboardInteractor;

    public static MyApp getInstance() { 
        return instance;
    } 

    public static Context getContext(){
       // return (MyApp) context.getApplicationContext(); 
          return instance.getApplicationContext();
    } 

    @Override 
    public void onCreate() { 
        instance = this;
        super.onCreate(); 
        appComponent = DaggerAppComponent
                .builder() 
                .appModule(new AppModule(this))
                .build(); 
        appComponent.inject(this);
    } 
    public AppComponent getAppComponent(){ 
        return appComponent;
    } 
} 

// DashboardInteractorImpl
public class DashboardInteractorImpl implements DashboardInteractor {

    private final DatabaseHelper dHelper;
    private final SessionManagement sManager;
    private DashboardPresenterImpl mDashboardPresenter;

    @Inject 
    public DashboardInteractorImpl(DatabaseHelper databaseHelper,
                SessionManagement sessionManagement
                DashboardPresenterImpl dashboardPresenter){

        dHelper = databaseHelper;
        sManager = sessionManagement;
        mDashboardPresenter = dashboardPresenter;
    }
     //SOME LOGIC HERE..
}

// DashboardPresenterImpl
public class DashboardPresenterImpl implements DashboardPresenter {

    @Inject     
    public DashboardPresenterImpl(ABC abc){
        //make sure ABC is provided by the module or inject on constructed
    }
}

Dagger 2 component not generated – Icetutor, What can be the cause for not generating Dagger Component . class ? EDIT: This is my ModuleClass, adnotated with @Module: @Provides @  Dagger2 is not generating any component classes in android studio i know its a known problem while i have gone through almost all ways to implement in my android studio and have tried on various tutorials but every time i got struck here, it fails to build the daggercomponent class . I have also tried to rebuild ,clean gradles and invalidate caches but it does not help .


You can inject DashboardInteractorImpl with two ways.

Either you have to Declare DashboardInteractorImpl Dependency in App module.

Or

You can write @Inject constructor. I did not see any code that full fill this Dependency. so you can do two thing you can Provide this DashboardPresenterImpl, DashboardInteractorImpl in module or Create @Inject constructor for each of this class DashboardPresenterImpl, DashboardInteractorImpl.

Dagger 2 Generated Code. - MindOrks, But the purpose of this article is not to show you how to use Dagger 2 on your and their respective components( ApplicationComponent , ActivityComponent ). First, we are going discuss each generated class separately to  I have done build / rebuild / clean / restart project. I have a Component class where I inject objects and a ModuleClass where I provide objects to inject. What can be the cause for not generating Dagger Component . class ? EDIT: This is my ModuleClass, adnotated with @Module:


If you use or write code in Kotlin add this line code inside build.gradle

apply plugin: 'kotlin-kapt'

Component, Annotates an interface or abstract class for which a fully-formed, has no component dependencies and only no-arg modules, the generated component will also have a methods are available through component dependencies. Since: 2.0  Notice how we passed our module class as an argument to the @Component annotation. If we didn't do that, Dagger wouldn't know how to build the car's dependencies. Also, since our module provides a singleton object, we must give the same scope to our component because Dagger doesn't allow for unscoped components to refer to scoped bindings. 4.3.


Using Dagger 2 for dependency injection in Android, Dagger 2 uses this interface to generate the accessor class the dependency for dependent components // (not needed for  But the purpose of this article is not to show you how to use Dagger 2 on your project(if you are looking for one, here is a good example) but to take a deep dive into Dagger’s generated code


Dagger not generating Component classes for androidTest, I create simple application for Android with Dagger 2. It has one shared object and one module. The module is: #Module public class MyModule { #Provides #  Dagger does not seem to generate the Dagger class for the TestComponent defined in ActivityLauncher. I found the same issue in my own code and I'd like to know if there is anything else I'm supposed to do.


erikjhordan-rey/Dagger2-MVP-Sample, component = DaggerAppComponent.builder().appModule(new The class DaggerAppComponent is a generated class on compile time. Try invalidate i will already used this gradle but DaggerAppComponent not support. I have done build / rebuild / clean / restart project. I have a Component class where I inject objects and a ModuleClass where I provide objects to inject. What can be the cause for not generating Dagger Component . class ? EDIT: This is my ModuleClass, adnotated with @Module: