Search code examples
proguard

proguard-maven-plugin an external lib com.github.sarxos obfuscation


I am trying to obfuscate a simlpe java application with an external lib "webcam-capture" from "com.github.sarxos"

I import a class

import com.github.sarxos.webcam.Webcam;

And somwhere in application call a method

Webcam webcam = Webcam.getDefault();

Without obfuscating everything work well, but after obfuscating jar I have got runtime errors:

  Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/github/sarxos/webcam/Webcamat 
    mdr.apmik.a.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
     at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)....

Here proguard-maven-plugin from my pom.xml. I have set an option to skip an com.github.sarxos.webcam class obfuscation, but without success.

 <plugin>
    <groupId>com.github.wvengen</groupId>
    <artifactId>proguard-maven-plugin</artifactId>
    <version>2.0.8</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals><goal>proguard</goal></goals>
        <configuration>
          <injar>${project.build.finalName}-jar-with-dependencies.jar</injar> 

      <proguardVersion>5.2</proguardVersion>

      <options>
         <option>-allowaccessmodification</option>
        <option>-dontoptimize</option>
        <option>-dontshrink</option>
        <option>-dontnote</option>
        <!--   <option>-dontwarn</option>  added option to ignore com.sun missing classes -->
        <option>-keepattributes Signature</option>
        <option>-adaptclassstrings</option>
        <option>-keep public class mdr.apmik.App { public *; public static *; }</option>
        <!--   Exclude external lib -->              
        <option>-keep class com.github.sarxos.webcam.** { *; } </option>               
      </options>
      <libs>
        <lib>${java.home}/lib/rt.jar</lib>
      </libs>
    <dependencies>
        <dependency>
          <groupId>net.sf.proguard</groupId>
          <artifactId>proguard-base</artifactId>
          <version>5.2</version>
          <scope>runtime</scope>
        </dependency>
      </dependencies> 
    </configuration>
  </execution>
</executions>

My question is - is it possible to use Proguard with a library like that? If yes, how to configure Proguard for that?


Solution

  • Finally, I have found decision. Just ran obfuscation before assembly stage. I have inserted the Proguard plugin between the compiler plugin and the assembly plugin. Idea from Sharcoux

    How to assembly a project after using proguard-maven-plugin