我正在嘗試創建一個簡單的應用程序,其中包含retrofit 2,匕首2和MVP,但我與依賴關係糾纏在一起,實際上,這是我嘗試重建項目錯誤:執行任務':app:compileDebugJavaWithJavac'失敗。Dagger 2無法解析符號'DaggerAppComponent'
java.lang.StackOverflowError
以及在App類,我提供AppComponent:不能解析符號「DaggerAppComponent」
我會向你們展示我的項目是什麼樣子所以有人看到了問題,第一個是我的AppModule其中包括PresentationModule.class
@Module(includes = PresentationModule.class)
public class AppModule {
private App app;
public AppModule(App app) {
this.app = app;
}
@Provides
@Singleton
public App provideApp() {
return app;
}
}
提示部看起來是這樣的:
@Module(includes = InteractorModule.class)
public class PresentationModule {
@Provides
JokePresenter providePresenter(JokeInteractor jokeInteractor) {
return new JokePresenterImpl(jokeInteractor);
}
}
而且InteractorModule:
@Module(includes = {NetworkModule.class, PresentationModule.class})
public class InteractorModule {
@Provides
JokeInteractor provideJokeInteractor(RetrofitService service, JokePresenter presenter) {
return new JokeInteractorImpl(service, presenter);
}
}
這是具有基準以查看和交互件JokePresenter:具有RetrofitService和JokePresenter引用
public class JokePresenterImpl implements JokePresenter {
private JokeView mJokeView;
private List<String> mData = new ArrayList<>();
private String mJoke;
private JokeInteractor jokeInteractor;
public JokePresenterImpl(JokeInteractor jokeInteractor) {
this.jokeInteractor = jokeInteractor;
}
@Override
public void setView(JokeView view) {
this.mJokeView = view;
}
@Override
public void getRandomJoke() {
mJokeView.showProgress();
jokeInteractor.getRandomJoke();
}
}
而且JokeInteractor:
public class JokeInteractorImpl implements JokeInteractor {
private RetrofitService retrofitService;
private JokePresenter presenter;
public JokeInteractorImpl(RetrofitService service, JokePresenter presenter) {
this.retrofitService = service;
this.presenter = presenter;
}
@Override
public void getRandomJoke() {
retrofitService.getRandomJoke()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<RandomJokeResponse>() {
@Override
public void onCompleted() {
presenter.onRandomJokeCompleted();
}
@Override
public void onError(Throwable e) {
presenter.onError(e.getMessage());
}
@Override
public void onNext(RandomJokeResponse randomJokeResponse) {
presenter.onNextRandomJoke(randomJokeResponse);
}
});
}
搖籃依賴性:
apt 'com.google.dagger:dagger-compiler:2.7'
compile 'com.google.dagger:dagger:2.7'
provided 'javax.annotation:jsr250-api:1.0'
//retrofit
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
//rx java
compile 'io.reactivex:rxjava:1.1.6'
compile 'io.reactivex:rxandroid:1.2.1'
//dagger2
compile 'com.google.dagger:dagger:2.0'
provided 'org.glassfish:javax.annotation:10.0-b28'
有人可以在這裏看到問題嗎?
你創建處理噴射組件接口?如果沒有,請告訴我,我很樂意提供一個例子。 – jch000
你應該顯示你的gradle依賴關係 – EpicPandaForce
是的,我有一個組件接口,它具有AppModule,以及其中演示者被注入的方法void inject(App app); void inject(JokeActivity activity); void inject(JokeListActivity activity); void inject(JokeDialog對話框); – joe