Using flattenpackagehierarchy or repackageclasses with applymapping

applymapping is ignored when using flattenpackagehierarchy or repackageclasses. Is it possible to use them in combination? That is obfuscate the packages of all classes not specified in mapping file.

An additional question: is it possible to obfuscate the enum name?

Hi @mirfatif,

First of all, welcome to the ProGuard Community!

Regarding applymapping and flattenpackagehierarchy/repackageclasses;
-applymapping can be used together with repackageclasses. It should normally not be ignored. Did you provide a path to the mapping file and a new package name.

Can you share your configuration file or a sample?

Regarding obfuscation of enums;
If the enum is not accessed through reflection, you can obfuscate it. If it’s accessed through reflection, then you must keep the name in your config.

If the enum is shrunk away (but there’s no issue with reflection) you can use the allowobfuscation keep modifier. This specifies that the entry points specified in the -keep option may be obfuscated, even if they have to be preserved otherwise. That is, the entry points may be renamed in the obfuscation step, but they may not be removed or optimized.

You can read more about this here:

And then cmd + f for “allowobfuscation”

If you can share your configuration and perhaps a small sample, we might be able to help determine why the -applymapping directive is not being applied for you.

If you have already done so, I suggest using the Proguard Playground when possible. It will allow you experiment with different -keep options to see their impact ahead of time, without having to build. This saves lots of time and effort.

Please let me know if anything is not clear.

Best Regards,

Jack

1 Like

Actually you are correct. I was testing with R8 and wrongly assumed that Proguard would behave the same way. Testing with Proguard plugin, not only applymapping worked with repackageclasses, but also repackageclasses gave more satisfactory results by moving 100% moveable classes to the single package.

But what’s heartbreaking is that APK built with Proguard is 17% (0.6 MB) bigger than that built with R8 (applying the default proguard-android-optimize.txt in both cases, plus a few custom rules). Having a quick look in APK Analyzer, the major difference is in androidx package.

If the enum is not accessed through reflection, you can obfuscate it.

I’m not sure if I understand this fully. But I removed the keep rules for static methods values() and valueOf(String) (those mentioned here) and now the enum name gets obfuscated. But it’s still retained in a static initialization block like this (decompiled using jadx):

public final class a extends Enum<a> {
    public static final a a;

    private a(String str) {
    }

    static {
        a aVar = new a("ENUM_NAME");
        a = aVar;
        new a[1][0] = aVar;
    }

    ...
}

I can share the configuration file or the whole test project if needed.

Thank you very much for the response.