-
-
Notifications
You must be signed in to change notification settings - Fork 97
集成指南
xuexiangjys edited this page Mar 23, 2022
·
4 revisions
1.先在项目根目录的 build.gradle
的 repositories 添加:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
2.再在项目根目录的 build.gradle
的 dependencies 添加xaop插件:
buildscript {
···
dependencies {
···
classpath 'com.github.xuexiangjys.XAOP:xaop-plugin:1.1.0'
}
}
3.然后在应用项目(一般是app)的 build.gradle
中增加依赖并引用xaop插件
apply plugin: 'com.xuexiang.xaop' //引用xaop插件
dependencies {
···
//如果是androidx项目,使用1.1.0版本及以上
implementation 'com.github.xuexiangjys.XAOP:xaop-runtime:1.1.0'
//如果是support项目,请使用1.0.5版本
implementation 'com.github.xuexiangjys.XAOP:xaop-runtime:1.0.5'
}
4.在Application
中进行初始化
XAOP.init(this); //初始化插件
XAOP.debug(true); //日志打印切片开启
XAOP.setPriority(Log.INFO); //设置日志打印的等级,默认为0
//设置动态申请权限切片 申请权限被拒绝的事件响应监听
XAOP.setOnPermissionDeniedListener(new PermissionUtils.OnPermissionDeniedListener() {
@Override
public void onDenied(List<String> permissionsDenied) {
//申请权限被拒绝的处理
}
});
//设置自定义拦截切片的处理拦截器
XAOP.setInterceptor(new Interceptor() {
@Override
public boolean intercept(int type, JoinPoint joinPoint) throws Throwable {
XLogger.d("正在进行拦截,拦截类型:" + type);
switch(type) {
case 1:
//做你想要的拦截
break;
case 2:
return true; //return true,直接拦截切片的执行
default:
break;
}
return false;
}
});
//设置自动捕获异常的处理者
XAOP.setIThrowableHandler(new IThrowableHandler() {
@Override
public Object handleThrowable(String flag, Throwable throwable) {
XLogger.d("捕获到异常,异常的flag:" + flag);
if (flag.equals(TRY_CATCH_KEY)) {
return 100;
}
return null;
}
});
1.在项目根目录的 build.gradle
的 dependencies 添加 aspectjx 插件:
buildscript {
···
dependencies {
···
classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10'
}
}
2.在应用项目(一般是app)的 build.gradle
中增加依赖并引用 aspectjx 插件
apply plugin: 'android-aspectjx' //引用aspectjx插件
aspectjx {
include '项目的applicationId'
}
详细使用可参见 kotlin-test 项目进行使用.
-keep @com.xuexiang.xaop.annotation.* class * {*;}
-keep @org.aspectj.lang.annotation.* class * {*;}
-keep class * {
@com.xuexiang.xaop.annotation.* <fields>;
@org.aspectj.lang.annotation.* <fields>;
}
-keepclassmembers class * {
@com.xuexiang.xaop.annotation.* <methods>;
@org.aspectj.lang.annotation.* <methods>;
}