【问题标题】:Proguard not keeping class although it says soProguard 没有上课,尽管它这么说
【发布时间】:2020-04-29 12:06:32
【问题描述】:

我试图阻止 proguard 重命名/优化具有特定注释的类。那里有很多例子,应该是直截了当的,但 proguard 的行为并不像我预期的那样。

问题

Proguard v6.2.2 混淆了用@KeepClass 注释的类,尽管-whyareyoukeeping 显示test.KeepMe is kept by a directive in the configuration。 我可以通过一个简单的 3 文件项目重现该问题。

Proguard 配置:

-optimizations !code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 3
-allowaccessmodification

-adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

-keep public class test.Entry {
    public static void main(java.lang.String[]);
}

-keep @proguard.annotation.KeepClass public class * {
    *;
}

-whyareyoukeeping class test.KeepMe

应该保留的类:

import proguard.annotation.KeepClass;

@KeepClass
public class KeepMe
{
}

Proguard 日志:

Explaining why classes and class members are being kept...
Printing usage to [D:\Development\Projects\ProguardTest\build\usage.txt]...

test.KeepMe
  is kept by a directive in the configuration.

Removing unused program classes and class elements...
  Original number of program classes: 3
  Final number of program classes:    2

最后是处理后的jar文件中的文件:

- test
   |- Entry.class
   |- a.class (Obfuscated KeepMe class)

但是,如果我在 proguard 配置中使用

明确列出该类
-keep class test.KeepMe{*;}

proguard 报告相同的日志输出,但该类未受影响(如预期的那样)

是我遗漏了什么还是 proguard 中的错误?

【问题讨论】:

    标签: java proguard


    【解决方案1】:

    事实证明,这个问题实际上与 proguard 中的一个错误有关。在尝试了最新的测试版后,它按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-11
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      • 1970-01-01
      • 2017-05-02
      • 1970-01-01
      • 2023-02-16
      相关资源
      最近更新 更多