Proguard:如何保留除特定条件以外的所有内容? [英] Proguard: How to keep everything except specific condition?

查看:247
本文介绍了Proguard:如何保留除特定条件以外的所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Proguard混淆我的代码,并且需要保留每个第三方库,例如:

I'm using Proguard to obfuscate my code, and I need to keep every third party libraries like:


-keep class com.layer.**
-dontwarn com.layer.**
-keep class com.twitter.**
-keep class android.support.**
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**
...

每当我添加一个新的第三方库时,我都需要检查其软件包名称并将其添加到我的proguard配置文件中,否则该应用程序可能会崩溃.

And whenever I add a new third party library, I need to check its package name and add it to my proguard config file, or the app may crashes.

我不能这样写规则吗?我不在乎不是我的代码.

Can't I write the rule just like this? I don't care about codes that's not mine.

-keep class !(my.package.name.**)
-dontwarn !(my.package.name.**)

谢谢!

推荐答案

要将除类之外的所有内容都保留在您自己的程序包中,您可以使用已经指出的规则(不包括方括号):

To keep everything except classes in your own package you can use the rule that you already pointed out (excluding the brackets):

-keep class !my.package.name.** { *; }

这将隐式保留所有其他内容. 如果需要,您仍然可以为课程另外添加 -keep 规则.

This will implicitly keep everything else. You still can add additionally -keep rules for your classes if needed.

-dontwarn 的规则应以类似的方式工作:

The rule for the -dontwarn should work in a similar way:

-dontwarn !my.package.name.**,**

如果需要,您还可以添加类似的 -dontnote 规则.

You can also add similar -dontnote rules if needed.

这篇关于Proguard:如何保留除特定条件以外的所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆