移除ARouter.getInstance().inject(this);
的使用,减少反射
利用ASM
自动往使用了@Autowired
的Activity
或Fragment
的onCreate(Bundle)
方法块注入字节码
@Override
protected void onCreate(Bundle bundle) {
new MainFragment$$ARouter$$Autowired().inject(this); // 此行由插件自动生成
super.onCreate(bundle);
}
本插件已依赖bytex开发,可以直接依赖接入
// in root build.gradle
repositories {
maven {
url "https://dl.bintray.com/zyhang/maven"
}
}
dependencies {
classpath "maven.evilmouth.arouter:autowired-plugin:<latest-version>"
}
// in app build.gradle
apply plugin: 'com.zyhang.arouter.autowired_plugin'
AutowiredExtension {
enableInDebug true
}