Skip to content

Commit bf71bcd

Browse files
committed
update creator for 5.x and 2.x
Signed-off-by: Cai Liming <405977146@163.com>
1 parent 93ab197 commit bf71bcd

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

PluginCore/src/com/plugin/core/PluginCreator.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,31 @@ public static Resources createPluginResource(Application application, String abs
6464
}
6565
return null;
6666
}
67+
68+
/*package*/ static Resources createPluginResourceFor5(Application application, String absolutePluginApkPath) {
69+
try {
70+
AssetManager assetMgr = AssetManager.class.newInstance();
71+
Method addAssetPaths = AssetManager.class.getDeclaredMethod("addAssetPaths", String[].class);
72+
73+
String[] assetPaths = new String[2];
74+
75+
//不可更改顺序否则不能兼容4.x
76+
assetPaths[0] = absolutePluginApkPath;
77+
assetPaths[1] = application.getApplicationInfo().sourceDir;
78+
79+
addAssetPaths.invoke(assetMgr, new Object[] { assetPaths });
80+
81+
Resources mainRes = application.getResources();
82+
Resources pluginRes = new Resources(assetMgr, mainRes.getDisplayMetrics(), mainRes.getConfiguration());
83+
84+
Log.e(LOG_TAG, "create Plugin Resource from: " + assetPaths[0] + ", " + assetPaths[1]);
85+
86+
return pluginRes;
87+
} catch (Exception e) {
88+
e.printStackTrace();
89+
}
90+
return null;
91+
}
6792

6893
/**
6994
* 创建插件apk的Context。

0 commit comments

Comments
 (0)