问题
Newbie to React Native and react-native-navigation. App works correctly on iOS but throws the exception below very quickly on launch:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.engagereact, PID: 8105
java.lang.BootstrapMethodError: Exception from call site #3 bootstrap method
at com.reactnativenavigation.react.JsDevReloadHandler.<init>(JsDevReloadHandler.java:29)
at com.reactnativenavigation.react.ReactGateway.<init>(ReactGateway.java:29)
at com.engagereact.MainApplication.createReactGateway(MainApplication.java:29)
at com.reactnativenavigation.NavigationApplication.onCreate(NavigationApplication.java:28)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5871)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassCastException: Bootstrap method returned null
at com.reactnativenavigation.react.JsDevReloadHandler.<init>(JsDevReloadHandler.java:29)
at com.reactnativenavigation.react.ReactGateway.<init>(ReactGateway.java:29)
at com.engagereact.MainApplication.createReactGateway(MainApplication.java:29)
at com.reactnativenavigation.NavigationApplication.onCreate(NavigationApplication.java:28)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5871)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
react-native-navigation/lib/android/app/source/etc does indeed return null in line 29 -
private ReloadListener reloadListener = () -> {};
Dependencies:
engage-react@0.0.1 /Users/komara/Documents/infor-repos/EngageReact
├── @babel/plugin-proposal-decorators@7.2.3
├── @babel/runtime@7.0.0
├── axios@0.18.0
├── babel-eslint@10.0.1
├── babel-jest@23.6.0
├── babel-plugin-transform-decorators-legacy@1.3.5
├── babel-preset-react-native@4.0.1
├── eslint@5.12.0
├── eslint-config-airbnb@17.1.0
├── eslint-config-prettier@3.4.0
├── eslint-plugin-import@2.14.0
├── eslint-plugin-jsx-a11y@6.1.2
├── eslint-plugin-prettier@3.0.1
├── eslint-plugin-react@7.12.3
├── jest@23.6.0
├── metro-react-native-babel-preset@0.49.2
├── mobx@5.8.0
├── mobx-react@5.4.3
├── node@11.6.0
├── prettier@1.15.3
├── react@16.6.3
├── react-native@0.57.8
├── react-native-gesture-handler@1.0.12
├── react-native-git-upgrade@0.2.7
├── react-native-navigation@2.5.2
├── react-native-userdefaults-ios@0.1.3
├── react-navigation@3.0.9
├── react-redux@6.0.0
├── react-test-renderer@16.5.0
├── redux@4.0.1
├── redux-devtools@3.5.0
├── redux-devtools-extension@2.13.7
├── redux-logger@3.0.6
├── redux-persist@5.10.0
├── redux-thunk@2.3.0
├── remote-redux-devtools@0.5.16
├── schedule@0.4.0
└── updeep@1.1.0
I'm guessing my dependencies are wrong, but have no idea how to fix.
回答1:
Set Java 8 in ./android/build.gradle adding these lines
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
来源:https://stackoverflow.com/questions/54224065/bootstrap-method-returned-null-android-crash-immediately-on-launch