【问题标题】:Fail build if annotation is present with ProGuard如果 ProGuard 存在注释,则构建失败
【发布时间】:2016-04-23 22:39:46
【问题描述】:

如果我将调试代码留在应用程序中,我想使构建失败
是否可以通过 ProGuard 做到这一点?如果有,怎么做?

这是我目前拥有的:

/** Annotate methods that shouldn't be used in production. */
@Retention(RetentionPolicy.CLASS) // TODO which one?
@Target({CONSTRUCTOR, METHOD, TYPE})
public @interface DebugHelper {
}

class Utils {
    /**
     * Dig up object's internals (with reflection if need be)
     * and convert them to string. Useful for View/Fragment/Bundle/etc.
     */
    @DebugHelper
    public static String toString(Object value) {
        ...
    }
}

假设我不小心在代码中的某处留下了Utils.toString(veryBigObject)。我正在寻找一种方法来使构建失败(或输出注释/警告行)。请注意,有许多类和方法是这样注释的,因此将它们一一列出并不是解决方案。


或者如果上述方法不可行,我会很高兴 ProGuard 可以摆脱这些调用(以加快发布的应用程序)以及所有带有注释的方法/类@DebugHelper(以减小尺寸)。

我试过了:

-assumenosideeffects class ** {
    @net.twisterrob.java.annotations.DebugHelper <methods>;
}

但它给了我

注意:配置指定类'**'的方法没有任何副作用
注意:有 1 个“-assumenosideeffects”选项会尝试将所有方法与通配符匹配。这可能会导致诸如“wait()”和“notify()”之类的方法出现问题。您应该更准确地指定方法。 (http://proguard.sourceforge.net/manual/troubleshooting.html#nosideeffects)

即使注释非常具体。

【问题讨论】:

    标签: java android android-gradle-plugin proguard release


    【解决方案1】:

    在您的情况下,该消息是无害的,因为如果指定了注释过滤器,则相应的代码不会考虑在内。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-31
      • 1970-01-01
      相关资源
      最近更新 更多