Skip to content
/ jaop Public
forked from ltshddx/jaop

jaop is a gradle plugin base on javassist&asm for android aop

License

Notifications You must be signed in to change notification settings

GothicFox/jaop

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jaop

jaop 是一个基于javassist和asm的gradle aop插件,可以在特定的方法调用处或方法体内 编程
javassist做简单的代码插入,asm做操作数栈分析和字节码的转录
不会新增任何方法,秒杀aspectj
兼容性更好
不支持instant run

配置

repositories {
  jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0' // 需要1.5及以上的plugin
    classpath 'jaop.gradle.plugin:gradle-plugin:1.0.4'
}

apply plugin: 'jaop'

用法

@Jaop  //配置文件的开关
public class JaopDemo {
    @After("demo.jaop.sample.MainActivity.onCreate")  // hook 掉onCreate 方法的方法体
    public void replace1(MethodBodyHook hook) {
        Button button = (Button) ((Activity) hook.getTarget()).findViewById(R.id.button);
        button.setText("text replace by jaop");
    }

    @Replace("android.widget.Toast.makeText") // hook Toast makeText 方法的调用处, 替换toast的文本
    public void replace2(MethodCallHook hook) {
        Object[] args = hook.getArgs();
        hook.setResult(Toast.makeText((Context)args[0], "hook toast", Toast.LENGTH_LONG)); // 设置返回值
    }
}

详情请看sample

About

jaop is a gradle plugin base on javassist&asm for android aop

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 66.6%
  • Groovy 33.4%