private static Context newDefaultAppContext(PluginDescriptor pluginDescriptor) { Context newContext = null; if (pluginDescriptor != null && pluginDescriptor.getPluginContext() != null) { Context originContext = pluginDescriptor.getPluginContext(); newContext = PluginCreator.createPluginContext( ((PluginContextTheme) originContext).getPluginDescriptor(), sApplication, originContext.getResources(), (DexClassLoader) originContext.getClassLoader()); newContext.setTheme(pluginDescriptor.getApplicationTheme()); } return newContext; }
/** * 构造插件信息 * * @param */ static void ensurePluginInited(PluginDescriptor pluginDescriptor) { if (pluginDescriptor != null) { DexClassLoader pluginClassLoader = pluginDescriptor.getPluginClassLoader(); if (pluginClassLoader == null) { LogUtil.e( "正在初始化插件" + pluginDescriptor.getPackageName() + "Resources, DexClassLoader, Context, Application"); LogUtil.d("是否为独立插件", pluginDescriptor.isStandalone()); Resources pluginRes = PluginCreator.createPluginResource(sApplication, pluginDescriptor); pluginClassLoader = PluginCreator.createPluginClassLoader( pluginDescriptor.getInstalledPath(), pluginDescriptor.isStandalone(), pluginDescriptor.getDependencies()); Context pluginContext = PluginCreator.createPluginContext( pluginDescriptor, sApplication, pluginRes, pluginClassLoader); // 插件Context默认主题设置为插件application主题 pluginContext.setTheme(pluginDescriptor.getApplicationTheme()); pluginDescriptor.setPluginContext(pluginContext); pluginDescriptor.setPluginClassLoader(pluginClassLoader); try { ActivityThread.installPackageInfo(getApplicatoin(), pluginDescriptor.getPackageName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } callPluginApplicationOnCreate(pluginDescriptor); LogUtil.e("初始化插件" + pluginDescriptor.getPackageName() + "完成"); } } }