集成okhttp, Android Studio编译失败:org.gradle.execution.MultipleBuildFailures: Build completed with 1 fail

背景:

项目中需要集成okhttp,但是编译release版本时失败(编译debug版本正常)。

Android Studio编译报错:


org.gradle.execution.MultipleBuildFailures: Build completed with 1 failures.
at org.gradle.initialization.DefaultGradleLauncherRunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)


原因

编译release版本时,进行了混淆了,但是工程中未配置针对okhttp的混淆配置文件。

解决方案

添加okhttp混淆配置:

-dontwarn com.squareup.okhttp.**
-keep class com.squareup.okhttp.**{*;}

# okhttp
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

# okio
-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-keep class okio.**{*;}
-dontwarn okio.**

附录:

安卓Proguard混淆配置:https://www.jianshu.com/p/155430a27f00

安卓开发技术分享: https://www.jianshu.com/p/442339952f26
点击关注专辑,查看最新技术分享
更多技术总结好文,请关注:「程序园中猿」

你可能感兴趣的:(集成okhttp, Android Studio编译失败:org.gradle.execution.MultipleBuildFailures: Build completed with 1 fail)