Phantom — 独一无二的零 Hook 稳定占坑类 Android 热更新插件化方案
Phantom 是满帮集团开源的一套稳定、灵活、兼容性好的 Android 插件化方案。
AndroidManifest.xml 中预埋组件),即可支持插件新增组件,甚至新增插件| 特性 | Atlas | Small | VirtualAPK | RePlugin | Phantom |
|---|---|---|---|---|---|
| Hook 数量 | 较多 | 较少 | 较少 | 仅一处 | 零 |
| 四大组件 | 全支持 | 只支持 Activity |
全支持 | 全支持 | 除 ContentProvider 外,全支持 |
| 剔除公共库 | 支持 | 支持 | 支持 | 不支持 | 支持 |
| 兼容性适配 | 高 | 高 | 高 | 高 | 非常高 |
| 插件热更新 | 不支持 | 不支持 | 不支持 | 不支持 | 支持 |
| 插件快速部署 | 不支持 | 不支持 | 不支持 | 支持 | 支持 |
| 插件宿主通信 | 一般 | 一般 | 弱 | 一般 | 强 |
在宿主项目根目录下的 build.gradle 中增加宿主 gradle 依赖
buildscript {
dependencies {
classpath 'com.wlqq.phantom:phantom-host-gradle:3.1.2'
}
}在宿主工程 Application 模块的 build.gradle 中增加宿主 library 依赖,并应用宿主 gradle 依赖包含的 gradle 插件 com.wlqq.phantom.host
dependencies {
compile 'com.wlqq.phantom:phantom-host-lib:3.1.3'
}
apply plugin: 'com.wlqq.phantom.host'在宿主工程 Application 模块中的 Application#onCreate() 方法中初始化 Phantom
public class YourApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
PhantomCore.getInstance().init(this, new PhantomCore.Config());
}
}// 安装打包到宿主 assets 中 plugins 目录下的插件
InstallResult ret = PhantomCore.getInstance().installPluginFromAssets("plugins/com.wlqq.phantom.pluign.component_1.0.0.apk");
// 插件安装成功后启动插件(执行插件的 Application#onCreate 方法)
if (ret.isSuccess() && ret.plugin.start()) {
Intent intent = new Intent();
// 指定插件 Activity 所在的插件包名以及 Activity 类名
intent.setClassName("com.wlqq.phantom.pluign.component", "com.wlqq.phantom.pluign.component.MainActivity");
PhantomCore.getInstance().startActivity(this, intent);
}在插件项目根目录下的 build.gradle 中增加插件 gradle 依赖
buildscript {
dependencies {
classpath 'com.wlqq.phantom:phantom-plugin-gradle:3.1.2'
}
}在插件项目 Application 模块的 build.gradle 中增加插件 library 依赖,并应用宿主 gradle 依赖包含的 gradle 插件 com.wlqq.phantom.plugin
…AndroidManifest.xml 中申明对宿主 Phantom 插件框架最低版本依赖<meta-data
android:name="phantom.service.import.PhantomVersionService"
android:value="30000"/>与编译独立 APK 相同,如:
./gradlew assembleDebug./gradlew assembleRelease插件端使用的 Gradle 插件会自动为项目的 variant 生成相应的插件安装 task ,格式为 phInstallPlugin${variant} ,例如:
./gradlew phInstallPluginDebug./gradlew phInstallPluginRelease如果你在使用过程中遇到问题,或者有好的建议,欢迎给我们提 issue 或 Pull Request。详细说明请移步 贡献指南
临时交流 QQ 群号:690051836
Apache License 2.0, part MIT. See the LICENSE file for details.
参考以及使用的开源项目
| 项目名称 | 开源协议 | 说明 |
|---|---|---|
| Maven | Apache License | 依赖库版本比较 |
| jsemver | MIT License | 依赖库版本比较 |
| Atlas | Apache License | 首次加载插件提速 jar 包及 so 库 |
| RePlugin | Apache License | Gradle Plugin 快速部署插件到宿主 反射工具类 ReflectUtils |
| VirtualApk | Apache License | 构建 Gradle Plugin 对 Gradle 4.x + Android Gradle Plugin 3.x 的兼容处理 |
暂无开放 Issues,或尚未同步最近议题。