当前位置: 首页 > 工具软件 > Dexposed > 使用案例 >

Dexposed实现热修复

钱华晖
2023-12-01

AndroLua开源项目:https://github.com/mkottman/AndroLua
阿里dexposed基于AOP思想:https://github.com/alibaba/dexposed
原理:
https://blog.csdn.net/yueqian_scut/article/details/50939034
https://blog.csdn.net/hgfujffg/article/details/87883068
使用:
1.引入依赖

implementation 'com.taobao.android:dexposed:0.1.1'


2.application的onCreate方法中添加:

if (DexposedBridge.canDexposed(this)) {
    // Use Dexposed to kick off AOP stuffs.
}


3.在要使用的activity中,判断是否支持dexposed

private boolean mIsSupported = DexposedBridge.canDexposed(this);

private boolean mIsLDevice = Build.VERSION.SDK_INT >= 21;


4.三种使用办法

if (mIsLDevice && mIsSupported) {
    //can dexposed or not
    //在方法前后执行逻辑
    DexposedBridge.findAndHookMethod(Activity.class, "test", new XC_MethodHook() {
        @Override
        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
            System.out.println("beforeHookedMethod test()");
        }

        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            System.out.println("afterHookedMethod test()");
        }
    });
    //直接替换整个方法
    DexposedBridge.findAndHookMethod(Activity.class, "test", new XC_MethodReplacement() {

        @Override
        protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
            System.out.println("replaceHookedMethod test()");
            return null;
        }
    });
}


 
 
 
 
 

 类似资料: