使用 proguard 时如何保留/排除特定的包路径?
我想从 ProGuard 中排除一些文件路径。示例 com.myapp.customcomponents
我该如何执行此操作?我讨厌为这个目录中的每个自定义组件文件放置 -keep 标志。
我已经尝试过以下方法,但它不起作用:
-keep public class com.myapp.customcomponents.*
I want to exclude some file paths from ProGuard. Example com.myapp.customcomponents
How can I do this? I hate to be placing -keep flags for every single custom component file I have in this directory.
I have tried the following but it doesn't work:
-keep public class com.myapp.customcomponents.*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您没有指定它以何种方式不起作用。您的配置保留指定包中所有公共类的名称:
以下配置保留指定包及其子包中所有公共类的名称:
以下配置保留指定包中所有公共/受保护的类/字段/方法的名称指定包及其子包:
You don't specify in what way it doesn't work. Your configuration keeps the names of all public classes in the specified package:
The following configuration keeps the names of all public classes in the specified package and its subpackages:
The following configuration keeps the names of all public/protected classes/fields/methods in the specified package and its subpackages:
在 ProGuard 配置的底部添加以下行:
相应地替换包名称,此处包
com.facebook
将从 ProGuard 中排除。Add the following line at the bottom of your ProGuard configuration:
Replace package name accordingly, here the package
com.facebook
will be excluded from ProGuard.使用 Android Studio 4.0 对我有用的是:
其他答案中的双星号 (**) 对我不起作用。我也用R8尝试了上述配置,效果很好。
What worked for me using Android Studio 4.0 is:
Double asterisks (**) in other answers did not work for me. I also tried the above configuration with R8, works fine.
很多人似乎推荐
-keep class com.myapp.customcomponents.** { *; }
作为从处理中排除路径的一种方式。请参阅此处:此解决方案的问题是仍然存在一定程度的混淆,这可能会破坏您的代码。您可以在映射打印输出中看到映射:
我选择的解决方案是一个两步过程。首先,使用
injars
和过滤器来选择我想要处理的包路径。可以将其他包路径添加为库。其次,将处理后的 jar 与原始 jar 合并,但仅合并那些跳过的路径。
结果是一个合并的 jar,它是已处理的包路径和跳过的路径的组合。如果有人可以提供一种完全跳过某些路径处理的方法(我还没有找到),那么这个练习是无效的。
Lots of people seem to recommend
-keep class com.myapp.customcomponents.** { *; }
as a way to exclude a path from being processed. See here:The problem with this solution is that there is still some level of obfuscation happening, which can break your code. You can see the mapping in the mapping print out:
The solution I have opted for is a two step process. First, use
injars
with a filter to select the package path I would like to process. It is possible to add the other package pathes as libraries.Second, merge the processed jar with the original jar, but only those paths that were skipped.
The result is a merged jar that is the combination of the processed package path and the skipped paths. This exercise is invalid, if someone can provide a way to skip processing of certain paths completely (which I haven't found).
将所有与模型相关的包括模型、请求和响应对象放入中央子包中。
例如:
com.example.models
然后将此行添加到您的
proguard-rules.pro
文件中:Put all your models-related include
models
,requests
andresponses
object into a central sub package.For example:
com.example.models
Then add this line to your
proguard-rules.pro
file: