1 官方资料

  滴滴开源Android插件方案:VirtualAPK

2 宿主App集成方法

  (1)在整个工程的build.gradle中添加依赖

dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.didi.virtualapk:gradle:0.9.8.4' // VirtualApk // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

  (2)在app模块(宿主App模块名,可改名)build.gradle添加插件引用

apply plugin: 'com.didi.virtualapk.host'    // VirtualApk  build.gradle文件顶部添加

  (3)在app模块build.gradle中添加依赖

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
compile 'com.didi.virtualapk:core:0.9.6' // VirtualApk
}

  (4)在Application的attachBaseContext中添加PluginManager初始化代码

import com.didi.virtualapk.PluginManager;

public class TestApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
long start = System.currentTimeMillis();
PluginManager.getInstance(base).init(); // 主要是这句
Log.d("KLH", "use time:" + (System.currentTimeMillis() - start));
}
}

  (5)在MainActivity的OnCreate中自动加载插件(这一步的时机可选,也可以是后续再加载),请注意这里加载插件的路径和apk名称,要约定好。

    private void loadPlugin() {
PluginManager pm = PluginManager.getInstance(this);
File apk = new File(Environment.getExternalStorageDirectory(), "test_plugin.apk");
if (apk.exists()) {
try {
pm.loadPlugin(apk);
showToast("插件加载成功!!!");
} catch (Exception e) {
e.printStackTrace();
showToast("插件加载异常了。。。");
}
}
}

  (6)启动插件Apk(这里以启动插件中的一个Activity为例)

Intent intent = new Intent();
intent.setClassName("com.klh.testplugin", "com.klh.testplugin.MainActivity");
startActivity(intent);

3 插件App集成方法

  插件工程是一个独立的App工程,只不过添加了VirtualAPK相关依赖,并且在编译时需要关联宿主工程目录(为了做一些信息同步与共享库删减)

  (1)在整个工程的build.gradle中添加依赖

dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.didi.virtualapk:gradle:0.9.8.4' // VirtualApk // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

  (2)在app模块的build.gradle中添加依赖

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
compile 'com.didi.virtualapk:core:0.9.6' // VirtualApk
}

  (3)在app模块的build.gradle文件末尾中添加插件配置

// VirtualApk
apply plugin: 'com.didi.virtualapk.plugin' virtualApk {
// 要指定一个不重复的ID来区分插件资源,有效值范围:[0x02, 0x7E]
packageId = 0x6a // the package id of Resources. // 宿主App的Application模块(绝对/相对)路径,插件的构建需要依赖此路径
targetHost = '../testAndroid/app' // the path of application module in host project. // 如果插件有引用宿主的类,那么此选项可以确保插件与宿主保持混淆一致
applyHostMapping = true //optional, default value: true.
}

  (4)编译方法:gradlew clean assemblePlugin

4 安装测试

  (1)安装宿主App

  (2)将编译好的插件改名与宿主约定一致,推送到指定目录。例如本文的约定路径是:/sdcard/test_plugin.apk

E:\VirtualShare\gitLab\research\05.VirtualApk\VATestPlugin>adb push app\build\outputs\apk\release\app-release-unsigned.apk /sdcard/test_plugin.apk
app\build\outputs\apk\release\app-release-unsigned.apk: 1 file pushed. 0.9 MB/s (27437 bytes in 0.030s)

5 其他

  插件不能直接访问宿主App的接口,可采用与宿主App集成相同的aar包来实现数据交互。

  

VirtualApk 插件入门小试的更多相关文章

  1. Uni-app原生插件入门使用教程「2」:如何离线使用原生插件

    当HBuilderX中提供的能力无法满足App功能需求,需要通过使用Andorid/iOS原生开发实现时,可使用App离线SDK开发原生插件来扩展原生能力. 如使用Uniapp开发直播功能时,需要调用 ...

  2. Unreal Engine 4(虚幻UE4) GameplayAbilities插件入门教程(一)

    本文系笔者的实习生分享会内容预备兼GameplayAbilities的初学者教程. 本文适合已有四十天UE4开发经验的初学者. 参考资料:https://wiki.unrealengine.com/G ...

  3. jQuery插件入门

    一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写("#"),("#"),("."),写了几年就对别人说非常熟悉JQ ...

  4. 关于jquery插件 入门

    关于 JavaScript & jQuery 的插件开发   最近在温故 JavaScript 的面向对象,于是乎再次翻开了<JavaScript高级程序设计>第3版,了解到其中常 ...

  5. 使用 ADD-ON SDK 开发 基于 Html JQuery 和 CSS 的 firefox 插件入门教程1: 创建一个简单的 Add-on

    [本文转载自http://sixpoint.me/942/implementing-simple-addon/] 实现一个简单的插件 教程的这个部分带你使用 SDK 来实现, 运行并打包一个插件. 这 ...

  6. jQuery 插件入门

    先看http://www.cnblogs.com/lideng/p/3605551.html http://www.cnblogs.com/xcj26/p/3345556.html (非常细致  很多 ...

  7. Unreal Engine 4 Radiant UI 插件入门教程(二)

    本篇章前提要求:在UE4上安装了Radiant UI插件.如果没有安装,请找其它教程(或者是笔者的其它的教程,目前正在写). 本教程的目的:探讨如何从网页元素中调用蓝图中的内容: 第一步: 写一个网页 ...

  8. Unreal Engine 4(虚幻UE4)GameplayAbilities 插件入门教程(三)技能标签(Ability Tags)

    本教程参考了https://wiki.unrealengine.com/GameplayAbilities_and_You,如果没有学习前两篇教程,请前往学习. GameplayAbilities插件 ...

  9. Unreal Engine 4(虚幻UE4)GameplayAbilities 插件入门教程(二)

    我们接着学习.如果没有学习第一篇,请前往学习. 由于GameplayAbilities插件基本上没有资料(除了前面提供的那篇Dave的博文以外,再无资料,有迹象表明Dave是这个插件的开发者). 这个 ...

随机推荐

  1. java HttpClient 忽略证书的信任的实现 MySSLProtocolSocketFactory

    当不需要任何证书访问https时,java中先实现一个MySSLProtocolSocketFactory类忽略证书的信任 package com.tgb.mq.producer.utils; imp ...

  2. 数据库between and

    在此记录一下,between相当于大于等于,and相当于小于,举个例子:select * from A where modefytime between '31-3月 -16' and '1-4月 - ...

  3. 运维chroot语法

    chroot命令 chroot命令用来在指定的根目录下运行指令.chroot,即 change root directory (更改 root 目录).在 linux 系统中,系统默认的目录结构都是以 ...

  4. Minimum Spanning Trees

    Kruskal’s algorithm always union the lightest link if two sets haven't been linked typedef struct { ...

  5. 今日bug:error: invalid array assignment

    错误代码: struct STUD { int ID;//学号 ]; float score; }stud; STUD SS[]; student.open("student.dat&quo ...

  6. 访问mysql出现Access denied for user 'root'@'的解决方法

    1.关闭mysql的服务 方法一:我的电脑右键-管理-服务和应用程序-服务,找到mysql,右键关闭 方法二:cmd进入命令提示符,service mysqld stop(这个是网上的方法,我试了一下 ...

  7. javascript 对象数组排序(按照科目级次)

    需求 从后台获取的数据是这样的                  上帝要这样的 背景 从后台获取到表格数据,然后填充到excel.当然是用js来填充的.js 本身的数组具有sort()功能.但是是针对 ...

  8. Linux批量复制文件到文件夹

    echo dirname* | xargs -n 1 cp -v filename 把当前目录下 filename文件拷贝到以dirname开头的不同文件夹里.

  9. 【EMV L2】2CS.001.00 ~ 2CS.007.00

    测试case要求,对于T=0和T=1卡,命令中是否存在Le是有差异的: - Select: Mandatory Command00 A4 04 00 Lc Command Data LeLc = 05 ...

  10. 最详细的 linux grep命令教程

    简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它 ...