File tree 1 file changed +34
-0
lines changed
PluginCore/src/com/plugin/util 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
import com .plugin .core .PluginPublicXmlConst ;
6
6
7
+ import java .lang .reflect .InvocationTargetException ;
8
+ import java .lang .reflect .Method ;
9
+
7
10
/**
8
11
* Created by cailiming
9
12
*/
@@ -84,4 +87,35 @@ public static boolean isMainResId(int resid) {
84
87
//默认宿主的资源id以0x7f3X开头
85
88
return PluginPublicXmlConst .resourceMap .get (resid >>16 ) != null ;
86
89
}
90
+
91
+ public static void rewriteRValues (ClassLoader cl , String packageName , int id ) {
92
+ final Class <?> rClazz ;
93
+ try {
94
+ rClazz = cl .loadClass (packageName + ".R" );
95
+ } catch (ClassNotFoundException e ) {
96
+ LogUtil .d ("No resource references to update in package " + packageName );
97
+ return ;
98
+ }
99
+
100
+ final Method callback ;
101
+ try {
102
+ callback = rClazz .getMethod ("onResourcesLoaded" , int .class );
103
+ } catch (NoSuchMethodException e ) {
104
+ // No rewriting to be done.
105
+ return ;
106
+ }
107
+
108
+ Throwable cause ;
109
+ try {
110
+ callback .invoke (null , id );
111
+ return ;
112
+ } catch (IllegalAccessException e ) {
113
+ cause = e ;
114
+ } catch (InvocationTargetException e ) {
115
+ cause = e .getCause ();
116
+ }
117
+
118
+ throw new RuntimeException ("Failed to rewrite resource references for " + packageName ,
119
+ cause );
120
+ }
87
121
}
You can’t perform that action at this time.
0 commit comments