Giter Club home page Giter Club logo

android-pluginmgr's Introduction

android-pluginmgr
dynamic load uninstalled apk
动态加载未安装APK

Change: experiment分支开始支持so

此框架使动态加载APK非常简单
只需要2分钟,您就可以学会它的用法:

你可以直接下载demo工程--PlugLoadDemo 再对照阅读下文

首先,添加jar包:
pluginmgr-xx.jar (可以下载源码,自己用maven build)
dexmaker-xx.jar (此时最新版为dexmaker-1.1.jar)
到您的app的libs目录

然后,在您App的 AndroidManifest.xml 文件中做两件事:
1、添加读写SD卡的权限:

<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  

2、注册一个Activity

<activity android:name="androidx.pluginmgr.PluginActivity" />

要想启动一个未安装的APK其中的Activity,您只需要掌握一个类,两个方法即可!
这个类就是androidx.pluginmgr.PluginManager
看代码:
第一步, 加载插件
PluginManager mgr = PluginManager.getInstance(Context);//传入您的context对象
// 第1个方法
mgr.loadPlugin(new File(您的插件路径));//加载,路径可以是单独一个apk,或者一个包含多个apk的目录
第二步,启动插件Activity
// 第2个方法
mgr.startActivity(context, new Intent().setComponentName(插件包名, Activity全类名)));
如果你只是想启动MainActivity, 只须: mgr.startMainActivity(context, 插件包名);

被加载的插件apk无须引入任何额外的依赖,也可以独立运行
怎么样,是不是很简单呢?


如果您感兴趣深入了解,请看下文,否则请return:

额外功能:

一个插件还可以启动另一个插件里的Activity,或宿主的Activity
插件可以使用宿主里的类,比如好几个插件都想调用宿主里的某个工具包里的类
,那么可以把这个包抽出成jar包,供插件依赖使用,插件如果不需要独立安装运行的话,
可以将这个jar包不要放在Android project 的 libs目录,而是change another directory,such as ‘mylib’

限制
1、插件apk里不要假定包名就是清单文件声明的包名,因为包名会在被加载后变成和宿主一样的包名
2、暂不支持插件的service, 未来将支持切换时间运行的service
3、不支持 activity 的 launch mode

关于作者:
email: [email protected]
blog: http://blog.csdn.net/hkxxx

许可

**本项目采用 Apache Licence 2.0 授权协议:
Apache Licence是著名的非盈利开源组织Apache采用的协议。该协议和BSD类似,同样鼓励代码共享和尊重原作者的著作权,同样允许代码修改
,再发布(作为开源或商业软件)更多...
Copyright (c) 2014, KJFrameForAndroid Open Source Project, Zhang Tao.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS
IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.

android-pluginmgr's People

Contributors

houkx avatar

Stargazers

 avatar

Watchers

 avatar

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.