能否愉快的写个最简单的 proguard-rules 混淆配置? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
maxxfire

能否愉快的写个最简单的 proguard-rules 混淆配置?

  •  
  •   maxxfire Jun 4, 2018 13718 views
    This topic created in 2883 days ago, the information mentioned may be changed or developed.

    本意很简单:就是把 App 中我自己写的几个类混淆一下即可。(主要是些界面 UI 的代码)

    我以为只要一两句话就可以搞定了,结果查了一下午,全都是长篇大论的配置。

    安卓这样搞实在太麻烦了,请教大虾,有没有简单一点的办法?

    11 replies    2018-06-07 09:48:58 +08:00
    shily
      &nbp; 1
    shily  
       Jun 4, 2018 via Android
    系统默认的已经提供大部分的功能了。
    18914940609
        2
    18914940609  
       Jun 4, 2018
    三方库把涉及 json 的包跳过混淆基本就行了
    boolean93
        3
    boolean93  
       Jun 4, 2018
    ???release 里面把 minifyEnabled 开开不就完了???
    maxxfire
        4
    maxxfire  
    OP
       Jun 4, 2018
    @18914940609 它就不能写 1 行来设置我的 com.test.xxx.* 命名空间下的代码进行混淆吗。
    如果要跳过第三方库,我引入了 10 个第三方库,还得写 10 行的配置。
    这样的配置也太不人性了吧。。
    CrisTao
        5
    CrisTao  
       Jun 5, 2018
    只加固的路过
    AndroidTraveler
        6
    AndroidTraveler  
       Jun 5, 2018
    @maxxfire
    最近刚好在弄一个 Demo,也加了混淆。
    其实也是很简单,就按照官方的配置基本混淆。
    然后如果引入第三方库,第三方库都有介绍添加什么代码进行混淆。
    除此之外,就是一些基本的 Bean 需要混淆。
    你混淆之后如果程序功能运行正常,说明就没问题了。
    这是我的混淆文件,基本都是第三方库的
    #Glide
    -keep public class * implements com.bumptech.glide.module.GlideModule
    -keep public class * extends com.bumptech.glide.module.AppGlideModule
    -keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
    **[] $VALUES;
    public *;
    }

    #Umeng
    -keep class com.umeng.** {*;}

    -keepclassmembers class * {
    public <init> (org.json.JSONObject);
    }

    -keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
    }
    maxxfire
        7
    maxxfire  
    OP
       Jun 5, 2018
    @AndroidTraveler 这些是什么问题呢,帮忙看看:

    ......
    Warning:library class android.net.http.AndroidHttpClientConnection extends or implements program class org.apache.http.HttpConnection
    Warning:library class com.android.internal.http.multipart.MultipartEntity extends or implements program class org.apache.http.entity.AbstractHttpEntity
    ......
    Warning:library class org.apache.http.impl.conn.LoggingSessionOutputBuffer extends or implements program class org.apache.http.io.SessionOutputBuffer
    Warning:com.makeramen.roundedimageview.RoundedTransformationBuilder: can't find referenced class com.squareup.picasso.Transformation
    Warning:com.makeramen.roundedimageview.RoundedTransformationBuilder$1: can't find referenced class com.squareup.picasso.Transformation
    Warning:okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
    Warning:okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
    Warning:retrofit2.Platform$Java8: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
    Warning:there were 7 unresolved references to classes or interfaces.
    Warning:there were 38 instances of library classes depending on program classes.
    Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.

    Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
    > Job failed, see logs for details


    这个我都有加了:
    -dontnote org.apache.**
    -keep class org.apache.** { *; }
    AndroidTraveler
        8
    AndroidTraveler  
       Jun 5, 2018
    @maxxfire
    你用了 picasso 第三方库。
    上面有说如何混淆。
    你要到官网看。
    https://github.com/square/picasso


    ProGuard

    If you are using ProGuard you might need to add OkHttp's rules: https://github.com/square/okhttp/#proguard

    If you are using ProGuard you might need to add the following options:

    -dontwarn okhttp3.**
    -dontwarn okio.**
    -dontwarn javax.annotation.**
    -dontwarn org.conscrypt.**
    # A resource is loaded with a relative path so the package of this class must be preserved.
    -keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
    maxxfire
        9
    maxxfire  
    OP
       Jun 6, 2018
    @AndroidTraveler 还是不行,算了,考虑用加固了。但是我不喜欢 360 和 TX。
    rb6221
        10
    rb6221  
       Jun 6, 2018
    你没弄明白的是,android 的混淆规则提供的是「 keep 的白名单」,除白名单之外的全部都需要混淆。
    所以如果你想「只混淆某部分」,那么正确的做法是把除了这部分之外的所有部分是否混淆全部定义好。
    gavin6liu
        11
    gavin6liu  
       Jun 7, 2018
    是啊,就没人做个简单点的混淆工具么。只是想混淆自己的某个包某个类。
    About     Help     Advertise     Blog     API     FAQ     Solana     2916 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 49ms UTC 00:23 PVG 08:23 LAX 17:23 JFK 20:23
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86