views:

731

answers:

3

I'm using Antenna to build, pack and obfuscate a j2me app. Building and packing works fine.

The project uses a 3rd party jar that is already obfuscated except by some interfaces.

When trying to obfuscate I got several errors like:

[wtkobfuscate] Warning: i: can't find referenced class fooPackage.fooClass

Class i and fooPackage.fooClass is from this 3rd party jar that I mentioned.

UPDATE:

This 3rd party library uses j2me-xmlrpc.jar. If I don't package all together then I won't be able to obfuscate the 3rd party interfaces and the j2me-xmlrpc.jar. (and I can't run the app this way, not sure why)

If I package only the j2me-xmlrpc.jar and my project classes I get the this error while obfuscating

[wtkobfuscate] Warning: there were 2 instances of library classes depending on program classes.

UPDATE 2:

I know this obfuscation is possible beacause in Netbeans I can do obfuscation using Proguard.

Since Netbeans internals uses ANT to make builds I tried to copy the generated build.xml to my own build.xml.

For obfuscation Netbeans uses the library org-netbeans-modules-mobility-antext.jar that can be used outside Netbeans. I imported this library to my project and used it without problem.

But I get the same error I got using antenna.

Obfuscating in Netbeans generates a lot of warnings but it still generates the obfuscated jar.

What I'm missing?

+1  A: 

If the 3rd party library is obfuscated, don't include that library while you obfuscate your classes. Rather follow these steps

  1. Jar your classes alone (dont include 3rd party library)
  2. Obfuscate the jar obtained in step 1
  3. Unjar the obfuscated jar obtained in step 2 and the 3rd party library in some temp folder
  4. Jar all the unjared classes
  5. Preverify and package them again
Ram
The 3rd party library contains some interfaces that my classes use. If I don't include them a can't make the build and packaging. Is there a way I can split the obfuscated classes from the interfaces that are inside the jar?
Daniel Moura
Of course, you will include these 3rd party libraries in the classpath of the javac target while compiling, however when you package them, you do it differently as mentioned above, so that the obfuscator does not have problems in obfuscating the already obfuscated classes. Hope it is clear, if not, let me know
Ram
More clearly, the obfuscator does not obfuscate the 3rd party libraries again.
Ram
I need to obfuscate the interfaces inside the 3rd party library. The interfaces are inside a package while the already obfuscated classes are in the default package (no package).
Daniel Moura
A: 

try using jshrink. I have much better results with it then with proguard:

     <java jar="obfuscator\jshrink.exe" fork="true">
      <arg value="..\${projectdir}\${projectname}.jar"/>
      <arg value="-classpath"/>
      <arg pathref="project.class.path"/>
      <arg value="-keep"/>
      <arg value="${midletclass}"/>
      <arg value="-o"/>
      <arg value="..\${projectdir}\${projectname}.jar"/>
     </java>
Toad
if you give me your emailadres (or some other means of communication), I can send you jshrink so you can test with it
Toad
@reinier, or he can google it and find it there : http://lmgtfy.com/?q=Jshrink+
Antoine Claval
A: 

I was using Proguard 4.3. Downgrading to Proguard 4.2 solved the problem.

Daniel Moura