Oridadedles
Oridadedles

Reputation: 871

Expected Android API level 21+ but was 30

How is it possible that I get this message? It does not make any sense. I'm using com.squareup.retrofit2:retrofit:2.9.0

     Caused by: java.lang.IllegalStateException: Expected Android API level 21+ but was 30
    at okhttp3.internal.platform.AndroidPlatform$Companion.buildIfSupported(AndroidPlatform.kt:370)
    at okhttp3.internal.platform.Platform$Companion.findPlatform(Platform.kt:204)
    at okhttp3.internal.platform.Platform$Companion.access$findPlatform(Platform.kt:178)
    2020-09-16 12:37:07.645 6480-6480/lv.ltt.gasogmp.dev_v3 E/AndroidRuntime:     at 
    okhttp3.internal.platform.Platform.<clinit>(Platform.kt:179)

Upvotes: 70

Views: 28605

Answers (4)

Samiran
Samiran

Reputation: 2954

Upgrage Okhttp3 or retrofit version

Latest Okhttp3 version is 4.9.2
Latest Retrofit version is 2.9.0

implementation 'com.squareup.okhttp3:okhttp:4.9.2' 
implementation 'com.squareup.retrofit2:retrofit:2.9.0'

Upvotes: 1

Moumit
Moumit

Reputation: 9510

Add implementation 'com.squareup.okhttp3:okhttp:4.9.2' inside android\app\build.gradle

dependencies {
    ........
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.android.support:multidex:1.0.3'   
    implementation 'com.squareup.okhttp3:okhttp:4.9.2' 
    ..........
}

Upvotes: 3

Hitesh Kushwah
Hitesh Kushwah

Reputation: 1361

Just Add the Dependency implementation 'com.squareup.okhttp3:okhttp:4.9.2'

PS - Check the latest version here before you add the dependency https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp

Upvotes: 65

Jesse Wilson
Jesse Wilson

Reputation: 40587

Add an explicit dependency on OkHttp 4.9.0. Or whatever is newest at the time you read this.

This bug is embarrassing but it's been fixed for so long that you shouldn’t be encountering it in new code.

Upvotes: 109

Related Questions