在公司做了一个关于寻找停车场的app,需要借助高德地图。项目未完成,老板让打个包,看看效果, 一打包瞬间蛋疼了 。报错如下:
[2015-03-02 10:46:25 - MapDemo] Proguard returned with error code 1. See console
[2015-03-02 10:46:25 - MapDemo] Note: there were 172 duplicate class definitions.
[2015-03-02 10:46:25 - MapDemo] Warning: com.amap.api.navi.j: can't find referenced class com.amap.api.navi.model.AMapNaviCamera
[2015-03-02 10:46:25 - MapDemo] You should check if you need to specify additional program jars.
[2015-03-02 10:46:25 - MapDemo] Warning: there were 1 unresolved references to classes or interfaces.
[2015-03-02 10:46:25 - MapDemo] You may need to specify additional library jars (using '-libraryjars').
[2015-03-02 10:46:25 - MapDemo] java.io.IOException: Please correct the above warnings first.
[2015-03-02 10:46:25 - MapDemo] at proguard.Initializer.execute(Initializer.java:321)
[2015-03-02 10:46:25 - MapDemo] at proguard.ProGuard.initialize(ProGuard.java:211)
[2015-03-02 10:46:25 - MapDemo] at proguard.ProGuard.execute(ProGuard.java:86)
[2015-03-02 10:46:25 - MapDemo] at proguard.ProGuard.main(ProGuard.java:492)
原因分析:
为了代码的安全 , 我们都会做代码混淆处理 ,而高德自己本身已经做了代码混淆 ,所以高德提供的类会找不到引用,既然高德已经做了代码混淆,我们就不需要再次混淆。
解决方案:
在progurd-protected.txt文件中添加以下代码:
-libraryjars libs/AMap_3DMap_V2.3.1.jar
-libraryjars libs/Android_Navi_V1.1.0.jar
-libraryjars libs/Android_Location_V1.3.0.jar
-libraryjars libs/AMap_Services_v2.3.1.jar
-dontwarn com.amap.api.**
-dontwarn com.a.a.**
-dontwarn com.autonavi.**
-keep class com.amap.api.** {*;}
-keep class com.autonavi.** {*;}
-keep class com.a.a.** {*;}
再次打包,,,,瞬间解决。
总结:在引入第三方jar包的时候要注意,该包是否已混淆过代码。再比如:百度地图的sdk,支付宝的sdk等,他们都自己已经混淆过代码,不需要我们在此处理了,同样需要在produrd-protected.txt文件中添加不再次混淆的声明。
希望对有同样问题兄弟们能够获得帮助。