期望的Android API级别为21+,但实际为30。

70

我怎么会收到这个消息?这毫无意义。

我正在使用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)

可能是重复的问题,参考链接:https://dev59.com/lOk5XIcBkEYKwwoY49sn - RAINA
4
那个问题是关于SDK INT何时实际低于21的。但是我有SDK INT 30! @RAINA - Oridadedles
它也与SDK 28兼容。 - Oridadedles
@JesseWilson 是的,我可以这样做,不过他们应该改进异常消息,因为它并不完全正确,而且容易引起困惑。 - Oridadedles
与 'com.github.bumptech.glide:okhttp3-integration:4.11.0' 相关的问题类似。看起来该库不支持 API 30。 - Darari Nur Amali
显示剩余4条评论
4个回答

106

在代码中明确添加对Okhttp 4.9.0的依赖关系,或者使用你阅读此内容时最新的版本。

这个缺陷很尴尬,但已经被修复很久了,所以你不应该在新代码中遇到它。


对我有用。我还必须更新一些okio用法(直接访问“源”和“buffed”,而不是调用它们的方法)。 - Rodrigo Calderano Barbacovi
最新版本是4.9.1。在阅读此内容时,请查看以下链接以获取最新版本:https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp - Joshua Pinter
3
对于仍在使用OkHttp 3.x版本的用户,升级到3.14.7或更高版本可以解决该错误。请参考此更改日志条目:https://square.github.io/okhttp/changelog_3x/#version-3147(撰写时的最新版本是3.14.9)。 - Klemens Zleptnig
我使用了implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.11",但是我仍然遇到了问题。 - undefined

65

谢谢,我花了很多时间来解决问题,因为我的应用在Android 11上无法正常工作。再次感谢你。 - Dhananjay pathak

3
implementation 'com.squareup.okhttp3:okhttp:4.9.2' 添加到 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' 
    ..........
}

1

升级Okhttp3或Retrofit版本

最新的Okhttp3版本是4.9.2
最新的Retrofit版本是2.9.0

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接