From 65d3167a802b2ca04d4f05ff972c2d51765f1e0d Mon Sep 17 00:00:00 2001 From: Marc Horowitz Date: Tue, 18 Feb 2020 12:24:07 -0800 Subject: [PATCH] If JSC fails to load when starting RN, expose that error to the caller Summary: See the comments for more info. Changelog: [Android] [Changed] - Improve exception message when JSC loading fails Reviewed By: tmikov Differential Revision: D19917034 fbshipit-source-id: d846f542c31e9c94edcee240c2935d77d48d1f2a --- .../react/ReactInstanceManagerBuilder.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java index 77b2e0f8cd43b1..e2809cd6580c68 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java @@ -297,8 +297,34 @@ private JavaScriptExecutorFactory getDefaultJSExecutorFactory( SoLoader.loadLibrary("jscexecutor"); return new JSCExecutorFactory(appName, deviceName); } catch (UnsatisfiedLinkError jscE) { + // https://github.com/facebook/hermes/issues/78 shows that + // people who aren't trying to use Hermes are having issues. + // https://github.com/facebook/react-native/issues/25923#issuecomment-554295179 + // includes the actual JSC error in at least one case. + // + // So, if "__cxa_bad_typeid" shows up in the jscE exception + // message, then we will assume that's the failure and just + // throw now. + + if (jscE.getMessage().contains("__cxa_bad_typeid")) { + throw jscE; + } + // Otherwise use Hermes - return new HermesExecutorFactory(); + try { + return new HermesExecutorFactory(); + } catch (UnsatisfiedLinkError hermesE) { + // If we get here, either this is a JSC build, and of course + // Hermes failed (since it's not in the APK), or it's a Hermes + // build, and Hermes had a problem. + + // We suspect this is a JSC issue (it's the default), so we + // will throw that exception, but we will print hermesE first, + // since it could be a Hermes issue and we don't want to + // swallow that. + hermesE.printStackTrace(); + throw jscE; + } } } }