ただ、同じモジュールに、あなたがそのokhttpも提供し、レトロフィットを提供するために、注入を使用して、あなたのクラスに続いて換装によって
@Singleton
@Provides
OkHttpClient providesOkHttpClient(){
return new OkHttpClient.Builder()
.connectTimeout(RETROFIT_API_CONNECTION_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.readTimeout(RETROFIT_API_CONNECTION_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.writeTimeout(RETROFIT_API_CONNECTION_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.build();
}
@Singleton
@Provides
Retrofit providesRetrofit(OkHttpClient client){
return new Retrofit.Builder()
.baseUrl(baseUrl)
.client(client)
.build();
}
を使用している:
public class MyClass {
Retrofit mRetrofit;
@Inject
public MyClass(Retrofit retrofit){
mRetrofit = retrofit;
}
}
私は間違っていないよ場合は、あなたはなぜ@Injectを使うことができますかなぜAndroidInjectionを使う必要がありますか? – savepopulation
[this](https://stackoverflow.com/questions/45075204/how-do-i-use-androidinjection-class-in-custom-views-or-other-android-classes/45195327#45195327)をご覧ください。 )。 – azizbekian