android - Retrofit2.Retrofit 的 Retrofit 类文件未找到

标签 android retrofit rx-java retrofit2

我的应用程序中有以下依赖项:

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/

相关文章:

Android Studio InstrumentationTestCase 配置和日志输出

android - 如何在同一级别解析具有重复元素的此 xml 文件

scala - combineLatest 仅在其中一个流发生变化时发出

java - 使用 Observable.timeout 超时后会发生什么?

android - 禁用 DrawerLayout 的稀松布触摸手势

java - 在首选项屏幕底部添加一个按钮

java - 使用 Gson 优雅地处理嵌套的 json 对象?

java - 失败 : retrofit. RetrofitError : 307 Temporary Redirect?

Android RxJava 取消旧请求

android.database.sqlite.SQLiteException : near "(": syntax error (code 1):