Sirop4ik
Sirop4ik

Reputation: 5233

Cannot resolve symbol DaggerAppComponent

There is my GitHub project - https://github.com/alekseytimoshchenko/MVVM_FLOW that I haven't used a lot of time and today I decided to check it out as a result I faced some compile/Gradle/build issues, so I needed to update some dependency and other things. Eventually looks like everything is ok, however, I got a compile

error: cannot find symbol import com.example.krokosha.quizyourself.di.components.DaggerAppComponent;

This likely happens due to some specific dependencies or their version, I went through a few answers here on SO, but looks like everything is correct, but still, this class is not generated.

If it is suitable you are welcome to take a look at the project by the ref provided above, otherwise, I'll put some code here

There are my grale dependencies

...
    //Dependency Injection
    api "com.google.dagger:dagger:2.35.1"
    annotationProcessor "com.google.dagger:dagger-compiler:2.28.3"
    api "com.google.dagger:dagger-android:2.35.1"
    api "com.google.dagger:dagger-android-support:2.28.3" // if you use the support libraries
    annotationProcessor "com.google.dagger:dagger-android-processor:2.28.3"
...

and there is my class where I got an error:

package com.example.krokosha.quizyourself.di;

import android.content.Context;

import com.example.krokosha.quizyourself.di.components.AppComponent;
import com.example.krokosha.quizyourself.di.components.BaseComponent;
import com.example.krokosha.quizyourself.di.components.BaseComponentBuilder;
import com.example.krokosha.quizyourself.di.components.DaggerAppComponent;
import com.example.krokosha.quizyourself.di.moduls.AppModule;
import com.example.krokosha.quizyourself.di.moduls.BaseModule;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Provider;

public class ComponentsHolder
{
    private final Context context;
    
    @Inject
    Map<Class<?>, Provider<BaseComponentBuilder>> builders;
    
    private Map<Class<?>, BaseComponent> components;
    private AppComponent appComponent;
    
    public ComponentsHolder(Context context)
    {
        this.context = context;
    }
    
    public ComponentsHolder init()
    {
        appComponent = DaggerAppComponent.builder().appModule(new AppModule(context)).build();
        appComponent.injectComponentsHolder(this);
        components = new HashMap<>();
        return this;
    }
    
    public BaseComponent getBaseComponent(Class<?> cls)
    {
        return getBaseComponent(cls, null);
    }
    
    public BaseComponent getBaseComponent(Class<?> cls, BaseModule module)
    {
        BaseComponent component = components.get(cls);
        
        if (component == null)
        {
            BaseComponentBuilder builder = builders.get(cls).get();
            
            if (module != null)
            {
                builder.module(module);
            }
            
            component = builder.build();
            components.put(cls, component);
        }
        
        return component;
    }
    
    public void releaseBaseComponent(Class<?> cls)
    {
        components.put(cls, null);
    }
}

What is a possible problem here?

Upvotes: 2

Views: 2537

Answers (1)

Jeff Bowman
Jeff Bowman

Reputation: 95614

DaggerAppComponent is the file Dagger generates as an implementation of your AppComponent interface. If DaggerAppComponent is not being generated, it usually means that Dagger has emitted an error that you can read further up in your compiler log. If you see one of those errors, please edit it into your question.

Also, note that you're mismatching your Dagger versions: your libraries are 2.35.1 but your annotation processor is 2.28.3. In some cases this mismatch can cause a compilation failure, though it's more typical for it to cause the generated DaggerAppComponent file to fail to compile within the generated code. (The generated code calls the dagger libraries at runtime, so if the versions don't match the generated code might call into a class or method that doesn't exist.) Because DaggerAppComponent is missing entirely, it's less likely that the version skew is the root cause of your error here, but in any case you should always have all your Dagger versions consistent: api/implementation/annotationProcessor and between dagger and dagger.android.

Upvotes: 1

Related Questions