赞
踩
一、系统资源加载
1、资源类别
2、Resources
(1)AssetManager
二、VirtualApk插件资源加载
资源插件化实现方式:
1、Resources创建
#LoadedPluginpublic LoadedPlugin(PluginManager pluginManager, Context context, File apk) throws Exception { ...... this.mResources = createResources(context, getPackageName(), apk); ......}protected Resources createResources(Context context, String packageName, File apk) throws Exception { if (Constants.COMBINE_RESOURCES) { //插件资源合并到宿主中,插件可访问宿主资源 return ResourcesManager.createResources(context, packageName, apk); } else { //插件创建独立的Resources,不与宿主关联 Resources hostResources = context.getResources(); AssetManager assetManager = createAssetManager(context, apk); return new Resources(assetManager, hostResources.getDisplayMetrics(), hostResources.getConfiguration()); }}
2、插件资源独立
主要通过反射创建新的AssetManager对象,通过addAssetPath加载插件资源。适用于资源独立的情况,无法调用宿主资源
protected AssetManager createAssetManager(Context context, File apk) throws Exception { //通过反射创建新的AssetManager对象,通过addAssetPath加载插件资源 AssetManager am = AssetManager.class.newInstance(); Reflector.with(am).method("addAssetPath
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。