Closed jdsjlzx closed 8 years ago
Actually RxJava 2 is only in preview releases. The final release is about a month away. You can use https://github.com/JakeWharton/retrofit2-rxjava2-adapter though.
I have a problem:
java.lang.IllegalArgumentException: Unable to create call adapter for org.reactivestreams.Publisher
Thank you!
build.gradle dependencies as following: compile 'com.squareup.okhttp3:okhttp:3.3.1' compile 'com.squareup.retrofit2:retrofit:2.1.0' compile 'com.squareup.retrofit2:converter-gson:2.1.0' compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0-RC3' compile 'com.squareup.okhttp3:logging-interceptor:3.3.1' compile 'io.reactivex.rxjava2:rxandroid:2.0.0-RC1' compile 'io.reactivex.rxjava2:rxjava:2.0.0-RC3'
at java side:
List
Flowable.fromIterable(apps)
.flatMap(new Function<App, Publisher<ResponseBody>>() {
@Override
public Publisher<ResponseBody> apply(App app) throws Exception {
return infoModel.downImage2(app.getUrl());
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<ResponseBody>() {
@Override
public void onSubscribe(Subscription s) {
TLog.error("onSubscribe ");
}
@Override
public void onNext(ResponseBody responseBody) {
TLog.error("onNext " + responseBody.contentLength());
}
@Override
public void onError(Throwable t) {
TLog.error("onError " + t.toString());
}
@Override
public void onComplete() {
TLog.error("onComplete ");
}
});
Use Flowable as the return type in the interface, not Publisher.
On Fri, Sep 30, 2016, 10:51 AM 一叶飘舟 notifications@github.com wrote:
I have a problem:
java.lang.IllegalArgumentException: Unable to create call adapter for org.reactivestreams.Publisher for method ApiRxService.downImage2
Thank you!
build.gradle dependencies as following: compile 'com.squareup.okhttp3:okhttp:3.3.1' compile 'com.squareup.retrofit2:retrofit:2.1.0' compile 'com.squareup.retrofit2:converter-gson:2.1.0' compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0-RC3' compile 'com.squareup.okhttp3:logging-interceptor:3.3.1' compile 'io.reactivex.rxjava2:rxandroid:2.0.0-RC1' compile 'io.reactivex.rxjava2:rxjava:2.0.0-RC3'
at java side:
List apps = new ArrayList<>(); apps.add(new App("qq", " http://file.market.xiaomi.com/thumbnail/PNG/l62/AppStore/072725ca573700292b92e636ec126f51ba4429a50 ")); apps.add(new App("爱奇艺", " http://file.market.xiaomi.com/thumbnail/PNG/l62/AppStore/0a4e5f4d25ff24f2237ba83be3dd43205cbf1b5b4 "));
Flowable.fromIterable(apps) .flatMap(new Function<App, Publisher<ResponseBody>>() { @Override public Publisher<ResponseBody> apply(App app) throws Exception { return infoModel.downImage2(app.getUrl()); } }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber<ResponseBody>() { @Override public void onSubscribe(Subscription s) { TLog.error("onSubscribe "); } @Override public void onNext(ResponseBody responseBody) { TLog.error("onNext " + responseBody.contentLength()); } @Override public void onError(Throwable t) { TLog.error("onError " + t.toString()); } @Override public void onComplete() { TLog.error("onComplete "); } });
— You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub https://github.com/square/retrofit/issues/2035#issuecomment-250764860, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEQDOm5BzPrcLM2COlJcbfLE-rfGMks5qvSH0gaJpZM4KLJSG .
That's for APIs which are agnostic to the implementation. This is an RxJava 2 specific feature and this returns the more specific types directly. I can add support for recognizing Publisher and just pretend it's Flowable, but it would be incorrect not to support Flowable directly.
On Fri, Nov 11, 2016, 5:43 AM Daniele Segato notifications@github.com wrote:
Use Flowable as the return type in the interface, not Publisher.
@JakeWharton https://github.com/JakeWharton according to this wiki page https://github.com/ReactiveX/RxJava/wiki/Reactive-Streams in RxJava (2.0) we should be actually using Publisher in the core library and wrap it in Flowable / Observable / ... RxJava 2.0 types in extension libraries
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/square/retrofit/issues/2035#issuecomment-259930954, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEccSUg_a2fAs9J2W_Rnzb573-okVks5q9EbDgaJpZM4KLJSG .
@JakeWharton Any updates on this? Can we merge your adapter into here?
It already is.
On Thu, Jan 26, 2017 at 10:04 PM Jared Burrows notifications@github.com wrote:
@JakeWharton https://github.com/JakeWharton Any updates on this? Can we merge your adapter into here?
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/square/retrofit/issues/2035#issuecomment-275578893, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEY0xj_8ElZli7SkF9C2jyjhgsXslks5rWV6egaJpZM4KLJSG .
@JakeWharton Thanks. It is here: https://github.com/square/retrofit/tree/master/retrofit-adapters. I guess we can deprecate: https://github.com/JakeWharton/retrofit2-rxjava2-adapter.
@JakeWharton When is 2.2.0 coming out? It is still not on mavenCentral: https://repo1.maven.org/maven2/com/squareup/retrofit2/adapter-rxjava2.
It hasn't been released and we don't give ETAs. Hopefully soon.
On Thu, Jan 26, 2017 at 10:13 PM Jared Burrows notifications@github.com wrote:
@JakeWharton https://github.com/JakeWharton When is 2.2.0 coming out? It is still not on mavenCentral: https://repo1.maven.org/maven2/com/squareup/retrofit2/adapter-rxjava2.
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/square/retrofit/issues/2035#issuecomment-275579938, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEZREXxRDac9qEEnpnrkKEhHMNCNRks5rWWDpgaJpZM4KLJSG .
@JakeWharton Is the "retrofit2-rxjava2-adapter" included in Retrofit 2.2 by default? I can't use it without adding it as gradle dependency.
@KhalidElSayed It is in 2.2.0
. Make sure you have you dependencies like this:
dependencies {
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
}
Sources: https://github.com/square/retrofit#download and https://github.com/square/retrofit/tree/master/retrofit-adapters/rxjava2#download
@jaredsburrows Thanks, The deprecated one confusing me :)
RxJava 2 had released,when retrofit can support RxJava 2 ?Thank you!