2016-06-09 3 views
12

내가 개조 2를 사용하기 위해 노력하고있어 및 RxJava로 변환 할 수 없습니다RxJavaCallAdapterFactory는 개조와 RxJava를 사용하는 방법을 설명합니다 "CallAdapter 와 RxJava 통합"섹션에서이 <a href="https://inthecheesefactory.com/blog/retrofit-2.0/en" rel="noreferrer">https://inthecheesefactory.com/blog/retrofit-2.0/en</a></p> <p>의 가이드 다음 공장

Retrofit retrofit = new Retrofit.Builder() 
    .baseUrl("http://api.nuuneoi.com/base/") 
    .addConverterFactory(GsonConverterFactory.create()) 
    .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 
    .build(); 

Error:(63, 71) error: incompatible types: RxJavaCallAdapterFactory cannot be converted to Factory 

어떻게 : 컴파일하는 동안 그러나

다음과 같은 오류가 고쳐? 감사합니다.

+0

은 당신이 언급 한 종속 관계를 포함나요 성공적으로 포장하게? 컴파일 'com.squareup.retrofit : adapter-rxjava : 2.0.0-beta2' compile 'io.reactivex : rxandroid : 1.0.1' –

+0

예, 종속성을 포함시킵니다. com.squareup.retrofit : adapter-rxjava : 2.0.0-beta2 ' compile'io.reactivex : rxandroid : 1.0.1 ' –

+0

@LuisaRepele 이상하지만 필자는 필요한 모든 의존성을 포함 시켰으며 Android Studio에서도 여전히'RxJavaCallAdapterFactory'를 찾을 수 없습니다. 그런 다음'import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; '를 수동으로 추가하면 제대로 작동합니다. – tchelidze

답변

40

기본 Retrofit 종속성, Gson 변환기 종속성 및 RxJava 어댑터 종속성에 대해 동일한 groupId 및 version을 사용하고 있는지 확인하십시오. 내가 당신을 추측하고있어

은 다음과 같이 보일 :

compile 'com.squareup.retrofit2:retrofit:2.0.2' 
compile 'com.squareup.retrofit2:converter-gson:2.0.2' 
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2' 
:
compile 'com.squareup.retrofit2:retrofit:2.0.2' 
compile 'com.squareup.retrofit2:converter-gson:2.0.2' 
compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2' 

그들은 모두가 같은 같은 보일 것이다 (서로 다른 groupIds 및 버전 번호를 사용합니다)
+0

2.3.0을 사용하면서 버전 코드에 관심을 가져 주셔서 감사합니다.하지만 convert-gson이 2.1.0 인 것을 알게되었으므로 RxJavaCallAdapterFactory를 해결할 수없는 오류가 발생했습니다. 그러나 내가 gradle 파일에서 보면 모든 라이브러리 세트가있었습니다. –

2

현재 "com.squareup.retrofit : adapter-rxjava : 2.0.0"이 다음 오류를 제공합니다

01 2,

하지만, 대신 추가, " 'com.jakewharton.retrofit을 컴파일 : retrofit2-rxjava2 어댑터 : 1.0.0"

+1

이것은 2017 년 3 월 9 일까지는 여전히 사실입니다. 2.2.0, jakewharton의 rxjava2-adapter 1.0.0, rxandroid 2.0.1 및 rxjava 2.0.7을 사용하고 있습니다. – Chris

+2

사실, 'compile'com.squareup.retrofit2 : adapter-rxjava2 : 2.2.0''을 가져 와서'.addCallAdapterFactory (RxJava2CallAdapterFactory.create())'를 사용하십시오. – Rumid