Tuesday, October 19, 2010

ProGuard obfuscation : error Could not load definitions from resource proguard/ant/task.properties

I've just tried to obfuscate my TrackSite app with ProGuard following Dan Galpin's instructions from Proguard, Android, and the Licensing Server.

I've encountered the « Could not load definitions from resource proguard/ant/task.properties » error during the ant release build :

compile:
[javac] /Users/raph/droid/android-sdk-mac/tools/ant/ant_rules_r3.xml:336: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 1 source file to /Users/raph/droid/workspace/TrackSites/bin/classes

-dex-obfuscate:
[taskdef] Could not load definitions from resource proguard/ant/task.properties. It could not be found.
[delete] Deleting: /Users/raph/droid/workspace/TrackSites/obf/original.jar
[jar] Building jar: /Users/raph/droid/workspace/TrackSites/obf/original.jar

BUILD FAILED



The add-proguard-release.xml provided with the Proguard, Android, and the Licensing Server contains the following definitions at lines 19 and 29

<property name="proguard-jar" value="${proguard.dir}/proguard.jar" />
...
<taskdef resource="proguard/ant/task.properties" classpath="${proguard-jar}" />


This refers to a task.properties file. According to the article Obfuscating Your MIDlet Suite from the Sun Developer Network (look for section « Ant Script ») this file is included into the proguard.jar jar file distributed with ProGuard, inside the .jar file.

Then, the solution is to update the property at line 19 to point to the real location of the proguard.jar archive, that is located in the lib/ sub-directory. So the property's value should be « value="${proguard.dir}/lib/proguard.jar" »

<property name="proguard-jar" value="${proguard.dir}/lib/proguard.jar" />


The ant release build then looks like :

compile:
[javac] /Users/raph/droid/android-sdk-mac/tools/ant/ant_rules_r3.xml:336: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 1 source file to /Users/raph/droid/workspace/TrackSites/bin/classes

-dex-obfuscate:
[delete] Deleting: /Users/raph/droid/workspace/TrackSites/obf/original.jar
[jar] Building jar: /Users/raph/droid/workspace/TrackSites/obf/original.jar
[proguard] ProGuard, version 4.5.1
[proguard] Reading input...
[proguard] Reading program jar [/Users/raph/droid/workspace/TrackSites/obf/original.jar]
[proguard] Reading library jar [/Users/raph/droid/android-sdk-mac/platforms/android-8/android.jar]
[proguard] Reading library directory [/Users/raph/droid/workspace/TrackSites/libs]
[proguard] Initializing...
[proguard] Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
[proguard] Note: there were 1 references to unknown classes.
[proguard] You should check your configuration for typos.
[proguard] Ignoring unused library classes...
...

3 comments:

a2b said...

Another resource about ProGuard How to obfuscate Java class files with ProGuard

Mikey said...

Thank you! You would think these guys would test a how-to before they post it!

a2b said...

Mickey,

They probably try to improve their process for the next time.