React Native 发布崩溃(调试工作)
Posted
技术标签:
【中文标题】React Native 发布崩溃(调试工作)【英文标题】:React Native Release Crashing (Debug working) 【发布时间】:2017-07-24 08:18:40 【问题描述】:我的 react native 应用程序在调试时工作,但在发布时崩溃。
我目前正在运行 RN:
react-native-cli: 2.0.1 反应原生:0.46.4我已经尝试打开 proguard。
def enableProguardInReleaseBuilds = true
我开始了一个全新的项目并添加了所有源代码,但问题仍然存在。
如何查找导致此错误的原因:
对象作为 React 子对象无效(发现:对象与键 $$typeof, type, key, ref, props, _owner)。
来自安卓监视器的错误日志:
07-24 18:00:39.511 5165-5185/com.imoovaapp I/ReactNativeJS: Running application "imoovaApp" with appParams: "rootTag":1. __DEV__ === false, development-level warning are OFF, performance optimizations are ON
07-24 18:00:39.545 5165-5185/com.imoovaapp E/ReactNativeJS: Objects are not valid as a React child (found: object with keys $$typeof, type, key, ref, props, _owner).
07-24 18:00:39.685 5165-5186/com.imoovaapp E/androidRuntime: FATAL EXCEPTION: mqt_native_modules
Process: com.imoovaapp, PID: 5165
com.facebook.react.common.javascriptException: Objects are not valid as a React child (found: object with keys $$typeof, type, key, ref, props, _owner)., stack:
ct@113:18788
ct@113:18631
lt@113:18974
instantiateChildren@114:24013
_reconcilerInstantiateChildren@114:24901
mountChildren@114:25121
initializeChildren@114:26997
mountComponent@114:27807
mountComponent@114:1015
performInitialMount@114:9245
mountComponent@114:8145
mountComponent@114:1015
performInitialMount@114:9245
mountComponent@114:8145
mountComponent@114:1015
Ue@113:13180
perform@114:2691
Me@113:13343
perform@114:2691
batchedUpdates@114:17977
Ce@113:10516
renderComponent@114:17006
$i@114:28352
r@262:116
run@258:547
runApplication@258:1970
value@29:3208
<unknown>@29:959
value@29:2640
value@29:931
at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:56)
at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:40)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:363)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:166)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
at android.os.Looper.loop(Looper.java:154)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
at java.lang.Thread.run(Thread.java:761)
07-24 18:00:39.706 1501-3485/system_process W/ActivityManager: Force finishing activity com.imoovaapp/.MainActivity
07-24 18:00:39.838 1229-1268/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x333 imply creation of host color buffer
[ 07-24 18:00:39.847 1501: 1908 D/ ]
HostConnection::get() New Host Connection established 0x93bb5080, tid 1908
07-24 18:00:39.859 1229-1229/? E/EGL_emulation: tid 1229: eglCreateSyncKHR(1451): error 0x3004 (EGL_BAD_ATTRIBUTE)
07-24 18:00:39.961 1501-1522/system_process W/art: Long monitor contention with owner Binder:1501_6 (1908) at android.graphics.Bitmap com.android.server.wm.WindowManagerService.screenshotApplicationsInner(android.os.IBinder, int, int, int, boolean, float, android.graphics.Bitmap$Config)(WindowManagerService.java:6252) waiters=0 in void com.android.server.wm.WindowAnimator$1.doFrame(long) for 149ms
07-24 18:00:39.968 1229-1829/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
07-24 18:00:39.991 1229-1829/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
07-24 18:00:40.035 1229-1829/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
07-24 18:00:40.036 1501-1908/system_process D/gralloc_ranchu: gralloc_unregister_buffer: exiting HostConnection (is buffer-handling thread)
07-24 18:00:40.053 1501-1511/system_process I/art: Background partial concurrent mark sweep GC freed 11915(870KB) AllocSpace objects, 3(60KB) LOS objects, 22% free, 13MB/17MB, paused 898us total 101.813ms
07-24 18:00:40.086 1501-1516/system_process W/art: Long monitor contention with owner Binder:1501_A (2584) at android.content.ComponentName com.android.server.am.ActivityManagerService.startService(android.app.IApplicationThread, android.content.Intent, java.lang.String, java.lang.String, int)(ActivityManagerService.java:16905) waiters=1 in android.content.Intent com.android.server.am.ActivityManagerService.registerReceiver(android.app.IApplicationThread, java.lang.String, android.content.IIntentReceiver, android.content.IntentFilter, java.lang.String, int) for 291ms
07-24 18:00:40.206 1501-1556/system_process I/OpenGLRenderer: Initialized EGL, version 1.4
07-24 18:00:40.206 1501-1556/system_process D/OpenGLRenderer: Swap behavior 1
07-24 18:00:40.213 1229-1274/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
07-24 18:00:40.240 1229-1274/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
07-24 18:00:40.262 1229-1274/? D/gralloc_ranchu: gralloc_alloc: format 1 and usage 0x900 imply creation of host color buffer
07-24 18:00:40.520 1501-1522/system_process I/WindowManager: Destroying surface Surface(name=com.imoovaapp/com.imoovaapp.MainActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.AppWindowToken.destroySurfaces:365 com.android.server.wm.WindowStateAnimator.finishExit:565 com.android.server.wm.AppWindowAnimator.stepAnimationLocked:427 com.android.server.wm.WindowAnimator.updateAppWindowsLocked:196
07-24 18:00:40.607 1957-2095/com.android.launcher3 W/OpenGLRenderer: Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
【问题讨论】:
好吧,ReactNative 通常会在尝试渲染既不是组件也不是基本类型(如字符串、整数等)的东西时引发该异常。可能发生的情况是,在发布模式下,您会收到一个复杂的对象,而不是您在调试模式下收到的简单对象。您能否添加有关如何生成发布部署的信息?谢谢。 有什么解决办法吗?我有同样的问题。 【参考方案1】:我在 react-native 应用程序中遇到了完全相同的问题。原来我在创建商店的文件上导入了 babel-polyfill(应用程序使用 redux)。在评论那条线之后,它就像一个魅力。如果您没有类似的东西,我建议您在文件中调试导入。
【讨论】:
【参考方案2】:似乎它试图呈现一个普通的 javascript 对象。
我的意思是你的 JSX 代码中可能有一个普通对象,正如你的错误日志中提到的那样。
ReactNativeJS: Objects are not valid as a React child (found: object with keys $$typeof, type, key, ref, props, _owner).
【讨论】:
以上是关于React Native 发布崩溃(调试工作)的主要内容,如果未能解决你的问题,请参考以下文章
React Native iOS 8.1 应用程序在访问新视图时崩溃 - 仅在不使用调试器时
Imagepicker React Native 在 iOS 上崩溃但在 Android 上运行良好
尝试连接到 react-native-debugger 或 Chrome 时崩溃
React-Native-Camera 不能在 IOS 上工作但在 Android 上工作,IOS 应用程序崩溃