RePlugin简介
RePlugin是一套完整的、稳定的、适合全面使用的实现插件化方案,由360手机卫士的RePlugin Team研发,是首个”全面插件化“(全面特性、全面兼容、全面使用)的方案。
主要优势:极其灵活、特性丰富、易于集成、管理成熟、数亿支撑
Replugin接入分三部分:
宿主的接入:这个主要是决定你要将那么module作为你的宿主,用于加载插件
插架的接入:这里可以新建一个module作为插件,也可以将现有的module(APK)改造为插件
插架化的使用:主要讲宿主和插件之间组件的通信,以及宿主和插件的调用等。
宿主接入步骤
根据官方的文档,如下宿主的接入分为三个步骤:
https://github.com/Qihoo360/RePlugin/wiki/%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B
第 1 步:添加 RePlugin Host Gradle 依赖
在项目根目录的 build.gradle中添加 replugin-host-gradle 依赖:
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.qihoo360.replugin:replugin-host-gradle:2.2.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
第 2 步:添加 RePlugin Host Library依赖
在 app/build.gradle 中应用 replugin-host-gradle 插件,并添加 replugin-host-lib 依赖:
apply plugin: 'replugin-host-gradle'
repluginHostConfig {
/*
* 是否使用 AppCompat 库
* 不需要个性化配置时,无需添加*/
useAppCompat = true
/*
* 背景不透明的坑的数量
不需要个性化配置时,无需添加*/
countNotTranslucentStandard = 6
countNotTranslucentSingleTop = 2
countNotTranslucentSingleTask = 3
countNotTranslucentSingleInstance = 2
}
dependencies {
compile 'com.qihoo360.replugin:replugin-host-lib:2.2.4'
}
第 3 步:配置 Application 类
public class BaseApp extends MultiDexApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
RePlugin.App.attachBaseContext(this);
}
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onCreate() {
super.onCreate();
RePlugin.App.onCreate();
}
@Override
public void onLowMemory() {
super.onLowMemory();
/* Not need to be called if your application's minSdkVersion > = 14 */
RePlugin.App.onLowMemory();
}
@Override
public void onTrimMemory(int level) {
super.onTrimMemory(level);
/* Not need to be called if your application's minSdkVersion > = 14 */
RePlugin.App.onTrimMemory(level);
}
@Override
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);
/* Not need to be called if your application's minSdkVersion > = 14 */
RePlugin.App.onConfigurationChanged(config);
}
}
插件接入步骤
第 1 步:添加 RePlugin Plugin Gradle 依赖
在项目根目录的 build.gradle 中添加 replugin-plugin-gradle 依赖:
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.qihoo360.replugin:replugin-host-gradle:2.2.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
第 2 步:添加 RePlugin Plugin Library 依赖
在 app/build.gradle 中应用 replugin-plugin-gradle 插件,并添加 replugin-plugin-lib 依赖:
apply plugin: 'replugin-plugin-gradle'
dependencies {
compile 'com.qihoo360.replugin:replugin-plugin-lib:2.2.4'
}
第3步: 配置插件的别名
<!--声明其插件别名-->
<meta-data
android:name="com.qihoo360.plugin.name"
android:value="appdemo" />
使用插架
Intent intent = RePlugin.createIntent("com.ltb.printtool", "com.ltb.printtool.view.FuncActivity");
String companyCode = (String) SPAllUtils.get(getActivity(), Constant.COMPANYCODE, Constant.NULL);
intent.putExtra("code",companyCode);
if (!RePlugin.startActivity(getActivity(), intent)) {
Toast.makeText(getContext(), "启动失败", Toast.LENGTH_LONG).show();
}