如何使用 proguard.cfg 保留我的测试方法
对于我的 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)
刚刚从代码中删除。我不知道为什么。
如何正确地将其用于通配符模式?
For my Android instrumentation test I need a few extra entry point into my classes. Those methods are not used in the actual application. My idea was to start them all with test_
and have a general rule to exclude them from being optimized away. This is how far I got:
-keepclassmembers class com.xxx.**.* {
public ** test_* ();
public ** test_* (**);
public static ** test_* ();
public static ** test_* (**);
}
But it still does not work. public static void test_destroy (final android.content.Context context)
and private void dropTables (final SQLiteDatabase db)
has just been removed from the code. And I have no idea why.
How is it properly used for wildcard patterns?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决办法是
The solution is
另一种方法是使用注释(即 guava 的 @VisibleForTesting)来标记这些方法。然后在 proguard 中,您可以使用该注释保留所有入口点和成员:
Another way to do this is to use an annotation (i.e. guava's @VisibleForTesting) to mark those methods. Then in proguard you can keep all entry points and members with that annotation: