views:

277

answers:

2

hello, i am optimizing a jar with proguard, but it crashes after optimization. here is my proguard task:

    <proguard>
        -injars     ${dist}/${jarname}
        -outjars    ${dist}-proguard/${jarname}

        -target 5

        -libraryjars '${java.home}/lib/rt.jar'

        -dontobfuscate            
        -optimizationpasses 4
        -overloadaggressively
        -repackageclasses ''
        -allowaccessmodification

        -keep public class * {
            public static void main(java.lang.String[]);
        }
    </proguard>

as soon as i put in the -dontoptimize option, it works.

according to the stack of the exception it crashes when accessing a static public member of a class with a nullpointer. here is the code:

public static Texture ring, dust, spikering, thinring, crystal, clouds;

public static void init() {
 Field [] fields = TexturePool.class.getDeclaredFields();

 for (Field field : fields) {
  if(field.getType() == Texture.class) {
   field.set( null, /*imagine new object here*/ );
  }
 }
}

thanks!

+1  A: 

According to http://stackoverflow.com/questions/93290/best-java-obfuscation-application-for-size-reduction:

"I was always able to fix the problem by not using the Proguard argument "-overloadaggressively"."

Perhaps you should try the same?


EDIT: The problem could easily be that an assignment is optimized away. The initializations happening in the source code, where a field is defined, is actually done by the compiler in a static code blokc. Appears that the optimizations tinker with that. What happens with fewer optimization passes?

Thorbjørn Ravn Andersen
thanks, but even if i dont put the overloadaggressively option, i get the same crash.
clamp
Lovely. Time to tweak options one at a time. You _must_ obfuscate?
Thorbjørn Ravn Andersen
thanks! well, only when i specify 0 optimization passes, it works: -optimizationpasses 0
clamp
@Thorbjorn: it is not obfuscation, but optimization (in proguard there is a difference!)
clamp
matt, I read the snippet wrong, and as "--obfuscate" where you had the opposite.
Thorbjørn Ravn Andersen
+1  A: 

ok, i just found out myself. i think the optimization completely optimized that classmembers away, since they are not directly accessed in this class. if i specify the option:

        -keepclassmembers public class com.package.** {
         public static * ;
        }

it works even with optimization.

clamp