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框架

https://github.com/hongyangAndroid/okhttp-utils

https://github.com/pengjianbo/OkHttpFinal

Android混淆打包配置总结的更多相关文章

  1. android混淆打包配置(忽略第三方jar)

    在project.properties里加上   proguard.config=proguard.cfg proguard.cfg 配置如下: -optimizationpasses 5-dontu ...

  2. android -------- 混淆打包报错(warning - InnerClass annotations are missing corresponding EnclosingMember annotations)

    最近做Android混淆打包遇到一些问题,Android Sdutio 3.1 版本打包的 错误如下: Android studio warning - InnerClass annotations ...

  3. android——混淆打包

    网上搜了一大堆,在此不一一赘诉. 直接讲解了 如上图这么配置,其实就是加上一句话而已.告诉打包工具混淆打包的代码放在./proguard-project.txt这里 proguard.config=. ...

  4. Android 混淆打包

    有些时候我们希望我们自己的apk包不能被别人反编译而获取自己的源代码.这就需要我们通过Android提供的混淆打包技术来完成. 一.没有引用外部包的情况: 这种情况下代码混淆的方式相对简单: 1)只需 ...

  5. [原] Jenkins Android 自动打包配置

    一.Jenkins自动打包配置 目标:1. 自动打包:2. 自动上传:3. 友好下载 1. Jenkins简介 Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作. 减少重复劳 ...

  6. [原] Jenkins Android 自动打包配置(转)

    一.Jenkins自动打包配置 目标:1. 自动打包:2. 自动上传:3. 友好下载 1. Jenkins简介 Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作. 减少重复劳 ...

  7. Jenkins Android 自动打包配置

    一.Jenkins自动打包配置 目标:1. 自动打包:2. 自动上传:3. 友好下载 1. Jenkins简介 Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作. 减少重复劳 ...

  8. Android 混淆打包不混淆第三方jar包

    项目由于要公布,所以要混淆打包. 混淆打包流程: 1.在proguard-project.txt文件里加入不须要混淆的类和第三方的jar包   这个是保持自己包中不须要混淆的类,假设有些类调用了jni ...

  9. Android混淆打包

    一.理论知识   ProGuard是一款免费的Java类文件压缩器.优化器和混淆器.它能发现并删除无用类.字段(field).方法和属性值(attribute).它也能优化字节码并删除无用的指令.最后 ...

随机推荐

  1. JQuery中对Select的option项的添加、删除、取值

    jQuery获取Select选择的Text和Value: $("#select_id").change(function(){//code...}); //为Select添加事件, ...

  2. Scala List的排序函数sortWith

    //原始方法: //val list=List("abc","bcd","cde") scala> list.sortWith( (s ...

  3. Debug Tools

    .NET专用调试工具:MDBG .NET的死锁调试工具:ACorns.Debugging WinDBG+SOS(Windows平台下最强DeBug工具,是解决BUG的最后手段)

  4. sgu - 274 - Spam-filter

    题意:判断一个字符串是不是有效的邮件地址. 题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=274 ——>>照着题目做. ...

  5. CGContext绘图

    0 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 1 CGContextMoveToPoint 开始画线 2 CGContex ...

  6. 如何克隆路由器MAC地址,怎么操作?

    路由器的“MAC地址克隆”的意思是: 不克隆时,从外网访问你的电脑,获得的MAC地址是路由器的mac地址. 克隆后,从外网访问你的电脑,获得的MAC地址是你电脑网卡的mac地址. 实用举例如下: 中国 ...

  7. UVa572 Oil Deposits DFS求连通块

      技巧:遍历8个方向 ; dr <= ; dr++) ; dc <= ; dc++) || dc != ) dfs(r+dr, c+dc, id); 我的解法: #include< ...

  8. 添加zlib压缩步骤 OpenSSL

    1.Link Binary With Libraries 中添加 libz.dyllb 2.复制OpenSSL(libssl.a & libcryto.a & NSData+Cocoa ...

  9. poj1190生日蛋糕

    生日蛋糕 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12277 Accepted: 4325 Description 7月1 ...

  10. TreeView1MouseMove

    procedure TForm1.TreeView1MouseMove(Sender: TObject; Shift: TShiftState; X,   Y: Integer); var   nod ...