Freeline是什么?
Freeline是蚂蚁金服旗下一站式理财平台蚂蚁聚宝团队15年10月在Android平台上的量身定做的一个基于动态替换的编译方案,5月阿里集团内部开源,稳定性方面:完善的基线对齐,进程级别异常隔离机制。性能方面:内部采用了类似Facebook的开源工具buck的多工程多任务并发思想:端口扫描,代码扫描,并发编译,并发dx,并发merge dex等策略,在多核机器上有明显加速效果,另外在class及dex,resources层面作了相应缓存策略,做到真正增量开发,另外引入并优化buck的部分加速组件dx,DexMerger,资源编译方面,深入改造了Aapt资源编译流程,当资源发生改变时候,秒级完成增量包编译,其中增量包仅含最小的变更集合(10Kb~数百Kb内),后期也被运用到线上进行资源/代码动态替换。相比目前instant-run,buck,layoutcast等方案快数倍速度。
使用教程
- 配置
project-build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.antfortune.freeline:gradle:0.8.6'
}
}
module’s build.gradle:
apply plugin: 'com.antfortune.freeline'
注:以上配置只是追加上去就行,不用把gradle相关的去除。
dependencies {
debugCompile 'com.antfortune.freeline:runtime:0.8.6'
releaseCompile 'com.antfortune.freeline:runtime-no-op:0.8.6'
testCompile 'com.antfortune.freeline:runtime-no-op:0.8.6'
}
android {
…
freeline {
hack true
productFlavor "znds"
autoDependency false
}
}
-
插件安装
studio中安装插件:Freeline Plugin。安装后工具栏,如图:
-
代码植入
Application中植入代码:
public void onCreate() {
FreelineCore.init(this);
super.onCreate();
…
}
之后,就可以运行项目了。