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

查看:1541
本文介绍了找不到符号类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
  • 更多.

对于我而言,唯一对我有帮助的是打开控制台"构建",单击"切换视图"(位于控制台左侧和下方)锤子)并修复该屏幕上显示的错误.

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天全站免登陆