java ProGuard remove (shrink) unused classes

◇◆丶佛笑我妖孽 提交于 2019-12-06 02:52:13

The optimization isn't performed because ProGuard decides not to inline the method Edition#is, so it then can't simplify the resulting series of instructions. The method is not inlined because it is not very short and it is also invoked more than once. You could work around the first criterion with this undocumented JVM option for ProGuard:

-Dmaximum.inlined.code.length=16

Alternatively, you could work around the second criterion, by making sure the method is only invoked once:

return Edition.is(Edition.FREE) ?
    new com.site.free.MyApp() :
    new com.site.pro.MyApp();

Alternatively, you could probably create short functions isFree() and isPro(), because they would return constants, which would be inlined.

It's a good practice to check the processed code if you're expecting some particular optimizations, because they are often subject to complex constraints.

Nice to hear that you like ProGuard.

It is because your method is(...) can take in more values than 1 and 2 only. It could be called elsewhere from the code with 3, 4, 6... Proguard cannot exclude that case.

The solution to your issue is to make Edition an enum. You would not need the is(...) method anymore and could rely on equals(...).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!