Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
petterh opened this issue Sep 5, 2019 · 1 comment
Labels
Bug p: Microsoft Partner: Microsoft Partner Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.

Comments

@petterh
Copy link
Contributor

petterh commented Sep 5, 2019

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:

@petterh petterh added the Bug label Sep 5, 2019
@react-native-bot react-native-bot added the Platform: Android Android applications. label Sep 5, 2019
facebook-github-bot pushed a commit that referenced this issue Sep 6, 2019
#26343)

Summary:
This change fixes the issue "[ReactInstanceManagerBuilder.build fails unless SoLoader.init has been called](#26342)" on Android.

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 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) 

## Changelog

[Android] [Fixed] - Don't crash ReactInstanceManagerBuilder.build even if SoLoader has not been explicitly initialized
Pull Request resolved: #26343

Test Plan:
To demonstrate the defect, remove the call to `SoLoader.init` from `RNTester.onCreate` and run the app.

To demonstrate the fix, apply this PR, which does in fact also remove the call to `SoLoader.init`

Differential Revision: D17223701

Pulled By: mdvacca

fbshipit-source-id: c508ab52bd3fefe8a946ebab7b2906a5d8c21e0f
@kelset
Copy link
Collaborator

kelset commented Jun 18, 2021

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 😊

@kelset kelset closed this as completed Jun 18, 2021
@facebook facebook locked as resolved and limited conversation to collaborators Jun 18, 2022
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jun 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug p: Microsoft Partner: Microsoft Partner Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants