Skip to content Skip to sidebar Skip to footer

Does Proguard Converts All Enums To Int Or Needs To Be Configured For This

Does proguard automatically converts enums to integer for memory optimization or I have to configure it to do this? If I do have to configure what is the configuration?

Solution 1:

The optimization is listed on ProGuard's optimizations page. It appears to be one of the default optimizations, but it (like other optimizations) can be specified explicitly if you need more control (e.g. disabling all class/* optimizations aside from enum unboxing).

class/unboxing/enum

Simplifies enum types to integer constants, whenever possible.


Solution 2:

Proguard Settings

The Proguard needs to have the configuration like following:

minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

Note the inclusion of the proguard-android-optimize.txt file and not the proguard-android.txt file.

ProguardEnumIntDefTest is a sample project on Github that tries to find out if Proguard converts enums into ints.


Optimization

For the Proguard to optimize an enum, that enum should not have methods and associated values(fields). Proguard converts these simple enums to ints so, you get the type-safety of the enums at compile-time and the performance of the ints at runtime!



Post a Comment for "Does Proguard Converts All Enums To Int Or Needs To Be Configured For This"