问题
I use ProGuard to optimize my Android Application. However for Android instrumentation test I need some (but not all) classes to keep all there members. I tried various approaches, the last being:
-keepclassmembers public class com.mycompany.myclass {
*;
}
But surprisingly I still get
java.lang.NoSuchMethodError: com.mycompany.myclass.<init>
The painful part here is that there are two constructors and one has quite a few parameters.
Does anyone know the correct syntax to keep a class completely unchanged and untouched by ProGuard?
回答1:
Well, it is confession time. The question is bollocks. The -keepclassmembers is correct. The problem occurred because a team mate broke the code and the constructor was truly not there.
Note that if there is a change that the whole class is optimized away then you should use -keep as kharles suggested but the {*;} is needed to ensure that all methods stay in place.
Note that the {*;} is for testing only. For production one should use a more fine grained approach.
I keep the question for anybody with the same problem.
回答2:
try
-keep public class com.mycompany.myclass
( use keep, and no {*;} )
来源:https://stackoverflow.com/questions/5592511/how-to-keep-all-methods-in-a-class-with-proguard