找不到符号类 DaggerAppComponent 或找不到符号类 DaggerActivityComponent [英] cannot find symbol class DaggerAppComponent or cannot find symbol class DaggerActivityComponent

查看:85
本文介绍了找不到符号类 DaggerAppComponent 或找不到符号类 DaggerActivityComponent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的类上添加注入后我收到这个错误然后它给了我一个编译错误.如果我删除

I get this error after adding inject on my class then it gives me a compilation error. If I remove

@Inject static ApiService mApiService;

一切正常

我正在使用 2 个应用程序类,它们是扩展的 MultidexApplication 因为我合并了 2 个应用程序,第一个是使用 dagger2,第二个应用程序是黄油刀,两个目录结构都不同,两个应用程序相互依赖地工作正常,但合并后代码应用程序无法编译并给出 DaggerAppComponent 错误!

And I'm using 2 Application class those are extended MultidexApplication because I have merge 2 application first is using dagger2 and second application is butterknife and both directory structure are differnet and both application interdependently working fine but after merge the code application not compile and give DaggerAppComponent error!

请帮助我们解决我的疑问

Please help us to resolve my query

我遵循以下结构

@ActivityScope
@Component(dependencies = AppComponent.class)
public interface ActivityComponent extends AppComponent {
    void inject(SignInActivity activity);
}

<小时>

@Singleton
@Component(modules = {ApplicationModule.class, ApiModule.class})
public interface AppComponent {
    Context appContext();
    Config config();
    ApiService apiService();    
}

<小时>

@Module
public class ActivityModule {
    private final Activity mActivity;

    public ActivityModule(Activity activity){
        mActivity = activity;
    }

    @Provides
    public Context activityContext(){
        return mActivity;
    }
}

<小时>

@Module
public class ApiModule {
    @Provides
    @Singleton
    public ApiService apiService(){
        OkHttpClient client = new OkHttpClient().newBuilder()
                .connectTimeout(10, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)
                .writeTimeout(10, TimeUnit.SECONDS)
                .build();
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES,false);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
        return new Retrofit.Builder()
                .baseUrl(Config.API_URL)
                .addConverterFactory(JacksonConverterFactory.create(mapper))
                .client(client)
                .build()
                .create(ApiService.class);
    }
}

<小时>

@Module
public class ApplicationModule {
    private final App mApp;

    public ApplicationModule(App app) {
        mApp = app;
    }

    @Provides
    @Singleton
    public Context appContext() {
        return mApp;
    }

    @Provides
    @Singleton
    public Config config() {
        return new Config(mApp);
    }    
}

<小时>

@Scope
@Retention(RetentionPolicy.RUNTIME)
public @interface ActivityScope {
}

<小时>

public class App extends BrowserApp {
    private AppComponent mAppComponent;

    @Override
    public void onCreate() {
        super.onCreate();
        mAppComponent = DaggerAppComponent.builder().applicationModule(new ApplicationModule(this)).build();

    }

    public AppComponent getAppAppComponent() {
        return mAppComponent;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

推荐答案

就我而言,我尝试过:

  • 使缓存无效并清理项目
  • 改变匕首的版本
  • 在 gradle.properties 中添加 -Pandroid.incrementalJavaCompile = false
  • 更多.

在我的情况下,唯一对我有帮助的是打开控制台build",点击切换视图"(在控制台左侧和下方锤子)并修复出现在该屏幕上的错误.

The only thing that helped me in my case was to open the console "build", click on "Toggle View" (to the left of the console and below the hammer) and fix the errors that appear on that screen.

这篇关于找不到符号类 DaggerAppComponent 或找不到符号类 DaggerActivityComponent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆