android - Dagger2 Error :component depends on scoped component in a non-hierarchical scope ordering -
can me resolve issue, i'm trying add dagger2 application getting scope issue.
error:(14, 1) error: com.bmx.presentation.authentication.login.logincomponent depends on scoped components in non-hierarchical scope ordering: @com.bmx.di.scope.activityscope com.bmx.data.remote.authenticationrepositorycomponent @com.bmx.di.scope.activityscope com.bmx.presentation.authentication.login.logincomponent @module public class appmodule { private application mapplication; public appmodule(application mapplication) { this.mapplication = mapplication; } @provides @singleton application provideapplication() { return mapplication; } @provides @singleton public resources provideresources(context context) { return context.getresources(); } } --------------------------------- @module public class netmodule { string mbaseurl; public netmodule(string mbaseurl) { this.mbaseurl = mbaseurl; } @provides @singleton cache providehttpcache(application application) { int cachesize = 10 * 1024 * 1024; cache cache = new cache(application.getcachedir(), cachesize); return cache; } @provides @singleton gson providegson() { gsonbuilder gsonbuilder = new gsonbuilder(); gsonbuilder.setfieldnamingpolicy(fieldnamingpolicy.lower_case_with_underscores); return gsonbuilder.create(); } @provides @singleton okhttpclient provideokhttpclient(cache cache) { okhttpclient.builder client = new okhttpclient.builder(); client.cache(cache); return client.build(); } @provides @singleton retrofit provideretrofit(gson gson, okhttpclient okhttpclient) { return new retrofit.builder() .addconverterfactory(gsonconverterfactory.create(gson)) .baseurl(mbaseurl) .client(okhttpclient) .build(); } @provides @singleton public bmxrestservice providebmxrestservice(retrofit retrofit) { return retrofit.create(bmxrestservice.class); } } --------------------------------------------- @singleton @component(modules = {netmodule.class,appmodule.class}) public interface apicomponent { bmxrestservice getbmxrestservice(); application getapplication(); } ----------------------------------------------------- public interface authenticationrepository { observable<list<userprofile>> dologin(string username, string password); observable<list<userprofile>> dosignup(string firstname, string lastname,string email,string password); } -------------------------------------------------------------- public class authenticationrepositoryimpl implements authenticationrepository { private bmxrestservice bmxrestservice; @inject public authenticationrepositoryimpl(@nonnull final bmxrestservice bmxrestservice) { this.bmxrestservice = bmxrestservice; } //implementation } ------------------------------------------- @activityscope @module public class authenticationrepositorymodule { @provides @activityscope public authenticationrepository provideauthenticationrepository(bmxrestservice bmxrestservice) { return new authenticationrepositoryimpl(bmxrestservice); } } ----------------------------- @activityscope @component(modules = {authenticationrepositorymodule.class},dependencies = apicomponent.class) public interface authenticationrepositorycomponent { authenticationrepository getauthenticationrepository(); } ----------------------------------- @module public class loginpresentermodule { private final logincontract.view mview; public loginpresentermodule(logincontract.view mview) { this.mview = mview; } @provides @activityscope logincontract.view providelogincontractview(){ return this.mview; } } ---------------------------------------------- @activityscope @component(dependencies = authenticationrepositorycomponent.class, modules = loginpresentermodule.class) public interface logincomponent { void inject(loginactivity activity); } ---------------------------------------- public class loginpresenter extends basepresenter<logincontract.view> implements logincontract.presenter{ private scheduler mainscheduler, ioscheduler; private authenticationrepository mauthenticationrepository; @inject public loginpresenter(@nonnull final authenticationrepository authenticationrepository,@nonnull final logincontract.view loginview) { super(loginview); this.mview =loginview; this.mauthenticationrepository =authenticationrepository; this.mainscheduler = androidschedulers.mainthread(); this.ioscheduler = schedulers.io(); } //implementation } ---------------------- public class loginactivity extends appcompatactivity implements logincontract.view { private static final string tag = "loginactivity"; @inject loginpresenter mloginpresenter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_login); } } ----------------------- public class bmxapp extends application { private apicomponent apicomponent; @override public void oncreate() { super.oncreate(); initializenetcomponent(); } private void initializenetcomponent() { apicomponent = daggerapicomponent.builder().netmodule(new netmodule(buildconfig.baseurl)).appmodule(new appmodule(this)).build(); } public apicomponent getapicomponent() { return apicomponent; } } --------------- @documented @scope @retention(retentionpolicy.runtime) public @interface activityscope { }
Comments
Post a Comment