如何使用android apectj
来源:互联网 发布:淘宝客的pid是什么 编辑:程序博客网 时间:2024/06/10 04:38
原文网址:
http://cund99.blogspot.com/2012/03/marrying-aspectj-to-android-code.html
Android-aspectj is a nice project that proves that AspectJ can be used with Android code, see http://code.google.com/p/android-aspectj. However the available code is a little outdated and the build file is rather complicated.
In this post I will show an improved solution so that we can build an Android App with or without AspectJ stuffs easily:
- "ant aop debug install", to compile and enable AspectJ
- "ant debug install", to have a clean compilation and install the app without AspectJ
Here are the steps you will do:
- download and install AspectJ from here: http://www.eclipse.org/aspectj/downloads.php, once downloaded, you should run the jar file to install AspectJ to your machine
- Copy the runtime lib: aspectjrt.jar from the AspectJ home to thelibs in your Android Project
- Add the following custom Ant code to your build.xml file (in case you dont have the file, just open the project in a Console, run "android update project -p .", the android tool will prepare the file for you)
<taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
<classpath>
<pathelement location="${aspectj.home}/lib/aspectjtools.jar" />
</classpath>
</taskdef>
<property name="aop.output" value="bin/aop" />
<target name="-post-compile">
<if condition="${aop.enabled}">
<then>
<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="config.lst" />
</argfiles>
<inpath>
<pathelement location="${out.classes.absolute.dir}" />
</inpath>
<classpath>
<pathelement location="${aspectj.home}/lib/aspectjrt.jar" />
<path refid="android.target.classpath" />
</classpath>
</iajc>
<move file="${out.classes.absolute.dir}" todir="${out.dir}/classes.old" />
<!-- remember to replace your package initial, e.g. com -->
<move file="${aop.output}/com" todir="${out.classes.absolute.dir}" />
<delete dir="${aop.output}" />
</then>
</if>
</target>
<target name="aop">
<property name="aop.enabled" value="true" />
</target>
If you look carefully into the build.xml file, you will see the target "-post-compile" is already there and commented. You should put the above code into that location. Remember to change the version-tag to custom so that your build file will not be overwritten by the android tool if you launch it again.
<!-- version-tag: custom -->
The build.xml file needs one external variable: aspectj.home, and you should put it in the local.properties file, like this:
aspectj.home=/home/programs/aspectj1.6
You can also specify parameters for iajc in the config.lst at the root of your project.
Now you write your aspect code and once you are done, you can build and install your project with or without aspect code by the flag aop:
- ant aop debug install
- ant debug install
You can download the example project at, http://code.google.com/p/android-aspectj, delete their build file, create a new build file and update local information with the android tool, and follow the above steps to have a quick try out.
0 0
- 如何使用android apectj
- Android DDMS如何使用
- Android DDMS如何使用?
- Android DDMS如何使用?
- Android DDMS如何使用?
- Android DDMS如何使用?
- Android DDMS如何使用?
- Android DDMS如何使用?
- Android DDMS如何使用?
- Android如何使用SQLiteOpenHelper
- Android DDMS如何使用?
- Android DDMS如何使用?
- Android如何使用API
- android 如何使用jni
- android如何使用数据库文件?
- Android DDMS如何使用?
- Android:如何使用addJavaScriptInterface
- Android DDMS如何使用
- 显示全部内容OR显示部分内容
- 好的句子
- OpenMIPS VHDL study学习笔记第一天 -- Feb 25
- 整理ajax笔记
- 解读Android 4.0 Camera原生应用程序的设计思路
- 如何使用android apectj
- 深圳Maker Faire创客市集:国内外创客组团来参展
- JQuery为元素添加样式
- Tftp
- c# 使用SendMessage向另一进程发送WM_COPYDATA消息通信
- HDOJ 1024 Max Sum Plus Plus -- 动态规划
- 【转载】Java语言中使用OpenMP
- 专访小恩爱CTO钟超:让数据决定创意功能的去留
- C# XMLDocument xmlns属性设置