I have runnable jar with couple of 3rd party jars inside it. Do I have to specify those libraries with Proguard’s -libraryjar option even if they are already packed in the main jar file?
At the moment I’m these errors:
Warning: there were 171 unresolved references to classes or interfaces.
Warning: there were 394 instances of library classes depending on program classes.
Warning: there were 1 unresolved references to program class members.
If I specify the jars with -libraryjar option Proguard warns alot about duplicate classes.
My ant build:
<target name="jar" depends="compile">
<delete file="${destfile}" />
<jar destfile="${destfile}" filesetmanifest="mergewithoutmain" duplicate="preserve">
<manifest>
<attribute name="Main-Class" value="main.Main"/>
<attribute name="Class-Path" value="${classpath}"/>
</manifest>
<fileset dir="${target}" includes="**/*.class" />
<zipfileset excludes="META-INF/*.SF" src="lib1.jar" />
<zipfileset excludes="META-INF/*.SF" src="lib2.jar" />
<zipfileset excludes="META-INF/*.SF" src="lib3.jar" />
</jar>
</target>
<target name="dist" depends="jar">
<taskdef resource="proguard/ant/task.properties" classpath="${proguard}" />
<proguard>
-injars ${destfile}
-outjars ${destfileobfuscated}
-libraryjars C:/Java/jdk1.6.0_25/jre/lib/rt.jar;
C:/Java/jdk1.6.0_25/jre/lib/jsse.jar;
C:/Java/jdk1.6.0_25/jre/lib/jce.jar;
lib1.jar;
lib2.jar;
lib3.jar
-optimizationpasses 5
-overloadaggressively
-repackageclasses ''
-allowaccessmodification
-dontskipnonpubliclibraryclassmembers
-keepclasseswithmembers public class * {
public static void main(java.lang.String[]);
}
</proguard>
<move file="${destfileobfuscated}" tofile="${destfile}" />
</target>
In
proguardyou must assign your 3rd party library jars with the following command:If you don’t include these jars as above, the code related to them will not be obfuscated/optimized/shrinked because they will be unresolved with respect to
proguard.It’s OK if it warns, because it will find a lot of classes with the same name, it’s normal, but this wont have any negative impacts on the outcome.