rovo89/XposedBridge

java.lang.NoSuchFieldError: android.content.res.XModuleResources#mCachedXmlBlockIds

Kyuuhachi opened this issue · 0 comments

I'm trying to modify an app's XML files (GBoard doesn't have enough obscure unicode characters), but it keeps giving the aforementioned error when loading the resource.

My module's source is this:

public class GBoard implements IXposedHookZygoteInit, IXposedHookInitPackageResources {
	private static String MODULE_PATH;
	
	@Override public void initZygote(StartupParam startupParam) throws Throwable {
		MODULE_PATH = startupParam.modulePath;
	}

	@Override public void handleInitPackageResources(XC_InitPackageResources.InitPackageResourcesParam resparam) {
		if (!resparam.packageName.equals("com.google.android.inputmethod.latin"))
			return;

		int id = resparam.res.getIdentifier("softkeys_input_en", "xml", "com.google.android.inputmethod.latin");
		XposedBridge.log(resparam.packageName + " " + id + " " + resparam.res.getXml(id));
		XModuleResources modRes = XModuleResources.createInstance(MODULE_PATH, resparam.res);
		Class c = modRes.getClass();
		while(c != Object.class && c != null) {
			XposedBridge.log(c + "");
			for(Object f : c.getDeclaredFields())
				XposedBridge.log("  " + f);
			c = c.getSuperclass();
		}
		resparam.res.setReplacement(id, modRes.fwd(R.xml.softkeys_input_en));
		XposedBridge.log(resparam.packageName + " " + id + " " + resparam.res.getXml(id));
	}
}

(I added some logs to confirm that mCachedXmlBlockIds indeed doesn't exist)

The log output is this:

07-12 12:01:42.167 I/Xposed  (14967): com.google.android.inputmethod.latin 2131298444 android.content.res.XmlBlock$Parser@7fc54d9
07-12 12:01:42.173 I/Xposed  (14967): class android.content.res.XModuleResources
07-12 12:01:42.173 I/Xposed  (14967): class android.content.res.Resources
07-12 12:01:42.173 I/Xposed  (14967):   final java.lang.ClassLoader android.content.res.Resources.mClassLoader
07-12 12:01:42.173 I/Xposed  (14967):   private android.graphics.drawable.DrawableInflater android.content.res.Resources.mDrawableInflater
07-12 12:01:42.173 I/Xposed  (14967):   private android.content.res.ResourcesImpl android.content.res.Resources.mResourcesImpl
07-12 12:01:42.173 I/Xposed  (14967):   private final java.util.ArrayList android.content.res.Resources.mThemeRefs
07-12 12:01:42.173 I/Xposed  (14967):   private android.util.TypedValue android.content.res.Resources.mTmpValue
07-12 12:01:42.173 I/Xposed  (14967):   private final java.lang.Object android.content.res.Resources.mTmpValueLock
07-12 12:01:42.173 I/Xposed  (14967):   final android.util.Pools$SynchronizedPool android.content.res.Resources.mTypedArrayPool
07-12 12:01:42.173 I/Xposed  (14967):   static final java.lang.String android.content.res.Resources.TAG
07-12 12:01:42.173 I/Xposed  (14967):   static android.content.res.Resources android.content.res.Resources.mSystem
07-12 12:01:42.173 I/Xposed  (14967):   private static final java.lang.Object android.content.res.Resources.sSync
07-12 12:01:42.174 E/Xposed  (14967): java.lang.NoSuchFieldError: android.content.res.XModuleResources#mCachedXmlBlockIds
07-12 12:01:42.174 E/Xposed  (14967): 	at de.robv.android.xposed.XposedHelpers.findField(XposedHelpers.java:116)
07-12 12:01:42.174 E/Xposed  (14967): 	at de.robv.android.xposed.XposedHelpers.getObjectField(XposedHelpers.java:894)
07-12 12:01:42.174 E/Xposed  (14967): 	at android.content.res.XResources.isXmlCached(XResources.java:1121)
07-12 12:01:42.174 E/Xposed  (14967): 	at android.content.res.XResources.getXml(XResources.java:1105)
07-12 12:01:42.174 E/Xposed  (14967): 	at c98.droid.tenaoshi.GBoard.handleInitPackageResources(GBoard.java:41)
07-12 12:01:42.174 E/Xposed  (14967): 	at de.robv.android.xposed.IXposedHookInitPackageResources$Wrapper.handleInitPackageResources(IXposedHookInitPackageResources.java:33)
07-12 12:01:42.174 E/Xposed  (14967): 	at de.robv.android.xposed.callbacks.XC_InitPackageResources.call(XC_InitPackageResources.java:55)
07-12 12:01:42.174 E/Xposed  (14967): 	at de.robv.android.xposed.callbacks.XCallback.callAll(XCallback.java:106)
07-12 12:01:42.174 E/Xposed  (14967): 	at de.robv.android.xposed.XposedInit.cloneToXResources(XposedInit.java:401)
07-12 12:01:42.174 E/Xposed  (14967): 	at de.robv.android.xposed.XposedInit.access$100(XposedInit.java:63)
07-12 12:01:42.174 E/Xposed  (14967): 	at de.robv.android.xposed.XposedInit$7.afterHookedMethod(XposedInit.java:285)
07-12 12:01:42.174 E/Xposed  (14967): 	at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:375)
07-12 12:01:42.174 E/Xposed  (14967): 	at android.app.ResourcesManager.getOrCreateResources(<Xposed>)
07-12 12:01:42.174 E/Xposed  (14967): 	at android.app.ResourcesManager.getResources(ResourcesManager.java:713)
07-12 12:01:42.174 E/Xposed  (14967): 	at android.app.LoadedApk.getResources(LoadedApk.java:951)
07-12 12:01:42.174 E/Xposed  (14967): 	at android.app.ContextImpl.createAppContext(ContextImpl.java:2270)
07-12 12:01:42.174 E/Xposed  (14967): 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5646)
07-12 12:01:42.174 E/Xposed  (14967): 	at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
07-12 12:01:42.174 E/Xposed  (14967): 	at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:361)
07-12 12:01:42.174 E/Xposed  (14967): 	at android.app.ActivityThread.handleBindApplication(<Xposed>)
07-12 12:01:42.174 E/Xposed  (14967): 	at android.app.ActivityThread.-wrap1(Unknown Source:0)
07-12 12:01:42.174 E/Xposed  (14967): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
07-12 12:01:42.174 E/Xposed  (14967): 	at android.os.Handler.dispatchMessage(Handler.java:106)
07-12 12:01:42.174 E/Xposed  (14967): 	at android.os.Looper.loop(Looper.java:164)
07-12 12:01:42.174 E/Xposed  (14967): 	at android.app.ActivityThread.main(ActivityThread.java:6501)
07-12 12:01:42.174 E/Xposed  (14967): 	at java.lang.reflect.Method.invoke(Native Method)
07-12 12:01:42.174 E/Xposed  (14967): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
07-12 12:01:42.174 E/Xposed  (14967): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
07-12 12:01:42.174 E/Xposed  (14967): 	at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:108)

As you can see, the resource loads just fine before being overridden, the field does indeed not exist, and it throws an error when trying to load it after overriding. The keyboard itself seems to be unaffected.

My guess is that there's some sort of API conflict between the versions of Xposed and Android I use, but I have no proof for this. Xposed version is 90-beta3, compiled for SDK 27, device TA-1004 (HMD Global), Android version 8.1.0 (SDK 27), ROM is 00WW_4_88C (vanilla, though not the latest update).

As a side note, is it possible to refer to other XML files and ids from my modified files? AAPT reasonably complains about them not existing when I try.