我的应用程序中有以下依赖项:
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方法。据我所知,这是初始化的正确方法。
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;
}发布于 2021-11-03 08:08:23
可能是gradle.build的一个问题。这种情况发生在您身上的一个可能的变体是在另一个模块中使用Retrofit实例。您需要向应用程序模块或任何需要依赖项的地方添加Retrofit的依赖项。
发布于 2022-08-12 05:18:36
我也有同样的问题。对我来说,对于应用程序来说,build.gradle中的依赖块已经超出了android块。解决方案:将依赖项块移动到android{ }块中。
安卓{。。。
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'
}}
https://stackoverflow.com/questions/54913508
复制相似问题