Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard does not remove certain classes

Tags:

scala

proguard

All

I am using proguard to obfuscate a scala application.

At this point I am using very little of the scala-library, but still my jar is ~300KB, 99% of it are scala-library classes.

Using the -whyareyoukeeping option, I see that it keeps any class that overrides java.lang.Object methods, such as "toString" or "equals". For example

scala.Some
  is invoked by    scala.Some.equals (300:300)
  implements       java.lang.Object.equals
  is a library method.

And so scala.Some class is kept although I am not using it in my code.

Is there anyway to fix this, so that I only keep the classes I am actually using in my code?

Thanks Amir

like image 662
Amir Tuval Avatar asked Nov 11 '22 21:11

Amir Tuval


1 Answers

ProGuard's answer to -whyareyoukeeping sometimes contains a circular reasoning, unfortunately. The shrinking operation is correct though. The class is not preserved because it overrides equals(), but because it is actually referenced by some other class that is required. You may get a better impression by querying other classes.

Even a small piece of Scala can drag in a lot of basic classes due to transitive dependencies (often surprising at first sight). A final size of 300k doesn't seem out of the ordinary, compared to the original size of many megabytes.

like image 73
Eric Lafortune Avatar answered Nov 15 '22 07:11

Eric Lafortune