第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

預(yù)期 Android API 級別為 21+,但使用 Retrofit 2、OkHttp3

預(yù)期 Android API 級別為 21+,但使用 Retrofit 2、OkHttp3

揚帆大魚 2024-01-28 17:31:32
我使用Retrofit 2 和 OkHttp3處理來自服務(wù)器的數(shù)據(jù),在使用Min_SDK 17時出現(xiàn)錯誤,我的設(shè)備的 API也是17我嘗試了這個答案:How to fix Expected Android API level 21+ but was 19 in Android我也嘗試了這個答案https://github.com/square/okhttp/issues/4597#issuecomment-461204144但我得到同樣的錯誤。我的 API 客戶端    public class APIClient {private static Retrofit retrofit;private static OkHttpClient okHttpClient;public static Retrofit getInstanceRetrofit(){    if(okHttpClient==null) {        initOkHttp();    }    if(retrofit==null) {        retrofit = new Retrofit.Builder()                .baseUrl(Const.URL)                .client(okHttpClient)                .addConverterFactory(GsonConverterFactory.create())                .build();    }        return retrofit;}  private static void initOkHttp() {    int REQUEST_TIMEOUT = 60;    OkHttpClient.Builder httpClient = new OkHttpClient().newBuilder()            .connectTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS)            .readTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS)            .writeTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS);    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);    httpClient.addInterceptor(interceptor);    httpClient.addInterceptor(new Interceptor() {        @Override        public Response intercept(@NonNull Chain chain) throws IOException {            Request original = chain.request();            Request.Builder requestBuilder = original.newBuilder()                    .addHeader("Accept", "application/json")                    .addHeader("Content-Type", "application/json");            Request request = requestBuilder.build();            return chain.proceed(request);        }    });    okHttpClient = httpClient.build();}  }
查看完整描述

3 回答

?
萬千封印

TA貢獻1891條經(jīng)驗 獲得超3個贊

問題是您已經(jīng)添加了OkHttp兩次依賴項。

在你的build.gradle你有:

dependencies {
    ...
    implementation "com.squareup.okhttp3:okhttp:3.11.0"
    ...
    implementation "com.squareup.okhttp3:okhttp:3.13.1"}

從版本 3.13.0 開始,他們刪除了對 Android < 5 的支持。您只需刪除

implementation "com.squareup.okhttp3:okhttp:3.13.1"

線,它應(yīng)該工作正常


查看完整回答
反對 回復(fù) 2024-01-28
?
慕桂英546537

TA貢獻1848條經(jīng)驗 獲得超10個贊

如果你們?nèi)匀槐罎ndroid 4.0 and above,這里有一個快速解決方案:


implementation("com.squareup.retrofit2:retrofit:2.7.1")


implementation("com.squareup.okhttp3:okhttp:3.12.8") {

force = true

}


implementation "com.squareup.okhttp3:logging-interceptor:3.12.8"

以上代碼經(jīng)過測試和驗證,Android 4.4


查看完整回答
反對 回復(fù) 2024-01-28
?
江戶川亂折騰

TA貢獻1851條經(jīng)驗 獲得超5個贊

在你的 gradle 文件中你有:

implementation "com.squareup.okhttp3:okhttp:3.11.0"

文檔說:

https://square.github.io/okhttp/

OkHttp 適用于 Android 5.0+(API 級別 21+)和 Java 8+。

OkHttp 3.12.x 分支支持 Android 2.3+(API 級別 9+)和 Java 7+。這些平臺缺乏對 TLS 1.2 的支持,不應(yīng)使用。但由于升級很困難,我們將在 2020 年 12 月 31 日之前將關(guān)鍵修復(fù)程序向后移植到 3.12.x 分支。

所以你可以嘗試:

implementation "com.squareup.okhttp3:okhttp:3.12.0"


查看完整回答
反對 回復(fù) 2024-01-28
  • 3 回答
  • 0 關(guān)注
  • 352 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號