【问题标题】:How can I disable renaming names of fragments classes during obfuscation?如何在混淆期间禁用片段类的重命名?
【发布时间】:2022-08-03 02:00:17
【问题描述】:

使用哪些 ProGuard/R8 规则?

目前只有活动没有重命名

我还需要为屏幕记录保留片段的名称,但片段中的代码本身应该被混淆

【问题讨论】:

    标签: android android-studio proguard android-r8 android-obfuscation


    【解决方案1】:

    您可以说 proguard 以保留所有扩展 androidx.fragment.app.Fragment 的类的名称(或您使用的另一个基本 Fragment 类)

    -keepnames class * extends androidx.fragment.app.Fragment
    

    【讨论】:

      【解决方案2】:

      我强烈建议您阅读此文档: https://www.guardsquare.com/manual/configuration/usage#keepoptions

      还要在 proguard.cfg 中使用 -keepnames 选项

      我给你举个例子:

      -keepnames class_specification
      

      您也可以使用它来避免混淆任何类名:

      -keepnames class ** { *; }
      

      【讨论】:

      • 它将保留所有类的名称
      【解决方案3】:

      只需添加 proguardrules 以保留包含所有碎片所以写在下面proguardrules

      -keep public class com.your_app_name.app.view.fragments.** {*;}
      

      例如:我的包名是com.tdscalculator.app 和我所有的碎片com -> tdscalculator -> app -> view -> fragments 里面,所以对于这个例子,我在上面写了proguardrule 所以相应地修改此规则

      如果你想保留不同目录的片段然后使用proguardrules 提及所有片段

      -keepnames class  com.your_app_name.app.view.fragments.HomeFragment{}
      

      快乐编码:)

      【讨论】:

      • 片段可以放在不同的包中
      • 然后你必须在保持类中给出所有片段名称我将修改上面的答案
      猜你喜欢
      • 2011-10-30
      • 2023-01-30
      • 2012-09-06
      • 2012-03-03
      • 2012-03-29
      • 2014-04-14
      • 2014-06-21
      • 2011-03-07
      • 1970-01-01
      相关资源
      最近更新 更多