java - Retrofit 2 类文件问题

标签 java android retrofit2 rx-java2

我目前在应用程序中使用改造 2 时遇到问题。

public static Retrofit getClient(Context context)
{

    if (okHttpClient == null)
        initOkHttp(context);

    if (retrofit == null)
    {
        retrofit = new Retrofit.Builder()
                .baseUrl(CaselotREST.CASELOT_BASEURL)
                .client(okHttpClient)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    return retrofit;
}

当我尝试编译我的项目时,出现以下错误。

error: cannot access Retrofit class file for retrofit2.Retrofit not found

最佳答案

我已经弄清楚了。该问题源于我们的 Android 应用程序中代码库的模块化。我的 Android 应用程序中有很多模块,每个模块都有依赖项。改造的依赖项位于 Webapi 模块中,但不在主应用程序模块中。要解决这个问题,请将以下内容添加到主 gradle 文件

implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
implementation 'com.squareup.retrofit2:retrofit:2.2.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'

关于java - Retrofit 2 类文件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54919533/

相关文章:

java - 如何向 Eclipse 指示我的运行时库在哪里?

ToggleButton 内的 Android 文本不会居中

android - 将游标数据复制到 arraylist

java - 为什么从 ViewModel 进行调用时,Retrofit enqueue 不起作用?

java - 运行其他类的 main 方法

java - 用于保存 Java -> HTML 的 Intellij IDEA 插件?

android - 如何更改android中的数字选择器样式?

android - 如何在 Retrofit (Android) 中获取没有任何键的 JSON 数组?

android - Retrofit 2 - 如何在接收 JSON 响应时显示进度条

java - 以编程方式修改 Minecraft World 文件 (Java)