Cannot run Jar file after obfuscate with proguard

Hi Guys! I am testing Proguard to apply for all Java project in my company. But after I run obfucate code my jar file cannot run as normal. Could you please help me to check. Here is the error I got:

Error: Could not find or load main class org.springframework.boot.loader.JarLauncher
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.loader.JarLauncher

And Here is the Configuration I used:

-verbose
-injars spring-boot-hello-world-example/target/spring-boot-hello-world-example-0.0.1-SNAPSHOT.jar
-outjars tuanna.jar

-dontskipnonpubliclibraryclasses
-printmapping mapping.txt
-ignorewarnings
-keep public class com.example.MyMain {
public static void main(java.lang.String[]);
}

Thanks in advance

Hi @tuanna2704 ,

A ClassNotFound exception occurs frequenstly when configuring ProGuard, you can find detailed explaination on the issue and solution in our troubleshooting guide, here: https://www.guardsquare.com/manual/troubleshooting/troubleshooting

A -keep option as shown below will fix it;
-keep class org.springframework.boot.loader.JarLauncher

You can make use of -addconfigurationdebugging to help you set up the necessary -keep rules for your project;

Best regards,

Jonas

Hi @jonas.gijbels! Thank you so much for taking a look into my issue. After I use this config:

-verbose
-injars       spring-boot-hello-world-example/target/spring-boot-hello-world-example-0.0.1-SNAPSHOT.jar
-outjars      tuanna.jar

-dontskipnonpubliclibraryclasses
-printmapping mapping.txt
-ignorewarnings
-keep class org.springframework.boot.loader.JarLauncher

I even cannot obfuscate code. Here is the error I got:

Unexpected error while performing partial evaluation:
  Class       = [org/springframework/boot/loader/Launcher]
  Method      = [createArchive()Lorg/springframework/boot/loader/archive/Archive;]
  Exception   = [java.lang.IllegalArgumentException] (Can't find common super class of [org/springframework/boot/loader/archive/JarFileArchive] (with 1 known super classes) and [org/springframework/boot/loader/archive/ExplodedArchive] (with 1 known super classes))
java.lang.RuntimeException: java.lang.IllegalArgumentException: Can't find common super class of [org/springframework/boot/loader/archive/JarFileArchive] (with 1 known super classes) and [org/springframework/boot/loader/archive/ExplodedArchive] (with 1 known super classes)
	at proguard.classfile.visitor.ParallelAllClassVisitor.visitClassPool(ParallelAllClassVisitor.java:126)
	at proguard.classfile.ClassPool.accept(ClassPool.java:111)
	at proguard.optimize.Optimizer$TimedClassPoolVisitor.visitClassPool(Optimizer.java:1716)
	at proguard.optimize.info.RepeatedClassPoolVisitor.visitClassPool(RepeatedClassPoolVisitor.java:78)
	at proguard.classfile.ClassPool.accept(ClassPool.java:111)
	at proguard.optimize.Optimizer.execute(Optimizer.java:530)
	at proguard.ProGuard.optimize(ProGuard.java:447)
	at proguard.ProGuard.execute(ProGuard.java:165)
	at proguard.ProGuard.main(ProGuard.java:594)
Caused by: java.lang.IllegalArgumentException: Can't find common super class of [org/springframework/boot/loader/archive/JarFileArchive] (with 1 known super classes) and [org/springframework/boot/loader/archive/ExplodedArchive] (with 1 known super classes)
	at proguard.evaluation.value.TypedReferenceValue.findCommonClass(TypedReferenceValue.java:527)
	at proguard.evaluation.value.TypedReferenceValue.generalize(TypedReferenceValue.java:320)
	at proguard.evaluation.value.TypedReferenceValue.generalize(TypedReferenceValue.java:225)
	at proguard.evaluation.value.TracedReferenceValue.generalize(TracedReferenceValue.java:276)
	at proguard.evaluation.value.TracedReferenceValue.generalize(TracedReferenceValue.java:163)
	at proguard.evaluation.value.ReferenceValue.generalize(ReferenceValue.java:354)
	at proguard.evaluation.Stack.generalize(Stack.java:143)
	at proguard.evaluation.TracedStack.generalize(TracedStack.java:149)
	at proguard.optimize.evaluation.PartialEvaluator.evaluateSingleInstructionBlock(PartialEvaluator.java:805)
	at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlock(PartialEvaluator.java:723)
	at proguard.optimize.evaluation.PartialEvaluator.evaluateInstructionBlockAndExceptionHandlers(PartialEvaluator.java:681)
	at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute0(PartialEvaluator.java:317)
	at proguard.optimize.evaluation.PartialEvaluator.visitCodeAttribute(PartialEvaluator.java:230)
	at proguard.classfile.attribute.visitor.MultiAttributeVisitor.visitCodeAttribute(MultiAttributeVisitor.java:278)
	at proguard.classfile.attribute.visitor.DebugAttributeVisitor.visitCodeAttribute(DebugAttributeVisitor.java:322)
	at proguard.classfile.attribute.CodeAttribute.accept(CodeAttribute.java:141)
	at proguard.classfile.ProgramMethod.attributesAccept(ProgramMethod.java:101)
	at proguard.classfile.attribute.visitor.AllAttributeVisitor.visitProgramMember(AllAttributeVisitor.java:95)
	at proguard.classfile.util.SimplifiedVisitor.visitProgramMethod(SimplifiedVisitor.java:93)
	at proguard.optimize.OptimizationInfoMemberFilter.visitProgramMethod(OptimizationInfoMemberFilter.java:99)
	at proguard.classfile.ProgramMethod.accept(ProgramMethod.java:93)
	at proguard.classfile.ProgramClass.methodsAccept(ProgramClass.java:588)
	at proguard.classfile.visitor.AllMethodVisitor.visitProgramClass(AllMethodVisitor.java:47)
	at proguard.classfile.ProgramClass.accept(ProgramClass.java:430)
	at proguard.classfile.visitor.ParallelAllClassVisitor$MyThreadedClassVisitor$1.run(ParallelAllClassVisitor.java:197)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:830)

Could you please guide me how to fix it? Thanks in advance.

@guardsquare-team Hi Team! could you please support me?

Hi @tuanna2704 ,

You don’t have any -libraryjars config which means that ProGuard has an incomplete class hierarchy. This will cause issues during optimization. ProGuard Manual: Troubleshooting | Guardsquare

You should add at least the Java rt.jar (Java < 9) or the jmods (Java >=9) as library jars, as well as any other compileOnly dependencies e.g. see this example proguard/applications.pro at master · Guardsquare/proguard · GitHub

The Gradle spring boot example here might also be helpful for you proguard/examples/spring-boot at master · Guardsquare/proguard · GitHub

Thanks,

James