问题
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?
回答1:
The solution is
-keepclassmembers class com.XXX.**.* {
*** test_* (...);
}
回答2:
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:
-keep @com.google.common.annotations.VisibleForTesting class *
-keepclasseswithmembers class * {
@com.google.common.annotations.VisibleForTesting *;
}
来源:https://stackoverflow.com/questions/6196746/how-to-keep-my-test-methods-with-proguard-cfg