如何使用ProGuard将所有方法保留在一个类中

如何使用ProGuard将所有方法保留在一个类中

本文介绍了如何使用ProGuard将所有方法保留在一个类中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ProGuard来优化我的Android应用程序.但是对于Android工具测试,我需要一些(但不是全部)类来保留所有成员.我尝试了各种方法,最后一种是:

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.

有人知道正确的语法来使类完全不变且不受ProGuard影响吗?

Does anyone know the correct syntax to keep a class completely unchanged and untouched by ProGuard?

推荐答案

好了,这是告白的时间.问题是胡扯. -keepclassmembers是正确的.发生此问题的原因是队友破坏了代码,而构造函数确实不在那儿.

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.

请注意,如果更改了整个类并进行了优化,则应按照kharles的建议使用-keep,但是需要{*;}来确保所有方法都保持不变.

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.

这篇关于如何使用ProGuard将所有方法保留在一个类中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 23:58