Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] AspectJ and obfuscator

Hi,

I really have some big problems with writing an ant build file for an application using an AspectJ aspect. The application is a J2ME project and that's why I need an abfuscator. I am using proguard as obfuscator and since 3 days I am now trying to write an ant file for building my project. Cause I am relative new to writing ant-files by myself, maybe the solution of the problem is easy, but at the moment I don't see any way to solve my problem... So the problem is that I don't know which jars to include in the obfuscation process, cause when I try to start my application I always get an error that he cannon find class org/aspectj/lang/NoAspectBoundException. I tried several things, like including aspectjtools.jar and aspectjrt.jar in the obfuscation-process, but none has any positive results on building... I only get millions of warnings, when I do this. So here is my actual build-file (I am already using as compiler the ajc-compiler; as ant-task I am using iajc):

build.xml:
---------------
<project name="biginteger" default="dist" basedir="..">
 <property name="project" value="biginteger"/>
 <property name="WTK.dir"  value="C:\Programme\WTK21"/>
 <property name="MIDP.lib" value="${WTK.dir}\lib\midpapi20.jar"  />
 <property name="CLDC.lib" value="${WTK.dir}\lib\cldcapi11.jar" />

 <property name="jdk.home"     value="C:\java\j2sdk" />
 <property name="ajc.home"     value="C:\Programme\aspectj" />

 <!-- The following property is needed only for obufscate_proguard. -->
 <property name="proguard" value="c:\Programme\proguard\lib\proguard.jar"/>

<taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
   </taskdef>

 <path id="bootclasspath">
    <pathelement path="${MIDP.lib}"/>
    <pathelement path="${CLDC.lib}"/>
   </path>

 <!-- The following property is only needs for the "tools"
      and "jad" targets. -->
 <property name="ant" value="C:\Programme\apache_ant"/>

 <path id="ajc.classpath">
     <pathelement location="${ajc.home}/lib/aspectjrt.jar" />
     <pathelement location="${ajc.home}/lib/aspectjtools.jar" />
     <pathelement location="${ajc.home}/lib/aspectj-ant.jar" />
     <pathelement location="${jdk.home}/lib/tools.jar" />
 </path>

   <path id="app.classpath">
         <pathelement location="${CLDC.lib}" />
         <pathelement location="${MIDP.lib}" />
   </path>

   <path id="app.crypt">
         <pathelement location="../lib/midp_classes.zip" />
   </path>

 <property name="Aspect.lib" value="${ajc.home}/lib/aspectjrt.jar" />

 <!-- Runs the application in the emulator. -->
 <target name="run">
   <exec executable="${WTK.dir}/bin/emulator">
     <arg line="-classpath build/bin/${project}.jar"/>
     <arg line="-Xdescriptor build/bin/${project}.jad"/>
   </exec>
 </target>

 <!-- Adjusts the JAR size in the JAD. -->
 <target name="jad" depends="dist">
   <taskdef name="jad" classname="JarSizeFix"/>
   <jad jar="build/bin/${project}.jar" jad="build/bin/${project}.jad"/>
 </target>

 <!-- Packages the application -->
 <target name="dist" depends="preverify">
   <mkdir dir="build/bin"/>
   <jar basedir="build/preverified"
       jarfile="build/bin/${project}.jar"
       manifest="MANIFEST.MF">
   </jar>
   <copy file="${project}.jad"
       tofile="build/bin/${project}.jad"/>
 </target>

 <!--
   This target runs the preverifier on the class files.

   Change 'depends' attribute here to select obfuscation:
     obfuscate_proguard
     obfuscate_retroguard
     obfuscate_null
 -->
 <target name="preverify" depends="obfuscate_proguard">
   <mkdir dir="build/preverified"/>
   <exec executable="${WTK.dir}/bin/preverify">
     <arg line="-classpath ${MIDP.lib};${CLDC.lib}"/>
     <arg line="-d build/preverified"/>
     <arg line="build/obfuscated"/>
   </exec>
 </target>

 <!-- Obufscates using ProGuard. -->
 <target name="obfuscate_proguard" depends="compile, copylib">
   <mkdir dir="build/proguard"/>
   <jar basedir="build/classes"
       jarfile="build/proguard/${project}-input.jar"/>

   <java fork="yes" classname="proguard.ProGuard"
       classpath="${proguard}">
     <arg line="-libraryjars ${MIDP.lib};${CLDC.lib}"/>
     <arg line="-injars build/proguard/${project}-input.jar"/>
     <arg line="-outjar build/proguard/${project}-output.jar"/>
<arg line="-keep 'public class * extends javax.microedition.midlet.MIDlet'"/>
     <arg line="-defaultpackage"/>
     <arg line="-dontusemixedcaseclassnames"/>
   </java>

   <mkdir dir="build/obfuscated"/>
   <unjar src="build/proguard/${project}-output.jar"
       dest="build/obfuscated"/>
 </target>

 <!-- Unjars the library APIs in preparation for obfuscation. -->
 <target name="copylib" depends="init">
   <unjar src="lib/midp_classes.zip" dest="build/classes"/>
 </target>

 <!-- Compiles the source code. -->
 <target name="compile" depends="init">
   <mkdir dir="build/classes"/>
       <iajc destdir="build/classes">
           <sourceroots>
        <pathelement location="src"/>
    </sourceroots>
       <classpath>
         <path refid="ajc.classpath"/>
         <path refid="app.classpath"/>
         <path refid="app.crypt"/>
       </classpath>

</iajc>
   </target>


 <!-- Builds the JarSizeFix Ant task and installs it
      in the Ant lib directory. -->
 <target name="tools">
   <mkdir dir="build/tools_classes"/>
   <javac destdir="build/tools_classes"
       srcdir="build/tools"
       target="1.1"/>
   <jar jarfile="${ant}/lib/wd-tools.jar">
     <fileset dir="build/tools_classes"/>
   </jar>
   <delete dir="build/tools_classes"/>
 </target>

 <target name="init">
   <tstamp/>
 </target>

</project>
-------------------------------------------------------

As result of starting this build.xml file with ant, I get the following result:
-----------------------------
Buildfile: build.xml

init:

compile:
   [mkdir] Created dir: D:\Programmierung\studi\biginteger\build\classes

copylib:
[unjar] Expanding: D:\Programmierung\studi\biginteger\lib\midp_classes.zip i
nto D:\Programmierung\studi\biginteger\build\classes

obfuscate_proguard:
   [mkdir] Created dir: D:\Programmierung\studi\biginteger\build\proguard
[jar] Building jar: D:\Programmierung\studi\biginteger\build\proguard\bigi
nteger-input.jar
    [java] ProGuard, version 3.2
    [java] Reading program jar [build/proguard/biginteger-input.jar]
    [java] Reading library jar [C:\Programme\WTK21\lib\midpapi20.jar]
    [java] Reading library jar [C:\Programme\WTK21\lib\cldcapi11.jar]
    [java] Preparing output jar [build/proguard/biginteger-output.jar]
[java] Copying resources from program jar [build/proguard/biginteger-input.
jar]
   [mkdir] Created dir: D:\Programmierung\studi\biginteger\build\obfuscated
[unjar] Expanding: D:\Programmierung\studi\biginteger\build\proguard\biginte
ger-output.jar into D:\Programmierung\studi\biginteger\build\obfuscated

preverify:
[mkdir] Created dir: D:\Programmierung\studi\biginteger\build\preverified
    [exec] Error preverifying class c
    [exec]     VERIFIER ERROR c.b()Lc;:
    [exec] Cannot find class org/aspectj/lang/NoAspectBoundException
    [exec] Result: 1

dist:
[jar] Building jar: D:\Programmierung\studi\biginteger\build\bin\bigintege
r.jar

jad:
     [jad] MIDlet-Jar-Size: 30230

BUILD SUCCESSFUL
-----------------------------------------

So the j2me preverifier tells me that he couldn't find the class: org/aspectj/lang/NoAspectBoundException

I really don't know how to solve the problem, so for any hints I would be sooooo thankful and happy, cause I am really getting depressed with this.

Thanks in advance,
Sebastian



Back to the top