• Android混淆打包配置总结


    Android打包失败出现Proguard returned with error code 1. See console的错误

    这个问题是由于代码混淆引起的,找不到引用包。

    只需在你的proguard-project.txt中添加如下两行即可。

    -libraryjars libs/okio-1.6.0.jar(你可以根据你的项目提示,添加需要的jar。)

    备注:

    如果添加上面两行后依然打包不成功,那么你需要修改位于

    android-sdk-windows oolsproguardin的目录下的:proguard.bat 文件,

    用记事本打开,修改如下:

    call %java_exe% -jar "%PROGUARD_HOME%"libproguard.jar %*

    改为:

    call %java_exe% -jar "%PROGUARD_HOME%"libproguard.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

  • 相关阅读:
    hdu 携程全球数据中心建设 (球面距离 + 最小生成树)
    next_permutation()函数 和 prev_permutation() 按字典序求全排列
    poj 3792 Area of Polycubes (简单模拟)
    poj 3790 Recursively Palindromic Partitions (递推)
    hdu 1575 Tr A (矩阵快速幂入门题)
    hdu 2986 Ballot evaluation (模拟)
    sscanf() 和 sprintf()的用法。
    Codeforces Round #239 (Div. 2)
    hdu 2372 El Dorado (dp)
    hdu 3433 A Task Process(dp+二分)
  • 原文地址:https://www.cnblogs.com/whycxb/p/5485796.html
Copyright © 2020-2023  润新知