Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Phantom — 唯一零 Hook 稳定占坑类 Android 热更新插件化方案

License

NotificationsYou must be signed in to change notification settings

ManbangGroup/Phantom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

licenseRelease VersionBuild Status

Phantom — 唯一零 Hook 稳定占坑类 Android 热更新插件化方案

Phantom 是满帮集团开源的一套稳定、灵活、兼容性好的 Android 插件化方案。

Phantom 的优势

  • 兼容性好: Hook,兼容 Android 4.0 ~ Android Q beta 4(final APIs)
  • 功能完整:插件支持独立应用的绝大部分特性
  • 稳定可靠:历经货车帮旗下多款产品 50+ 插件两年多千万级用户验证(稳定性和兼容性指标都在 4 个 9 以上)
  • 部署灵活:宿主无需升级(无需在宿主AndroidManifest.xml 中预埋组件),即可支持插件新增组件,甚至新增插件
  • 易于集成:无论插件端还是宿主端,只需『数行』就能完成接入,改造成本低

Phantom 与主流开源插件框架的对比

特性AtlasSmallVirtualAPKRePluginPhantom
Hook 数量较多较少较少仅一处
四大组件全支持只支持Activity全支持全支持ContentProvider 外,全支持
剔除公共库支持支持支持不支持支持
兼容性适配非常高
插件热更新不支持不支持不支持不支持支持
插件快速部署不支持不支持不支持支持支持
插件宿主通信一般一般一般

接入指南

宿主端

添加 Gradle 配置

在宿主项目根目录下的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'

初始化 Phantom 插件框架

在宿主工程 Application 模块中的Application#onCreate() 方法中初始化 Phantom

publicclassYourApplicationextendsApplication {@OverridepublicvoidonCreate() {super.onCreate();PhantomCore.getInstance().init(this,newPhantomCore.Config());    }}

安装内置到宿主 assets 中的插件 APK 并启动插件中的 Activity

// 安装打包到宿主 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);}

插件端

添加 Gradle 配置

在插件项目根目录下的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}

在插件AndroidManifest.xml 中申明对宿主 Phantom 插件框架最低版本依赖

<meta-dataandroid:name="phantom.service.import.PhantomVersionService"android:value="30000"/>

编译插件

与编译独立 APK 相同,如:

  • ./gradlew assembleDebug
  • ./gradlew assembleRelease

编译插件并将插件 APK 安装到宿主

插件端使用的 Gradle 插件会自动为项目的 variant 生成相应的插件安装 task ,格式为phInstallPlugin${variant} ,例如:

  • ./gradlew phInstallPluginDebug
  • ./gradlew phInstallPluginRelease

进阶指南

示例应用

联系我们

如果你在使用过程中遇到问题,或者有好的建议,欢迎给我们提issuePull Request。详细说明请移步贡献指南

临时交流 QQ 群号:690051836

项目作者

开源协议

Apache License 2.0, part MIT. See theLICENSE file for details.

致谢

参考以及使用的开源项目

项目名称开源协议说明
MavenApache License依赖库版本比较
jsemverMIT License依赖库版本比较
AtlasApache License首次加载插件提速 jar 包及 so 库
RePluginApache LicenseGradle Plugin 快速部署插件到宿主
反射工具类 ReflectUtils
VirtualApkApache License构建 Gradle Plugin 对 Gradle 4.x + Android Gradle Plugin 3.x 的兼容处理

About

Phantom — 唯一零 Hook 稳定占坑类 Android 热更新插件化方案

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp