引用 okhttp3 后编译报错

implementation("com.squareup.okhttp3:okhttp:3.14.1")方式引用 okhttp3 后,执行编译,报错,内容如下:
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process D:\gradle\caches\modules-2\files-2.1\com.squareup.okhttp3\okhttp\3.14.1\67612a22d4b8f33c55263b188bf5a72774d06d18\okhttp-3.14.1.jar

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.

Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete

Caused by: com.android.tools.r8.utils.AbortException: Error: Static interface methods are only supported starting with Android N (--min-api 24): okhttp3.Request okhttp3.Authenticator.lambdastatic0(okhttp3.Route, okhttp3.Response)

解决办法
在项目的build.gradle中的defaultConfig中加入下面这句话
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容