我目前在应用程序中使用改造 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/