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

2018-06-04 17:27:27 +08:00
 maxxfire

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

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

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

5424 次点击
所在节点    Android
11 条回复
shily
2018-06-04 18:58:58 +08:00
系统默认的已经提供大部分的功能了。
18914940609
2018-06-04 19:02:18 +08:00
三方库把涉及 json 的包跳过混淆基本就行了
boolean93
2018-06-04 20:53:03 +08:00
???release 里面把 minifyEnabled 开开不就完了???
maxxfire
2018-06-04 21:04:27 +08:00
@18914940609 它就不能写 1 行来设置我的 com.test.xxx.* 命名空间下的代码进行混淆吗。
如果要跳过第三方库,我引入了 10 个第三方库,还得写 10 行的配置。
这样的配置也太不人性了吧。。
CrisTao
2018-06-05 09:31:46 +08:00
只加固的路过
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
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
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
2018-06-06 09:00:02 +08:00
@AndroidTraveler 还是不行,算了,考虑用加固了。但是我不喜欢 360 和 TX。
janus77
2018-06-06 10:25:56 +08:00
你没弄明白的是,android 的混淆规则提供的是「 keep 的白名单」,除白名单之外的全部都需要混淆。
所以如果你想「只混淆某部分」,那么正确的做法是把除了这部分之外的所有部分是否混淆全部定义好。
gavin6liu
2018-06-07 09:48:58 +08:00
是啊,就没人做个简单点的混淆工具么。只是想混淆自己的某个包某个类。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/460297

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX