1 说明

在Android中有时需要用到AOP编程的场景,aspectj是一个不错的选择。因此特此记录下

2 Android引入Aspectj

项目的build.gradle中引入如下配置

        //for AspectJ        classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.4'

需要切入的模块build.gradle如下配置

apply plugin: 'android-aspectjx' // apply plugin    //AspectJ    api 'org.aspectj:aspectjrt:1.8.9'

接下来就可以写要切的代码了,这里以Application为例

@Aspectpublic class PerformanceManager {    private static final String TAG = "PerformanceManager";    @Around("execution(* com.qiyei.android.AndroidApplication.on**(..))")    public void getAndroidApplicationTime(ProceedingJoinPoint joinPoint) {        Signature signature = joinPoint.getSignature();        long time = System.currentTimeMillis();        try {            joinPoint.proceed();        } catch (Throwable throwable) {            throwable.printStackTrace();        }        LogManager.i(TAG, "getAndroidApplicationTime " + signature.getName() + " cost " + (System.currentTimeMillis() - time) + " ms");    }    @Around("call(* com.qiyei.android.AndroidApplication.**(..))")    public void getApplicationTime(ProceedingJoinPoint joinPoint) {        Signature signature = joinPoint.getSignature();        long time = System.currentTimeMillis();        try {            joinPoint.proceed();        } catch (Throwable throwable) {            throwable.printStackTrace();        }        LogManager.i(TAG, "getApplicationTime " + signature.getName() + " cost " + (System.currentTimeMillis() - time) + " ms");    }}

基本配置完毕

更多相关文章

  1. mac 不识别 android samsung手机
  2. Ubuntu识别不到Android设备
  3. Android下USB Accessory的实现分析 (四)--- AOA上层分析
  4. 【Android】数据存储之Shared Preferences
  5. android studio怎么生成HttpClient????
  6. Activity切换动画无效(android:windowIsTranslucent)影响(androi
  7. 关于android真机测试(linux系统下)
  8. 使用SharedPreferences存储和读取数据
  9. android flutter 混合开发(配置篇)

随机推荐

  1. android 开发之Activity切换
  2. android xml布局中TextView文字居中方法
  3. android 之Dialog对话框(简易版)
  4. android之音乐播放器
  5. android:MotionEvent
  6. Android中使用SurfaceView视频播放器
  7. [置顶] 基于android2.3.5系统:开天辟地And
  8. Android(安卓)SDK r16 发布
  9. Android(安卓)Parcelable
  10. android手机端保存xml数据