本插件可实现AGP7.4+和AGP8下ARouter框架自动化插桩,使用方法和com.alibaba:arouter-register
完全一致,无缝替换;
插件发布在 ArouterPlugin ,点开即可查阅最全面的插件导入方式;
Koltin
Using the plugins DSL:
plugins {
id("io.github.JailedBird.ARouterPlugin") version "1.0.1"
}
Using legacy plugin application:
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath("io.github.JailedBird:arouter-gradle-plugin:1.0.1")
}
}
apply(plugin = "io.github.JailedBird.ARouterPlugin")
Grovvy
Using the plugins DSL:
plugins {
id "io.github.JailedBird.ARouterPlugin" version "1.0.1"
}
Using legacy plugin application:
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath "io.github.JailedBird:arouter-gradle-plugin:1.0.1"
}
}
apply plugin: "io.github.JailedBird.ARouterPlugin"
遍历注解处理器生成的路由信息,然后在loadRouterMap函数中插桩
override fun visitInsn(opcode: Int) {
// generate code before return
if (opcode in Opcodes.IRETURN..Opcodes.RETURN) {
targetList?.forEach { scanSetting ->
scanSetting.classList.forEach { name ->
val className = name.replace("/", ".")
mv.visitLdcInsn(className)// 类名
mv.visitMethodInsn(
Opcodes.INVOKESTATIC,
ScanSetting.GENERATE_TO_CLASS_NAME,
ScanSetting.REGISTER_METHOD_NAME,
"(Ljava/lang/String;)V",
false
)
}
}
}
super.visitInsn(opcode)
}
插桩后字节码如下:
.method public static loadRouterMap()V
.registers 1
.line 63
const/4 v0, 0x0
sput-boolean v0, Lcom/alibaba/android/arouter/core/LogisticsCenter;->registerByPlugin:Z
.line 68
const-string v0, "com.alibaba.android.arouter.routes.ARouter$$Root$$app"
invoke-static {v0}, Lcom/alibaba/android/arouter/core/LogisticsCenter;->register(Ljava/lang/String;)V
const-string v0, "com.alibaba.android.arouter.routes.ARouter$$Root$$arouterapi"
invoke-static {v0}, Lcom/alibaba/android/arouter/core/LogisticsCenter;->register(Ljava/lang/String;)V
const-string v0, "com.alibaba.android.arouter.routes.ARouter$$Providers$$app"
invoke-static {v0}, Lcom/alibaba/android/arouter/core/LogisticsCenter;->register(Ljava/lang/String;)V
const-string v0, "com.alibaba.android.arouter.routes.ARouter$$Providers$$arouterapi"
invoke-static {v0}, Lcom/alibaba/android/arouter/core/LogisticsCenter;->register(Ljava/lang/String;)V
return-void
.end method
相关文档见issue1,如果对您有帮助,请点亮star支持作者😘