From cfb82ad8c8014ae3071333f86973c78ca1abddff Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Wed, 18 Mar 2020 21:05:54 -0700 Subject: [PATCH] Fix the broken export of layout plugin in android(not easily reproducible) Summary: There was a bug reported recently where the fetching all the nodes failed and the error is pasted [here](https://our.intern.facebook.com/intern/paste/P127476330/). From the paste we can see this `android.content.res.Resources$NotFoundException: Unable to find resource ID #0x0`. Reported bug is [here](https://fb.workplace.com/groups/flippersupport/permalink/830359447444715/) I was able to repro this luckily {F231474948} Reviewed By: xiphirx Differential Revision: D20441839 fbshipit-source-id: 9e9bfd15422c0f6c6f7a71aa22e9b1c8d640ec4a --- .../utils/ContextDescriptorUtils.java | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/android/src/main/java/com/facebook/flipper/plugins/inspector/descriptors/utils/ContextDescriptorUtils.java b/android/src/main/java/com/facebook/flipper/plugins/inspector/descriptors/utils/ContextDescriptorUtils.java index 8f6d6efae..f2b036d17 100644 --- a/android/src/main/java/com/facebook/flipper/plugins/inspector/descriptors/utils/ContextDescriptorUtils.java +++ b/android/src/main/java/com/facebook/flipper/plugins/inspector/descriptors/utils/ContextDescriptorUtils.java @@ -51,23 +51,29 @@ public final class ContextDescriptorUtils { || sThemeImplThemeKeyField == null || sThemeKeyResIdField == null || sThemeImplAssetManagerField == null) { - sThemeImplField = theme.getClass().getDeclaredField("mThemeImpl"); - sThemeImplField.setAccessible(true); - themeImpl = sThemeImplField.get(theme); - sThemeImplThemeKeyField = themeImpl.getClass().getDeclaredField("mKey"); - sThemeImplThemeKeyField.setAccessible(true); + // Early exiting as this bit of code causes too much of the metadata to be created and + // ultimately leads to out of memory exception. Reference D20441839 + // sThemeImplField = theme.getClass().getDeclaredField("mThemeImpl"); + // sThemeImplField.setAccessible(true); - sThemeImplAssetManagerField = themeImpl.getClass().getDeclaredField("mAssets"); - sThemeImplAssetManagerField.setAccessible(true); + // themeImpl = sThemeImplField.get(theme); + // sThemeImplThemeKeyField = themeImpl.getClass().getDeclaredField("mKey"); + // sThemeImplThemeKeyField.setAccessible(true); - sAssetManagerGetStyleAttributesMethod = - assetManager.getClass().getDeclaredMethod("getStyleAttributes", int.class); - sAssetManagerGetStyleAttributesMethod.setAccessible(true); + // sThemeImplAssetManagerField = themeImpl.getClass().getDeclaredField("mAssets"); + // sThemeImplAssetManagerField.setAccessible(true); + + // sAssetManagerGetStyleAttributesMethod = + // assetManager.getClass().getDeclaredMethod("getStyleAttributes", int.class); + // sAssetManagerGetStyleAttributesMethod.setAccessible(true); + + // themeKey = sThemeImplThemeKeyField.get(themeImpl); + // sThemeKeyResIdField = themeKey.getClass().getDeclaredField("mResId"); + // sThemeKeyResIdField.setAccessible(true); + + return builderMap; - themeKey = sThemeImplThemeKeyField.get(themeImpl); - sThemeKeyResIdField = themeKey.getClass().getDeclaredField("mResId"); - sThemeKeyResIdField.setAccessible(true); } else { themeImpl = sThemeImplField.get(theme); themeKey = sThemeImplThemeKeyField.get(themeImpl); @@ -77,6 +83,9 @@ public final class ContextDescriptorUtils { TypedValue typedValue = new TypedValue(); Resources resources = context.getResources(); for (int themeId : appliedThemeResIds) { + if (themeId == 0) { + continue; + } String name = resources.getResourceName(themeId); // The res id array can have duplicates if (builderMap.containsKey(name)) {