我的应用程序中有以下依赖项:
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'org.slf4j:slf4j-api:1.7.21'
implementation 'net.danlew:android.joda:2.7.2'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.okhttp3:okhttp:3.7.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.3'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
我最初有不同版本的改造库,这些版本导致了错误。 Refrofit dependency issues我已经解决了这个问题。但是,现在在编译时,出现以下错误:
错误:无法访问 Retrofit retrofit2.Retrofit 的类文件未找到
导致此错误的方法是 getClient 方法。 据我所知,这是正确的初始化方式
private static Retrofit retrofit = null;
private static int REQUEST_TIMEOUT = 60;
private static OkHttpClient okHttpClient;
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;
}
最佳答案
可能是gradle.build中的问题。发生这种情况的一个可能的变体是在另一个模块中使用 Retrofit 的实例。您需要将 Retrofit 的依赖项添加到您的应用程序模块或任何需要依赖项的地方。
关于android - Retrofit2.Retrofit 的 Retrofit 类文件未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54913508/