Proguard打包混淆報錯:can't find superclass or interface
在Eclipse打包工程時報如下錯誤:
[2014-01-06 08:58:44 - emp_android] Proguard returned with error code 1. See console
[2014-01-06 08:58:44 - emp_android] Warning: com.baidu.location.b$a: can't find superclass or interface android.location.GpsStatus$NmeaListener
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.APS: can't find referenced class android.telephony.cdma.CdmaCellLocation
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.APS: can't find referenced method 'int getLac()' in class android.telephony.NeighboringCellInfo
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.APS: can't find referenced class android.telephony.cdma.CdmaCellLocation
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.APS: can't find referenced class android.telephony.cdma.CdmaCellLocation
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.APS: can't find referenced class android.telephony.cdma.CdmaCellLocation
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.APS: can't find referenced class android.telephony.cdma.CdmaCellLocation
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.APS: can't find referenced class android.telephony.cdma.CdmaCellLocation
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.e: can't find referenced class android.telephony.SignalStrength
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.e: can't find referenced method 'void onSignalStrengthsChanged(android.telephony.SignalStrength)' in class android.telephony.PhoneStateListener
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.e: can't find referenced class android.telephony.SignalStrength
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.e: can't find referenced class android.telephony.SignalStrength
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.i: can't find referenced class android.telephony.SignalStrength
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.i: can't find referenced method 'void onSignalStrengthsChanged(android.telephony.SignalStrength)' in class android.telephony.PhoneStateListener
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.i: can't find referenced class android.telephony.SignalStrength
[2014-01-06 08:58:44 - emp_android] Warning: com.autonavi.aps.api.i: can't find referenced class android.telephony.SignalStrength
[2014-01-06 08:58:44 - emp_android] Warning: com.baidu.location.b: can't find referenced method 'boolean addNmeaListener(android.location.GpsStatus$NmeaListener)' in class android.location.LocationManager
[2014-01-06 08:58:44 - emp_android] Warning: com.baidu.location.b: can't find referenced method 'void removeNmeaListener(android.location.GpsStatus$NmeaListener)' in class android.location.LocationManager
[2014-01-06 08:58:44 - emp_android] Warning: com.baidu.location.b: can't find referenced class android.location.GpsStatus$NmeaListener
[2014-01-06 08:58:44 - emp_android] Warning: com.baidu.location.b$a: can't find referenced class android.location.GpsStatus$NmeaListener
[2014-01-06 08:58:44 - emp_android] Warning: com.baidu.location.c: can't find referenced class android.telephony.cdma.CdmaCellLocation
[2014-01-06 08:58:44 - emp_android] Warning: com.baidu.location.c$a: can't find referenced method 'int getLac()' in class android.telephony.NeighboringCellInfo
[2014-01-06 08:58:44 - emp_android] Warning: com.baidu.location.c$b: can't find referenced class android.telephony.SignalStrength
[2014-01-06 08:58:44 - emp_android] Warning: com.baidu.location.c$b: can't find referenced class android.telephony.SignalStrength
[2014-01-06 08:58:44 - emp_android] Warning: com.baidu.location.c$b: can't find referenced class android.telephony.SignalStrength
[2014-01-06 08:58:44 - emp_android] Warning: com.baidu.location.c$b: can't find referenced class android.telephony.SignalStrength
[2014-01-06 08:58:44 - emp_android] Warning: com.lakala.b.b$2: can't find referenced method 'boolean isWiredHeadsetOn()' in class android.media.AudioManager
[2014-01-06 08:58:44 - emp_android] Warning: com.lingtu.mapapi.MapView: can't find referenced method 'int getPointerCount()' in class android.view.MotionEvent
[2014-01-06 08:58:44 - emp_android] You should check if you need to specify additional program jars.
[2014-01-06 08:58:44 - emp_android] Warning: there were 20 unresolved references to classes or interfaces.
[2014-01-06 08:58:44 - emp_android] You may need to specify additional library jars (using '-libraryjars').
[2014-01-06 08:58:44 - emp_android] Warning: there were 8 unresolved references to program class members.
[2014-01-06 08:58:44 - emp_android] Your input classes appear to be inconsistent.
[2014-01-06 08:58:44 - emp_android] You may need to recompile them and try again.
[2014-01-06 08:58:44 - emp_android] Alternatively, you may have to specify the option
[2014-01-06 08:58:44 - emp_android] '-dontskipnonpubliclibraryclassmembers'.
[2014-01-06 08:58:44 - emp_android] java.io.IOException: Please correct the above warnings first.
[2014-01-06 08:58:44 - emp_android]at proguard.Initializer.execute(Initializer.java:321)
[2014-01-06 08:58:44 - emp_android]at proguard.ProGuard.initialize(ProGuard.java:211)
[2014-01-06 08:58:44 - emp_android]at proguard.ProGuard.execute(ProGuard.java:86)
[2014-01-06 08:58:44 - emp_android]at proguard.ProGuard.main(ProGuard.java:492)
大體意思是找不到相關的類或者方法,因為工程引入了第三方包,混淆的時候如果把第三方包也混淆了,那麼相關的類在使用這些包的時候就會找不到相關方法。
因此在proguard.cfg加上以下程式碼:
-dontwarn com.baidu.**
-keep class com.baidu.** { *;}
-dontwarn com.lakala.**
-keep class com.lakala.** { *;}
-dontwarn com.lingtu.**
-keep class com.lingtu.** { *;}
-dontwarn com.autonavi.**
-keep class com.autonavi.** { *;}
其實找不到引用的這個類是第三方包裡面的,而且很多時候我們只需要打亂自己的程式碼就行了,第三方包的程式碼就是否要打亂就不要管了。我們可以使用
-dontwarn com.xx.bbb.**-keep class com.xx.bbb.** { *;}
引數來保持第三方庫中的類而不亂,-dontwarn和-keep 結合使用,意思是保持com.xx.bbb.**這個包裡面的所有類和所有方法而不混淆,接著還叫ProGuard不要警告找不到com.xx.bbb.**這個包裡面的類的相關引用。
配置好後,重新打包,一切OK!而且程式能正確執行
(本文參考http://blog.csdn.net/u_xtian/article/details/7495023)