Replugin是360开源的一款插件化框架,同样过多的资料就不在这展现了,github上有最完整的官网介绍。
github地址:https://github.com/DroidPluginTeam/DroidPlugin
project的gradle中加入:
classpath'com.qihoo360.replugin:replugin-host-gradle:2.2.1'
app的gradle中加入:
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.1' }
新建application继承RepluginApplication,并在Mainfest中加入。
或者重写Application的生命周期
public class MyApplication extends Application { public static int a = 1; @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); RePlugin.App.attachBaseContext(this); } @Override public void onCreate() { super.onCreate(); RePlugin.getConfig().setUseHostClassIfNotFound(true); RePlugin.App.onCreate(); RePlugin.enableDebugger(this, BuildConfig.DEBUG); // RePlugin.getConfig().setUseHostClassIfNotFound(true); } @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); } }
RePlugin.uninstall("plugin"); RePlugin.install(Environment.getExternalStorageDirectory().getAbsolutePath() + "/plugin.apk");
Intent intent = RePlugin.createIntent("插件名", "要跳转的activity的包名+名字"); RePlugin.startActivity(this, intent); //或者 RePlugin.startActivity(v.getContext(), new Intent(), "com.jumu.application", "com.jumu.activity.LoginActivity");
classpath 'com.qihoo360.replugin:replugin-plugin-gradle:2.2.1'
apply plugin: 'replugin-plugin-gradle' repluginPluginConfig { pluginName = "plugin_outer" hostApplicationId = "com.xiaoqi.replugindemo" hostAppLauncherActivity = "com.xiaoqi.replugindemo.MainActivity" } dependencies { compile 'com.qihoo360.replugin:replugin-plugin-lib:2.2.1' .... }这样其实就已经完成了插件的制作,只需生成apk即可。
private void initView() { mTv = (TextView) findViewById(R.id.tv); Class<Context> contextClass = (Class<Context>) RePlugin.getHostContext().getApplicationContext().getClass(); try { Field field = contextClass.getField("a"); int a = field.getInt(RePlugin.getHostContext().getApplicationContext()); mTv.setText("" + a); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }