工程目录
宿主配置
apply plugin: 'com.android.application'
apply plugin: 'com.didi.virtualapk.host'
//***
dependencies{
implementation '***.huozhu:core:' + rootProject.ext.versions.core
implementation 'com.didi.virtualapk:core:0.9.8'
}
公共库配置
因为涉及到插件的下载加载以及之间的跳转 所以封装一个下载加载的公共类
dependencies{
implementation 'com.didi.virtualapk:core:0.9.8'
}
插件配置
apply plugin: 'com.didi.virtualapk.plugin'
virtualApk {
packageId = 0x75
targetHost = '../app'
applyHostMapping = true
forceUseHostDependences = true
}
插件中的gradle.properties
android.useDexArchive=false
项目配置
build.gradle中
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.didi.virtualapk:gradle:0.9.8.6'
}
}
插件加载并跳转
loadPlugin("plugin_mywallet", new LoadPlugin() {
@Override
public void plugin(LoadedPlugin plugin) {
startActivity(plugin.getLaunchIntent());
}
});
插件之间的跳转和传参
loadPlugin("plugin_orderlist", new LoadPlugin() {
@Override
public void plugin(LoadedPlugin loadedPlugin) {
try {
Intent intent = new Intent(context,Class.forName("***.plugin_orderlist.PluginOrderDetailsActivity"));
intent.putExtra("extra_orderid", orderCode);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
});
其他配置
基地址
基地址封装在公共库 并能够在宿主中修改,插件中之间调用基地址即可区分正式和开发环境
public static String BaseUrl = "https://tess.cisdom.com.cn/public/index.php/apient/";
public static String BaseDownload = "http://192.168.50.7/wx/";
public static void setBaseUrl(String baseUrl) {
BaseUrl = baseUrl;
}
public static void setBaseDownload(String baseDownload) {
BaseDownload = baseDownload;
}
公共库打包aar
见 https://blog.csdn.net/u013325929/article/details/50563571