V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
maxxfire
V2EX  ›  Android

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

  •  
  •   maxxfire · 2018-06-04 17:27:27 +08:00 · 5171 次点击
    这是一个创建于 2146 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    11 条回复    2018-06-07 09:48:58 +08:00
    shily
        1
    shily  
       2018-06-04 18:58:58 +08:00 via Android
    系统默认的已经提供大部分的功能了。
    18914940609
        2
    18914940609  
       2018-06-04 19:02:18 +08:00
    三方库把涉及 json 的包跳过混淆基本就行了
    boolean93
        3
    boolean93  
       2018-06-04 20:53:03 +08:00
    ???release 里面把 minifyEnabled 开开不就完了???
    maxxfire
        4
    maxxfire  
    OP
       2018-06-04 21:04:27 +08:00
    @18914940609 它就不能写 1 行来设置我的 com.test.xxx.* 命名空间下的代码进行混淆吗。
    如果要跳过第三方库,我引入了 10 个第三方库,还得写 10 行的配置。
    这样的配置也太不人性了吧。。
    CrisTao
        5
    CrisTao  
       2018-06-05 09:31:46 +08:00
    只加固的路过
    AndroidTraveler
        6
    AndroidTraveler  
       2018-06-05 09:45:30 +08:00
    @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
       2018-06-05 10:49:49 +08:00
    @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  
       2018-06-05 15:56:45 +08:00
    @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
       2018-06-06 09:00:02 +08:00
    @AndroidTraveler 还是不行,算了,考虑用加固了。但是我不喜欢 360 和 TX。
    janus77
        10
    janus77  
       2018-06-06 10:25:56 +08:00
    你没弄明白的是,android 的混淆规则提供的是「 keep 的白名单」,除白名单之外的全部都需要混淆。
    所以如果你想「只混淆某部分」,那么正确的做法是把除了这部分之外的所有部分是否混淆全部定义好。
    gavin6liu
        11
    gavin6liu  
       2018-06-07 09:48:58 +08:00
    是啊,就没人做个简单点的混淆工具么。只是想混淆自己的某个包某个类。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2976 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 11:11 · PVG 19:11 · LAX 04:11 · JFK 07:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.