android - 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
我的代码有什么问题?
解决方案
正确的导入是implementation "com.squareup.retrofit2:adapter-rxjava2:2.4.0"
(注意使用rxjava2)
推荐阅读
- php - 如何将 PHP 值发送回 HTML 表单?
- powershell-2.0 - 当Powershell 2中的文件夹达到一定大小时重命名文件夹+删除超过一定大小的任何内容
- python - 以与输入相同的顺序返回列表的索引
- python - 命令“python setup.py egg_info”在 /tmp/pip-build-qgafa8x3/numba/ 中失败,错误代码为 1
- spring-boot - 保存新的父+子实体时“参数索引超出范围”(manyToOne)
- http - HTTP POST请求中的自定义内容类型?
- firebase - 使用 fastlane 和 Firebase App Distribution 分发 Flutter 应用
- mongodb - Mongodb - 索引使用和应用
- python - 用于测试 Postgres 连接并获取响应代码的 Python 代码
- android - 颤振错误:没有为“对象”类型定义方法“数据”