ReInjectPlugin is an android build plugin. It uses ASM to modify classes without write duplicate code in many places. Inspired by xposed, the user just define original class and method, and write inject class and method, then the code will be injected to apk.
ReInjectPlugin is already published to mavenCenter, please add mavenCenter in your mvn config update root project's build.gradle
buildscript {
dependencies {
classpath 'io.github.nylon009:reinject-plugin:0.0.1'
}
}
update app/build.gradle
plugins {
id 'io.github.nylon009.reinject-plugin'
}
add ReInject.json file in the app project path: Please note the method for static and non static method are different in InjectUtil.java, for non static method, the inject function should use the origin class as the first parameter.
{
"injects": [
{
"className": "com.nylon.app.Utils",
"methodName": "foobar",
"methodSignature": "(Ljava/lang/String;)V",
"injectClassName": "com.nylon.app.InjectUtils",
"injectEnterMethodName": "foobarEnter",
"injectExitMethodName": "foobarExit"
},
{
"className": "com.nylon.app.Utils",
"methodName": "hello",
"methodSignature": "(Ljava/lang/String;)V",
"injectClassName": "com.nylon.app.InjectUtils",
"injectEnterMethodName": "helloEnter",
"injectExitMethodName": "helloExit"
}
]
}
original code: com.nylon.app.Utils
public static void foobar(String test) {
Log.d(TAG, "foobar");
}
after injected:
public static void foobar(String test) {
InjectUtils.foobarEnter(test); // this is injected by asm
Log.d(TAG, "foobar");
InjectUtils.foobarExit(test); // this is injected by asm
}
origin
public void hello(String msg) {
Log.d(TAG, "hello " + msg);
}
after injected
public void hello(String msg) {
InjectUtils.helloEnter(this, msg);
Log.d(TAG, "hello " + msg);
InjectUtils.helloExit(this, msg);
}
Update the Plugin module, change to snapshot version, and publish plugin to local repo directory
./gradlew :Plugin:assemble :Plugin:publishAllPublicationsToMyRepoRepository
this project already add local repo directory as maven center, so no need to change it. update the app/build.gradle to use snapshot version.