Skip to content

Commit 582f298

Browse files
committed
modify getResources().getIdentifier()
1 parent ad95d2d commit 582f298

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ public static DexClassLoader createPluginClassLoader(String absolutePluginApkPat
4848
* 插件apk文件路径
4949
* @return
5050
*/
51-
public static Resources createPluginResource(Application application, String absolutePluginApkPath,
52-
boolean isStandalone, String[] dependencies) {
51+
public static Resources createPluginResource(Application application, PluginDescriptor pluginDescriptor) {
52+
String absolutePluginApkPath = pluginDescriptor.getInstalledPath();
53+
boolean isStandalone = pluginDescriptor.isStandalone();
54+
String[] dependencies = pluginDescriptor.getDependencies();
55+
5356
try {
5457

5558
// 插件运行时可能会通过getActivityInfo等
@@ -67,7 +70,7 @@ public static Resources createPluginResource(Application application, String abs
6770

6871
Resources mainRes = application.getResources();
6972
Resources pluginRes = new PluginResourceWrapper(assetMgr, mainRes.getDisplayMetrics(),
70-
mainRes.getConfiguration());
73+
mainRes.getConfiguration(), pluginDescriptor);
7174

7275
return pluginRes;
7376
} catch (Exception e) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,7 @@ static void ensurePluginInited(PluginDescriptor pluginDescriptor) {
435435

436436
LogUtil.d("是否为独立插件", pluginDescriptor.isStandalone());
437437

438-
Resources pluginRes = PluginCreator.createPluginResource(sApplication, pluginDescriptor.getInstalledPath(),
439-
pluginDescriptor.isStandalone(), pluginDescriptor.getDependencies());
438+
Resources pluginRes = PluginCreator.createPluginResource(sApplication, pluginDescriptor);
440439

441440
pluginClassLoader = PluginCreator.createPluginClassLoader(pluginDescriptor.getInstalledPath(),
442441
pluginDescriptor.isStandalone(), pluginDescriptor.getDependencies());

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@
55
import android.content.res.Resources;
66
import android.util.DisplayMetrics;
77

8+
import com.plugin.content.PluginDescriptor;
9+
import com.plugin.util.LogUtil;
10+
811
/**
912
* 根据不同的rom,可能需要重写更多的方法,目前发现的几个机型的问题暂时只需要重写下面2个方法。
1013
* @author cailiming
1114
*
1215
*/
1316
public class PluginResourceWrapper extends Resources {
1417

18+
private PluginDescriptor mPluginDescriptor;
19+
1520
public PluginResourceWrapper(AssetManager assets, DisplayMetrics metrics,
16-
Configuration config) {
21+
Configuration config, PluginDescriptor pluginDescriptor) {
1722
super(assets, metrics, config);
23+
this.mPluginDescriptor = pluginDescriptor;
1824
}
1925

2026
@Override
@@ -56,6 +62,12 @@ private static boolean isMainResId(int resid) {
5662
//默认宿主的资源id以0x7f开头
5763
return resid>>24 == 0x7f;
5864
}
59-
65+
66+
@Override
67+
public int getIdentifier(String name, String defType, String defPackage) {
68+
LogUtil.e("packageName", defPackage, "重置为:", mPluginDescriptor.getPackageName());
69+
defPackage = mPluginDescriptor.getPackageName();
70+
return super.getIdentifier(name, defType, defPackage);
71+
}
6072
}
6173

0 commit comments

Comments
 (0)