我有一个类和接口。我正在尝试将接口对象注入到我的类构造函数中。 类和接口在Kotlin中,而Dagger模块在Java中。
接口
interface PurchaseProductRest {
@POST
fun postPurchase(@Url url: String, @HeaderMap authHeaders: Map<String, String>, @Body request: InAppPurchase): Call<String>
}
班
class PurchaseProductCall @Inject constructor(val purchaseProductRest: PurchaseProductRest) {
private var authHeaders: HashMap<String, String>
private val TAG = "PurchaseProductCall"
init {
authHeaders = HashMap()
}
fun ping() {
Log.e(TAG, "succesful")
}
fun call(url: String, apiKey: String, authToken: String, inAppPurchase: InAppPurchase,
apiResponse: Action1<String>) {
authHeaders.clear()
authHeaders["Authorization"] = authToken
authHeaders["x-api-key"] = apiKey
Log.d(TAG, "URL: $url")
purchaseProductRest.postPurchase(url, authHeaders, inAppPurchase).enqueue(object : Callback<String> {
override fun onFailure(call: Call<String>, t: Throwable) {
//Log.e(TAG, "onFailure: " + t.getMessage());
Observable.just(null as String)
.onErrorResumeNext { throwable: Throwable? -> Observable.empty() }
.subscribe(apiResponse)
}
override fun onResponse(call: Call<String>, response: Response<String>) {
Observable.just<String>(response.body())
.onErrorResumeNext { throwable: Throwable? -> Observable.empty() }
.subscribe(apiResponse)
}
})
}
}
这是我的模块中的
@Module
public class AppCMSUIModule {
@Provides
@Singleton
public Gson providesGson() {
return new GsonBuilder().registerTypeAdapterFactory(new Stag.Factory())
.create();
// return new Gson();
}
@Provides
@Singleton
public OkHttpClient providesOkHttpClient() {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.level(HttpLoggingInterceptor.Level.BODY);
return new OkHttpClient.Builder()
.connectTimeout(defaultConnectionTimeout, TimeUnit.MILLISECONDS)
.writeTimeout(defaultWriteConnectionTimeout, TimeUnit.MILLISECONDS)
.readTimeout(defaultReadConnectionTimeout, TimeUnit.MILLISECONDS)
.addInterceptor(logging)
.cache(cache)
.build();
}
@Provides
@Singleton
public Retrofit providesRetrofit(OkHttpClient client, Gson gson) {
return new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(gson))
.baseUrl(baseUrl)
.client(client)
.build();
}
@Provides
@Singleton
public PurchaseProductRest providesPurchaseProductRest(Retrofit retrofit) {
return retrofit.create(PurchaseProductRest.class);
}
@Provides
@Singleton
public PurchaseProductCall providesPurchaseProductCall(PurchaseProductRest purchaseProductRest) {
return new PurchaseProductCall(purchaseProductRest);
}
}
另一个模块
@Module(includes = {AppCMSUIModule.class})
public class AppCMSPresenterModule {
@Provides
@Singleton
public AppCMSPresenter providesAppCMSPresenter(Gson gson,PurchaseProductCall purchaseProductCall){
return new AppCMSPresenter(gson,purchaseProductCall);
}
}
构建应用程序时出现错误
[ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
有人可以指导我这里有什么问题吗?