Giter Club home page Giter Club logo

xplugin's Introduction

xPlugin

一. 介绍

Android消息化插件框架 利用消息最大化解耦, 使插件在启动时可异步加载, 提高应用启动效率. 目前所有接口通过Android API [19, 30] 各版本兼容测试.

特性:

  1. 资源共享: 可指定Runtime Module, 其他Module可使用其提供的类型和资源.
  2. 资源隔离: 每个插件模块尽量使用自己内部的类型和资源, 避免类型和资源冲突问题.
  3. 消息通信: 模块间通过消息通信实现相互调用, 最大化的解耦, 延迟加载依赖, 在模块被调用时加载(可设置自动异步加载依赖模块).
  4. 接近原生: 接近原生方式使用系统API, 部分限制及解决方法参考如下信息.
限制:
  • Activity: 不支持外部应用直接启动, 如有需要建议在宿主中注册 或 实现自定义Activity进行跳转.
  • Service: 不支持外部应用直接启动, 使用场景有限, 更新不频繁, 如有需要建议在宿主中注册.
  • Broadcast: 使用动态注册实现, 需要应用处于运行状态, 如需实现静态注册建议在宿主中注册.
  • ContentProvider: 不支持外部应用直接启动, 如有需要建议在宿主中注册.
  • 系统进程资源问题: Notification等需要系统进程加载应用内资源的情况, 建议由应用包装包接口供插件使用.
  • overridePendingTransition动画资源问题: 类似系统进程资源问题, 但可以在宿主中添加同名资源, 或通过 ActivityHelper#registerOverridePendingTransitionAnimId 设置映射关系, 框架将自动处理加载过程.

二. 软件架构

image

注意: Demo工程中main模块编译完成后会在runtime目录输出其他Module依赖的资源文件, 使得其他Module可以使用Runtime Module提供的类型和资源.

三. 常用接口

  1. PluginRuntime: 插件初始化入口类, 在Application初始化时使用.
  2. Installer: 插件安装及加载的工具类, 从这里可以获取已安装和已加载的插件的信息.
  3. PluginMsg: 插件消息, 插件之间通信.
  4. PluginEntry: 消息注册的入口, 类名约定: $packageName.PluginEntry 的形式; 为方便集成到对外sdk, 宿主的PluginEntry可通过初始化接口指定.
  5. Plugin: 宿主(Host)和子模块(Module)的父类, 通过 Plugin.getPlugin(插件中的类型或其实例) 可以获取对应插件的信息.

四. 初始化

  1. gradle添加依赖:
// 最低gradle编译插件版本要求 com.android.tools.build:gradle:4.0.0

// 宿主中
implementation 'org.xutils:xutils:3.9.0'
implementation 'org.xplugin:xplugin:1.3.10'
// 插件中
compileOnly 'org.xutils:xutils:3.9.0' // 可选
compileOnly 'org.xplugin:xplugin:1.3.10'
  1. 初始化接口示例: MyApplication
  2. 在宿主或插件中的Manifest中添加 dependence 信息, 框架将自动异步加载依赖的插件模块, 参考 AndroidManifest.xml
  3. gradle配置参考示例工程, 注意插件模块的 packageId >= 0x70, 但不要设置为 0x7F, 示例:
aaptOptions {
    // 使用小于0x80的packageId需要添加 '--allow-reserved-package-id'
    // additionalParameters '--allow-reserved-package-id', '--package-id', '0x72',
    additionalParameters '--package-id', '0x80'
}

五. 插件中使用 Activity

参考main工程的示例 更多信息

六. 插件中使用 Service

参考main工程的示例

七. 插件中使用 Broadcast

参考main工程的示例

八. 插件中使用 ContentProvider

参考main工程的示例

九. 插件间消息调用

参考示例代码中 PluginEntry 和 PluginMsg 的使用.

其他

示例工程编译:

  1. 清理编译缓存: ./gradlew clean
  2. 编译main模块: ./gradlew main:build
  3. 编译module1模块: ./gradlew module1:build
  4. 编译module2模块: ./gradlew module2:build

关于主题

Android API 28 以下系统不支持引用 Runtime Module 的主题, 包含主题的资源包需要以 implementation 依赖方式编译进入插件包.

styleable 反射获取问题

如有使用 Class.forName(packageName + ".R$styleable").getFields() 反射获取styleable资源的情况, 建议修改为 R.styleable.class.getFields() 方式反射获取, 兼容性会更好. 否则, 需要在插件编译时添加:

aaptOptions {
    additionalParameters '--java', 'src/main/java', '--custom-package', 'app_packageName'
}

xplugin's People

Contributors

wyouflf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

xplugin's Issues

怎样从 sdcard 安装插件

我希望在 app 运行中,用户点某一个按钮从服务器将一个插件下载并运行,可以实现这样的场景吗?

runtime module和插件module中都使用了Databinding, 会产生冲突

插件第一次调用DataBindingUtil.setContentView()时, 会初始化androidx.databinding.DataBinderMapperImpl对象,
但是runtime module中也有同样的类,于是就初始化了错误的类(不同的包名的DataBinderMapperImpl类),引发错误.

类似这种冲突有什么解决方案吗

加载插件中的 so文件 崩溃

java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/org.xplugin.demo.app/app_xpl_modules/org.xplugin.demo.module2/1/libares.so" is 32-bit instead of 64-bit
        at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
        at java.lang.System.loadLibrary(System.java:1657)

但是我单独安装这个插件APK是可以运行的,把他编成插件使用就报上面这个错误,巨佬有办法解决吗?

云测兼容性不佳,50%的崩溃率

首先谢谢您开源此框架,下面是我在云测的兼容性测试,看看是否能帮助您完善这个框架。

直接编译出demo的app,在testin云测平台标准测试100款机型,有50款机型monkey测试崩溃。

测试结果可通过下面的链接下载。

注意:app中的MainActivity的申请权限获取结果的时候,grantResults[0] 没有判断数组长度,会出现大面积的崩溃,下面的测试结果是已经解决了这个问题再次测试的,看了下日志主要是插件化的问题了,希望作者能够完善这个框架,加油!

https://testin-files-low.oss-cn-hangzhou.aliyuncs.com/compatibility/other/2020/11/9/5181487/1665555/d87943738ac84764b24dfcdddc6d7f4d.xls?filename=xPlugin(1.0)%E5%85%BC%E5%AE%B9%E6%B5%8B%E8%AF%95%E9%AA%8C%E6%94%B6%E6%8A%A5%E5%91%8A.xls

请教下如果想实现加载外部Service有啥思路不?

Service: 不支持外部应用直接启动, 使用场景有限, 更新不频繁, 如有需要建议在宿主中注册.
ContentProvider: 不支持外部应用直接启动, 如有需要建议在宿主中注册
请教一下,这两种有实现思路不?

无法正常编译

`AGPBI: {"kind":"error","text":"Android resource linking failed","sources":[{}],"original":"AAPT: ../runtime/org.xplugin.demo.module2.id.txt: error: failed reading stable ID file.\n\n ","tool":"AAPT"}

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':module2:processReleaseResources'.

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
Android resource linking failed
AAPT: ../runtime/org.xplugin.demo.module2.id.txt: error: failed reading stable ID file.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 11s`
AS中 Build-Build Apk失败。

另外,Demo中没有插件Apk 手动放到存储目录下,按button后手动安装加载的示列。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.