Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 views
in Technique[技术] by (71.8m points)

android - cannot find symbol class DaggerAppComponent or cannot find symbol class 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;

it's working fine

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

I'm follow the below structure


@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);
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In my case I tried:

  • invalidating the cache and cleaning the project
  • changing the version of dagger
  • adding -Pandroid.incrementalJavaCompile = false in gradle.properties
  • much more.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...