最近做项目时遇到这个问题了,就是在打包的时候遇到这个异常,在网上查了很多找到了解决方案如下
gradle在build混淆后的代码时,会出现如下错误提示:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
Warning: there were 2 unresolved references to library class members.
You probably need to update the library versions.
Alternatively, you may have to specify the option
'-dontskipnonpubliclibraryclassmembers'.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.
:app:transformClassesAndResourcesWithProguardForRelease FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
java.io.IOException: Please correct the above warnings first.
|
上面提示编译过程中出现了warning,要求修复,所以停止了编译。按照上面的提示在混淆配置文件proguard-rules.pro
中增加-dontskipnonpubliclibraryclassmembers
项,也不会起作用。只能按上面提示寻找warings,如下Log中的中间两行Waring
:
1
2
3
4
|
Note: the configuration refers to the unknown class 'com.alipay.mobile.security.senative.APSE'
Warning: com.baidu.platform.comapi.map.e: can't find referenced method 'float sqrt(float)' in library class android.util.FloatMath
Warning: com.tencent.connect.avatar.c: can't find referenced method 'float sqrt(float)' in library class android.util.FloatMath
Note: android.support.v4.text.ICUCompatIcs: can't find dynamically referenced class libcore.icu.ICU
|
中间两行Warning
是分别使用了百度地图的jar包和QQ第三方登录的jar包,其中使用了FloatMath.sqrt()这个方法后,编译时找不到,原因是使用了android 6.0的jar包去编译。通过查看源代码,发现源码里面有这个方法的实现,但反编译SDK中的android.jar
时,发现里面没有实现,坑!
之前一直没有使用android 23编译代码,现在项目要兼容6.0,就使用了6.0的编译环境,结果就出现了这样的错。唉,各种坑啊!
在proguard-rules.pro
文件中增加如下所示的配置:
1
2
|
-dontwarn com.baidu.**
-dontwarn com.tencent.**
|
以后遇上这种waring,都可以这样做,-dontwarn
是混淆参数,com.xxx
是包名,也就是忽略这个包名下面的waring。