改造 2.0 beta1

Retrofit 2.0 beta1

public interface AppApi 
{
        @GET("/api?action=" + ApiManager.API_USER)
        Observable<JsonObject> getUser();
}

whith Retrofit 2.0 beta1。我无法收到回复?

Retrofit 2.0 beta 不支持 Observable,现在?

现在需要一个适用于 RxJava 的适配器。

你可以从changeLog

那里得到消息

New: CallAdapter (and Factory) provides extension point for supporting multiple execution mechanisms. An RxJava implementation is provided by a sibling module.

尝试以下代码,问题可能会得到解决。

在 app/build.gradle

compile 'com.squareup.okhttp3:okhttp:3.0.1'
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
compile 'io.reactivex:rxandroid:0.24.0'

在您的 java 代码中(如您的 activity)

retrofit = new Retrofit.Builder().baseUrl(YOUR_END_POINT)
    .addConverterFactory(GsonConverterFactory.create())
    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
    .(other options.....)
    .build();

现在您将使用 RxJava

你可以这样写。

public interface AppApi {
   @GET("/api")
   Observable<JsonObject> getUser(@Query("action") String api_user);
}