- Notifications
You must be signed in to change notification settings - Fork190
Phantom — 唯一零 Hook 稳定占坑类 Android 热更新插件化方案
License
ManbangGroup/Phantom
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Phantom 是满帮集团开源的一套稳定、灵活、兼容性好的 Android 插件化方案。
- 兼容性好:零 Hook,兼容 Android 4.0 ~ Android Q beta 4(final APIs)
- 功能完整:插件支持独立应用的绝大部分特性
- 稳定可靠:历经货车帮旗下多款产品 50+ 插件两年多千万级用户验证(稳定性和兼容性指标都在 4 个 9 以上)
- 部署灵活:宿主无需升级(无需在宿主
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'}applyplugin:'com.wlqq.phantom.host'在宿主工程 Application 模块中的Application#onCreate() 方法中初始化 Phantom
publicclassYourApplicationextendsApplication {@OverridepublicvoidonCreate() {super.onCreate();PhantomCore.getInstance().init(this,newPhantomCore.Config()); }}
// 安装打包到宿主 assets 中 plugins 目录下的插件InstallResultret =PhantomCore.getInstance().installPluginFromAssets("plugins/com.wlqq.phantom.pluign.component_1.0.0.apk");// 插件安装成功后启动插件(执行插件的 Application#onCreate 方法)if (ret.isSuccess() &&ret.plugin.start()) {Intentintent =newIntent();// 指定插件 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
android { buildTypes { release { minifyEnabledtrue proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'// Phantom 混淆配置文件 proguardFile'proguard-phantom.pro' } }}dependencies { provided'com.wlqq.phantom:phantom-plugin-lib:3.1.2' compile'com.android.support:support-v4:28.0.0'}applyplugin:'com.wlqq.phantom.plugin'phantomPluginConfig {// BEGIN 剔除公共库配置// 若插件中有使用 support-v4 ,则需要剔除掉(必须) excludeLib"com.android.support:support-v4:28.0.0"// END// BEGIN 生成插件额外的混淆配置文件,避免因剔除公共库引起的混淆问题 libraryJarsProguardFile file('proguard-phantom.pro')// END// BEGIN 快速部署插件配置// 宿主包名 hostApplicationId="com.wlqq.phantom.sample"// 宿主 launcher Activity full class name hostAppLauncherActivity="com.wlqq.phantom.sample.MainActivity"// 插件包名 pluginApplicationId= android.defaultConfig.applicationId// 插件版本名 pluginVersionName= android.defaultConfig.versionName// END}<meta-dataandroid: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
- 杨锋 - 核心开发者 -iceskyblue
- 邵彬 - 核心开发者 -shaobin0604
- 俞静波 - 主要贡献者 -CalmYu
Apache License 2.0, part MIT. See theLICENSE 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 的兼容处理 |
About
Phantom — 唯一零 Hook 稳定占坑类 Android 热更新插件化方案
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.