首页 > 解决方案 > Android - 改造 2 - 无法解析 RxJava2CallAdapterFactory

问题描述

我在我的应用程序中使用改造 2 和 rxjava 2。这些是我的 gradle 实现:

implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.4.0'

implementation 'io.reactivex.rxjava2:rxjava:2.2.1'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'

这是我的 API 连接类:

public class ApiConnection {
  private static String BaseUrl = "http://mysites.com/";
  private static Retrofit retrofit = null;

  public static Retrofit getClient() {
    Gson gson = new GsonBuilder()
      .setLenient()
      .create();

    if (retrofit == null) {
      retrofit = new Retrofit.Builder()
        .baseUrl(BaseUrl)
        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
        .addConverterFactory(GsonConverterFactory.create(gson))
        .build();
    }
    return retrofit;
  }
}

我在这一行遇到错误:

RxJava2CallAdapterFactory

这是错误:

Cannot resolve symbol 'RxJava2CallAdapterFactory

我的代码有什么问题?

标签: androidretrofit2rx-java2

解决方案


正确的导入是implementation "com.squareup.retrofit2:adapter-rxjava2:2.4.0"(注意使用rxjava2)


推荐阅读