在Android中,是否有一个proguard规则可以保留类的所有内部对象并保护它们免受混淆?

发布于 2025-01-16 11:49:35 字数 472 浏览 2 评论 0原文

我在 android SDK 中有一些 dagger 类,在创建和发布发布版本时需要保护它们免受缩小和混淆。我通过在 @Module 和 @DaggerGenerate 注释周围使用自定义混淆器规则来保护它们。

-keep @dagger.Module public class * { public <methods>; }
-keep @dagger.internal.DaggerGenerated public class * {public <methods>;}

其中一些类具有也应该受到保护的伴生对象。目前,我通过使用 @Keep 专门注释同伴来保护它们。有没有办法指定一个 proguard 规则来自动保留同伴?

我尝试了一些变体,例如下面的变体,但没有一个能完成工作。

-keep @dagger.Module class *$Companion { *; }

I have some dagger classes in an android SDK that need to be protected from minification and obfuscation when creating and publishing the release version. I protect those by using custom proguard rules around the @Module and @DaggerGenerated annotations.

-keep @dagger.Module public class * { public <methods>; }
-keep @dagger.internal.DaggerGenerated public class * {public <methods>;}

Some of those classes have companion objects that should also be protected. At the moment, I protect them by annotating the companions specifically with @Keep. Is there a way to specify a proguard rule to automatically keep the companion?

I tried a few variations such as the one below but none of them got the job done.

-keep @dagger.Module class *$Companion { *; }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒芜了季节 2025-01-23 11:49:35

也许不是一个理想的解决方案,但您可以尝试保留整个包而不是单个文件,使用类似的方法:

-keep class com.foo.bar.** { *; }

这样,您也将覆盖此处找到的任何伴随对象

Perhaps not an ideal solution, but you could instead try to keep an entire package instead of individual files, using something like:

-keep class com.foo.bar.** { *; }

this way, you'll be covering any companion objects found here as well

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文