如何使用proguard.cfg保存我的测试方法

时间:2011-06-01 05:37:12

标签: android proguard

对于我的Android测试测试,我需要在我的课程中添加一些额外的入口点。这些方法未在实际应用中使用。我的想法是用test_启动它们,并有一个通用的规则来排除它们被优化掉。这是我得到了多远:

-keepclassmembers class com.xxx.**.* {
    public ** test_* ();
    public ** test_* (**);
    public static ** test_* ();
    public static ** test_* (**);
}

但它仍然无效。刚刚从代码中删除了public static void test_destroy (final android.content.Context context)private void dropTables (final SQLiteDatabase db)。我不明白为什么。

如何正确使用通配符模式?

2 个答案:

答案 0 :(得分:4)

解决方案是

-keepclassmembers class com.XXX.**.* {
    *** test_* (...);
}

答案 1 :(得分:3)

另一种方法是使用注释(即番石榴的@VisibleForTesting)来标记这些方法。然后在proguard中,您可以使用该注释保留所有入口点和成员:

-keep @com.google.common.annotations.VisibleForTesting class *

-keepclasseswithmembers class * {
  @com.google.common.annotations.VisibleForTesting *;
}
相关问题