Obfuscate jar and use the obfuscated jar in unobfuscated code

Hi, I have built an intelliJ plugin - say in Module A. I have my core code in Module B. Module B is a dependency of Module A. Now I just want to obfuscate Module B as it contains my business level code. I know I could just keep classes in Module B that are being used in Module A but that will make obfuscation useless for me as classes in Module B are being heavily used.

Is there a way to obfuscate Module A depending on mapping of Module B so that my code from Module A runs.

Dear @Ankush_Jangid ,

First of all, thanks for posting this question and welcome to our community!

If I understand correctly, Module B needs to be obfuscated but at the moment, if you run ProGuard on Module A and subsequently on Module B, too much gets obfuscated resulting in runtime issues? In case you still want to name obfuscate the classes, methods and fields in module B, I would recommend you to run ProGuard on Module B separately before you make it a dependency of Module A. You can then process Module A with ProGuard after you configured keep rules that will keep the - now obfuscated - class, method and fields names of Module B.

Kind regards,

Ewout

1 Like

Hi @ewoutd , thanks for the reply.

I tried to obfuscate module B first which gives me a mapping file. Then when I try to obfuscate A with this rule
–applyMapping mappingFromB.map

it doesn’t work.

BTW, I did get a workaround, I am running single obfuscation run with

-injars build/libs/moduleB.jar
-outjars build/libs/obfuscated-moduleB.jar
-injars build/libs/moduleA.jar
-outjars build/libs/obfuscated-moduleA.jar
-keep class moduleA**

The only issue I am facing now is module A is written in kotlin and the companion objects are being obfuscated and they fail at runtime.

I simply did -keep class moduleA** and then when I try to paste this jar into my main application, I get

java.lang.RuntimeException: java.lang.VerifyError: Expecting a stackmap frame at branch target 16

One thing to check: make sure you don’t have -dontpreverfiy in your configuration. Preverification is required to create the StackMap frames. See ProGuard Manual: Usage | Guardsquare

1 Like

@james Thanks, this was the issue for me. I am facing another issue now though, when I add library jars to the config, the proguard task fails as it runs out of memory. Is there any documentation available to increase proguard task heap?

Also is there a simpler way of adding all runtime library jars to the config file?

1 Like

The above questions are also fixed for me. Added
libraryjars(configurations.runtimeClassPath) in gradle proguard task which fixed the heap issue also for me while also adding runtime jars.

2 Likes