第一步 :android
咱們使用gradle添加依賴關係和插件:git
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() mavenCentral() maven { url 'https://github.com/Archinamon/GradleAspectJ-Android/raw/master' } } dependencies { classpath 'com.android.tools.build:gradle:1.5.0' classpath 'com.archinamon:AspectJ-gradle:1.1.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
apply plugin: 'com.android.application' apply plugin: 'com.archinamon.aspectj' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.sw.myapplication" minSdkVersion 8 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.1' compile 'com.android.support:support-v4:23.2.1' compile 'com.android.support:design:23.2.1' }
第二步:建立日誌切面:github
com.sw.myapplication.aspect; android.app.Application; android.app.NotificationManager; android.content.Context; android.support.v4.app.NotificationCompat; android.util.Log; com.sw.myapplication.R; ; ; ; LogAspect { () mainActivity() { } () onCreate() { } (pointcut = ) logAfterOnCreateOnMainActivity() { Log.(,); } }