Following post done a nice job at explaining how to introduce aspects in android world.
I gave it a try and it worked like a charm with some modifications. I have listed my modifications below just to save them safely. Two thumbs up for the original authors !
To make this work,
- I installed AspectJ 1.6 version and added "/Users/nehameht/aspectj1.6/bin" to my PATH.
- renamed all .properties files and build.xml file with .bk extensions to save their contents for later use.
- Executed "android update project" command to generate build.xml.
./android update project --name HelloWorld --target 8 --path /Users/nehameht/Downloads/android-aspectj
- Verified (and modified if needed) .properties files to point to my android sdk and AspectJ install locations
local.properties:
sdk.dir=/android-sdk-mac_86
build.properties:
aspectj.home=/Users/nehameht/aspectj1.6
default.properties:
target=Google Inc.:Google APIs:8
- Added following sections (whole XML nodes) from the saved build.xml.bk file to new generated build.xml.
<property name="aop.output" value="bin/aop"/>
<taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
<classpath>
<pathelement location="${aspectj.home}/lib/aspectjtools.jar"/>
</classpath>
</taskdef>
<property name="external.libs.dir" value="libs"/>
<property name="external.libs.absolute.dir" location="${external.libs.dir}"/>
<!-- extension targets. Uncomment the ones where you want to do custom work
in between standard targets -->
<!--
<target name="-pre-build">
</target>
<target name="-pre-compile">
</target>
[This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir}]
<target name="-post-compile">
</target>
-->
<target name="-post-compile">
<echo message="Weaving aspects to .class files before dex converts .class files to .dex file"/>
<iajc destDir="${aop.output}" Xlintwarnings="true" showWeaveInfo="true" target="1.5"
source="1.5">
<argfiles>
<pathelement location="trace.lst"/>
</argfiles>
<inpath>
<pathelement location="${out.classes.absolute.dir}"/>
</inpath>
<classpath>
<pathelement location="${aspectj.home}/lib/aspectjrt.jar"/>
<fileset dir="${external.libs.absolute.dir}" includes="*.jar"/>
<fileset dir="${extensible.libs.classpath}" includes="*.jar"/>
<path refid="android.target.classpath"/>
</classpath>
</iajc>
<move file="${out.classes.absolute.dir}" todir="bin/classes.old"/>
<move file="bin/aop/com" todir="bin/classes"/>
</target>
- After this "ant install" worked just fine. And I was able to verify the traces thru logcat.