Android打包失敗出現Proguard returned with error code 1. See console的錯誤


這個問題是由於代碼混淆引起的,找不到引用包。
只需在你的proguard-project.txt中添加如下兩行即可。
-libraryjars libs/okio-1.6.0.jar(你可以根據你的項目提示,添加需要的jar。)
備注:
如果添加上面兩行后依然打包不成功,那么你需要修改位於
android-sdk-windows\tools\proguard\bin的目錄下的:proguard.bat 文件,
用記事本打開,修改如下:
把
call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %*
改為:
call %java_exe% -jar "%PROGUARD_HOME%"\lib\proguard.jar %1 %2 %3 %4 %5 %6 %7 %8 %9
即可!
此方法是把當前版本SDK改成和之前SDK版本中含有的proguard.bat文件一致!
不混淆第三方jar包包括以下方面
- libs中的第三方jar包(第三方jar包中如果有.so文件,不用去理會)
- 如果有些類調用了jni也不需要混淆,不然會出錯。
- 還有如果項目中有其他項目作為library引入,那這些項目的一些類也不能混淆。
混淆配置整理
#====================================第三方=============================================== #聲明第三方jar包,不用管第三方jar包中的.so文件(如果有) -libraryjars libs/android-support-v4.jar #不混淆第三方jar包中的類 -dontwarn android.support.v4.** -keep class android.support.v4.**{*;} #=====================百度地圖,你需要添加以下申明:===================== -libraryjars libs/locSDK_6.23.jar -keep class com.baidu.**{*;} -keep class vi.com.gdi.bgl.android.**{*;} #=====================xUtils-不要混淆xUtils中的注解類型,對使用DbUtils模塊持久化的實體類不要混淆,或者注解所有表和列名稱===================== -libraryjars libs/xUtils-2.6.14.jar -keep class * extends java.lang.annotation.Annotation {*;} #@Table(name="xxx"),@Id(column="xxx"),@Column(column="xxx"),@Foreign(column="xxx",foreign="xxx"); #=====================litpal框架混淆===================== -libraryjars libs/litepal-1.3.1.jar -dontwarn org.litepal.* -keep class org.litepal.**{*;} -keep enum org.litepal.** -keep interface org.litepal.**{*;} -keep public class * extends org.litepal.** -keepattributes *Annotation* -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keepclassmembers class * extends org.litepal.crud.DataSupport{*;} #=====================okhttputils框架===================== #====okhttputils==== -libraryjars libs/okhttputils.jar -dontwarn com.zhy.http.** -keep class com.zhy.http.**{*;} -keep interface com.zhy.http.**{*;} #====okhttp==== -libraryjars libs/okhttp-2.7.0.jar -dontwarn okhttp3.** -keep class okhttp3.**{*;} -keep interface okhttp3.**{*;} -keepattributes Signature -keepattributes *Annotation* -dontwarn com.squareup.okhttp.** -keep class com.squareup.okhttp.**{*;} -keep interface com.squareup.okhttp.**{*;} #====okio==== -libraryjars libs/okio-1.6.0.jar -dontwarn java.nio.file.* -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement -dontwarn okio.** -keep class okio.**{*;} -keep interface okio.**{*;} #====gson==== -libraryjars libs/gson-2.2.1.jar -keep class sun.misc.Unsafe{*;} -dontwarn com.google.gson.** -keep class com.google.gson.**{*;} -keep class com.google.gson.stream.**{*;} -keep class com.google.gson.examples.android.model.**{*;} #=====================pulltorefresh框架===================== -dontwarn com.handmark.pulltorefresh.library.** -keep class com.handmark.pulltorefresh.library.**{*;} -dontwarn com.handmark.pulltorefresh.library.extras.** -keep class com.handmark.pulltorefresh.library.extras.**{*;} -dontwarn com.handmark.pulltorefresh.library.internal.** -keep class com.handmark.pulltorefresh.library.internal.**{*;} #==================================API================================================= #API里邊的類,最好都要避免混淆 -keep public class * extends android.app.Fragment -keep public class * extends android.app.Activity -keep public class * extends android.app.Application -keep public class * extends android.app.Service -keep public class * extends android.content.BroadcastReceiver -keep public class * extends android.content.ContentProvider -keep public class * extends android.app.backup.BackupAgentHelper -keep public class * extends android.preference.Preference -keep public class * extends android.support.v4.** -keep public class com.android.vending.licensing.ILicensingService -dontwarn android.annotation -keepattributes *Annotation* #=====================保留了所有的Native變量名及類名===================== -keepclasseswithmembernames class * { native <methods>; } #某些構造方法不能去混淆 -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet); } #枚舉類不能去混淆 -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet, int); } #aidl文件不能去混淆. -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } -keepclassmembers class * { public <init>(org.json.JSONObject); } #=====================不混淆資源類===================== -keepclassmembers class **.R$* { public static <fields>; } #=================================當前項目================================================== #一般model最好避免混淆(model無關緊要,不混淆也沒多大關系)如: -keep class com.xxx.xxxx.xxxx.model.**{*;} #===================================其他常規================================================ #加上這句話,不然會在控制台中報warning警告【不添加的話比較好,可以用來驗證簽名是否成功】 #-ignorewarnings #設置混淆的壓縮比率 0 ~ 7 -optimizationpasses 5 #Aa aA -dontusemixedcaseclassnames #混淆后生產映射文件 map 類名->轉化后類名的映射 -verbose #混淆采用的算法. -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
其中,-keep class com.xxx.xxxx.xxxx.model.**{*;},填寫自己項目中model包路徑。
參考資料:
proguard returned with error code 1.異常的解決方法
http://wangwei121004-163-com.iteye.com/blog/1206595
Android打包失敗Proguard returned with error code 1. See console
http://www.cnblogs.com/snake-hand/p/3161438.html
Android 混淆打包不混淆第三方jar包
http://blog.csdn.net/qwiwuqo/article/details/33452107
android混淆打包配置(忽略第三方jar)
http://blog.csdn.net/wangbofei/article/details/8266553
Android 混淆代碼總結
http://blog.csdn.net/lovexjyong/article/details/24652085
android數據庫框架,sqlite框架,LitePal框架,混淆配置
http://www.aiuxian.com/article/p-1927692.html
[Android Pro] android 混淆文件project.properties和proguard-project.txt
http://www.cnblogs.com/0616--ataozhijia/p/3730746.html
關於使用了OkHttp和Android-PullToRefresh開源庫后如何混淆
http://www.codes51.com/article/detail_124186.html
Android之混淆心得與親身體驗
http://www.cnblogs.com/lee0oo0/archive/2013/12/04/3457877.html
[置頂] Android 混淆代碼總結
http://blog.csdn.net/lovexjyong/article/details/24652085
android 代碼混淆示例
http://www.cnblogs.com/lesliefang/p/3819259.html
OKHttpUtils框架
