我正在尝试使用改装2,匕首2和MVP创建一个简单的应用程序,但我在依赖性方面遇到困难,实际上,这是我在尝试重建项目后得到的错误错误:任务执行失败’:app:compileDeBUGJavaWithJavac ”.
java.lang.StackOverflowError
以及我提供AppComponent的App类:无法解析符号’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,它具有对视图和交互器的引用:
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(); }}
和具有RetrofitService和JokePresenter引用的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 one rror(Throwable e) { presenter.onError(e.getMessage()); } @OverrIDe public voID onNext(RandomJokeResponse randomJokeResponse) { presenter.onNextRandomJoke(randomJokeResponse); } }); }
Gradle依赖项:
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'
有人能在这看到问题吗?
解决方法:
看看执行情况:
@Module(includes = InteractorModule.class)public class PresentationModule
和
@Module(includes = {NetworkModule.class, PresentationModule.class})public class InteractorModule
你有一个循环依赖.你需要重新考虑你的设计.我建议将Interactor与Presenter分离.
简单的解决方案:
更改getRandomJoke()实现以返回Observable并在Presenter中订阅它.并从Interactor中删除presenter引用.
交互器:
public class JokeInteractorImpl implements JokeInteractor { private RetrofitService retrofitService; public JokeInteractorImpl(RetrofitService service) { this.retrofitService = service; } @OverrIDe public Observable getRandomJoke() { return retrofitService.getRandomJoke() .subscribeOn(Schedulers.io()) .observeOn(AndroIDSchedulers.mainThread()); }}
主持人:
@OverrIDepublic voID getRandomJoke() { mJokeVIEw.showProgress(); jokeInteractor.getRandomJoke() .subscribe(new Observer<RandomJokeResponse>() { @OverrIDe public voID onCompleted() { onRandomJokeCompleted(); } @OverrIDe public voID one rror(Throwable e) { one rror(e.getMessage()); } @OverrIDe public voID onNext(RandomJokeResponse randomJokeResponse) { onNextRandomJoke(randomJokeResponse); } });}
总结 以上是内存溢出为你收集整理的android – Dagger 2无法解析符号’DaggerAppComponent’全部内容,希望文章能够帮你解决android – Dagger 2无法解析符号’DaggerAppComponent’所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)