首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >2.找不到Retro菲特类文件

2.找不到Retro菲特类文件
EN

Stack Overflow用户
提问于 2019-02-27 19:56:28
回答 2查看 541关注 0票数 2

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

代码语言:javascript
复制
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 类文件进行追溯。2.Retrofit未找到

导致此错误的方法是getClient方法。据我所知,这是初始化的正确方法。

代码语言:javascript
复制
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;
}
EN

回答 2

Stack Overflow用户

发布于 2021-11-03 08:08:23

可能是gradle.build的一个问题。这种情况发生在您身上的一个可能的变体是在另一个模块中使用Retrofit实例。您需要向应用程序模块或任何需要依赖项的地方添加Retrofit的依赖项。

票数 2
EN

Stack Overflow用户

发布于 2022-08-12 05:18:36

我也有同样的问题。对我来说,对于应用程序来说,build.gradle中的依赖块已经超出了android块。解决方案:将依赖项块移动到android{ }块中。

安卓{。。。

代码语言:javascript
复制
dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    implementation 'androidx.navigation:navigation-fragment:2.3.5'
    implementation 'androidx.navigation:navigation-ui:2.3.5'
    implementation 'com.squareup.retrofit2:retrofit:2.7.2'
    implementation 'com.squareup.retrofit2:converter-gson:2.7.2'
    implementation 'com.squareup.okhttp3:okhttp:3.6.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54913508

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档