proguard icon indicating copy to clipboard operation
proguard copied to clipboard

Obfuscation fails when specifying target 1.8

Open xmariachi opened this issue 4 years ago • 1 comments

I am able to run this to obfuscate a jar-with-dependencies.

However, if I specify the target 1.8, I get the following error:

...
 [proguard]     java.lang.String describe(java.util.List,picocli.CommandLine) -> b
 [proguard]     java.lang.String quoteElements(java.util.List) -> b
 [proguard] Unexpected error while evaluating instruction:
 [proguard]   Class       = [org/a/o/h/a]
 [proguard]   Method      = [a(Lorg/a/o/p;Lorg/a/o/h/f;)Lorg/a/o/f/p;]
 [proguard]   Instruction = [306] aload v19
 [proguard]   Exception   = [java.lang.NullPointerException] (null)
 [proguard] Unexpected error while performing partial evaluation:
 [proguard]   Class       = [org/a/o/h/a]
 [proguard]   Method      = [a(Lorg/a/o/p;Lorg/a/o/h/f;)Lorg/a/o/f/p;]
 [proguard]   Exception   = [java.lang.NullPointerException] (null)
 [proguard] Unexpected error while preverifying:
 [proguard]   Class       = [org/a/o/h/a]
 [proguard]   Method      = [a(Lorg/a/o/p;Lorg/a/o/h/f;)Lorg/a/o/f/p;]
 [proguard]   Exception   = [java.lang.NullPointerException] (null)
 [proguard] Error: null
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:07 min

I'm doing it through the maven-proguard-plugin, which just calls the 7.1.0-beta3 in this case (cannot make it work with a newer version). POM:

<plugin>
        <groupId>com.github.wvengen</groupId>
        <artifactId>proguard-maven-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals><goal>proguard</goal></goals>
            <configuration>
              <injar>${project.build.finalName}-jar-with-dependencies.jar</injar> <!-- make sure to obfuscate the jar with dependencies -->
              <outjar>${project.build.finalName}-small.jar</outjar>
              <options>
                <option>-allowaccessmodification</option>
                <option>-dontoptimize</option>
                <option>-dontshrink</option>
                <option>-dontnote</option>
                <option>-target 1.8</option>
                <option>-printmapping</option>
                <option>-dontusemixedcaseclassnames</option>
                <option>-dontwarn</option> 
                <option>-keepattributes Signature</option>
                <option>-keep class mypackage.MyClass { *; }</option>
              </options>
              <libs>
                <lib>${java.home}\lib\rt.jar</lib>
              </libs>
            </configuration>
          </execution>
        </executions>
      </plugin>

Removing the <option>-target 1.8</option> will at least pass and generate an obfuscated jar (which has other problems when running it as a java -cp myjar-small.jar mypackage.MyClass , but that's another issue).

xmariachi avatar Aug 20 '21 09:08 xmariachi

You're specifying the option -dontwarn, but the warnings may have pointed to important problems about missing dependencies. Like a compiler, ProGuard needs all dependencies to process the code properly. Some suggestions:

  • The best solution: can you resolve the warnings by adding all of the missing dependencies?
  • If the input code worked properly because some classes or packages with missing dependencies remained unused anyway, can you filter out those unused classes classes from the input? You can find the original names in the obfuscation mapping (or temporarily just disable obfuscation with -dontobfuscate). You can remove them from the input jar or you can add a filter to -injars, e.g. -injars input.jar(!com/unused/**,!org/unused/**). I don't know the equivalent syntax for the Maven plugin.
  • With some luck, ProGuard's shrinking step may remove these classes for you, so you can try leaving out -dontshrink.

EricLafortune avatar Sep 13 '21 21:09 EricLafortune