facebook/react-native

Android: ReactInstanceManagerBuilder.build fails unless SoLoader.init has been called

petterh opened this issue · 1 comments

Android: ReactInstanceManagerBuilder.build fails unless SoLoader.init has been explicitly called.

The ReactInstanceManager constructor calls initializeSoLoaderIfNecessary, so the intent is clearly that things should work without an explicit call to SoLoader.init on the part of the application. However, with the introduction of Hermes, we have ReactInstanceManagerBuilder.getDefaultJSExecutorFactory, which gets called before the ReactInstanceManager constructor. It attempts this:

SoLoader.loadLibrary("jscexecutor");

This fails. A simple fix is to ensure that the SoLoader is initialized first. I have a PR that fixes the issue.

React Native version:

System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Xeon(R) CPU E5-1620 v3 @ 3.50GHz
    Memory: 11.43 GB / 31.93 GB
  Binaries:
    Node: 10.16.3 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.17.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
  SDKs:
    Android SDK:
    Android NDK: 17.2.4988734
  IDEs:
    Android Studio: Version  3.5.0.0 AI-191.8026.42.35.5791312

Steps To Reproduce

  1. In RNTester.onCreate, remove the call to SoLoader.init
  2. Run the app

The app crashes with the following stack trace:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.facebook.react.uiapp/com.facebook.react.uiapp.RNTesterActivity}: java.lang.RuntimeException: SoLoader.init() not yet called
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 Caused by: java.lang.RuntimeException: SoLoader.init() not yet called
    at com.facebook.soloader.SoLoader.assertInitialized(SoLoader.java:781)
    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:505)
    at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:484)
    at com.facebook.react.ReactInstanceManagerBuilder.getDefaultJSExecutorFactory(ReactInstanceManagerBuilder.java:291)
    at com.facebook.react.ReactInstanceManagerBuilder.build(ReactInstanceManagerBuilder.java:266)
    at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:86)
    at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:38)
    at com.facebook.react.ReactDelegate.loadApp(ReactDelegate.java:103)
    at com.facebook.react.ReactActivityDelegate.loadApp(ReactActivityDelegate.java:83)
    at com.facebook.react.ReactActivityDelegate.onCreate(ReactActivityDelegate.java:78)
    at com.facebook.react.uiapp.RNTesterActivity$RNTesterActivityDelegate.onCreate(RNTesterActivity.java:40)
    at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:44)
    at android.app.Activity.performCreate(Activity.java:7183)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) 
    at android.app.ActivityThread.-wrap11(Unknown Source:0) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
    at android.os.Handler.dispatchMessage(Handler.java:105) 
    at android.os.Looper.loop(Looper.java:164) 
    at android.app.ActivityThread.main(ActivityThread.java:6944) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 

Related issues

These touch upon the issue, but have been closed after workarounds were found:

Hello there 👋 this issue seems to have been inactive for the past few years. Because of this, it's likely that the issue is not a high priority anymore or it has been solved by OP; for these reasons, we'll close it.

But please, if it's actually still an issue with latest (RN64 at the time of writing) please comment below and we can reopen it or please send a Pull Request with a fix 😊