how to keep all methods in a class with ProGuard

2019-04-18 15:06发布

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?

2条回答
小情绪 Triste *
2楼-- · 2019-04-18 15:42

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.

查看更多
别忘想泡老子
3楼-- · 2019-04-18 15:58

try

-keep public class com.mycompany.myclass

( use keep, and no {*;} )

查看更多
登录 后发表回答