React native 调试版本中的React本机崩溃
我正在使用并且在Android上遇到无法调试的崩溃。不幸的是,这只发生在发行版中 我得到的堆栈跟踪如下所示:React native 调试版本中的React本机崩溃,react-native,react-native-android,React Native,React Native Android,我正在使用并且在Android上遇到无法调试的崩溃。不幸的是,这只发生在发行版中 我得到的堆栈跟踪如下所示: E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules Process: com.xx.xx, PID: 22986 com.facebook.react.common.JavascriptException: unable to find socket, stack:
E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
Process: com.xx.xx, PID: 22986
com.facebook.react.common.JavascriptException: unable to find socket, stack:
d@664:708
_onError@664:4582
<unknown>@664:3790
value@77:1364
value@53:2778
<unknown>@53:1013
<unknown>@53:106
value@53:985
at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:99)
at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:83)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:345)
at com.facebook.react.cxxbridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:136)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:739)
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:145)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196)
at java.lang.Thread.run(Thread.java:818)
TcpSocket.prototype._onError = function(error: string): void {
this._debug('received', 'error');
this.emit('error', normalizeError(error));
this.destroy();
};
上面的normalizeError
调用映射到stacktrace中的d
函数。我知道这一点,因为我检查了生成过程中生成的捆绑文件
我理解为什么我的代码流会导致找不到socket
事件,但我不理解的是这个事件最终是如何导致应用程序崩溃的。如果有帮助,此事件将在react native tcp
的本机(Android)组件中生成,并传播到JS端
我希望这样的事件能够报告给监听器(如果有的话),而不是使应用程序崩溃
通过React Native报告的事件是否可能在某些情况下导致崩溃?例如,如果没有侦听器,或者如果事件是错误
对象,或者其他情况
如果这个问题只发生在发行版中,我该如何进行调试呢?我找不到一种有效的调试技术,但能够用良好的ol'打印来调试我遇到的问题 问题是nodej(显然也是React Native)有一个我发现很奇怪的行为:当发出
错误
事件并且没有错误
侦听器时,会抛出一个未处理的异常。这记录在以下文件中:
我的问题是,我正在删除代码中的
错误
侦听器,因为当连接
失败时,错误
回调会被调用两次,因为没有人在端口上侦听。将设备连接到pc并打开android studio,然后运行应用程序,如果它崩溃了,那么你可以在logcat中看到日志。我粘贴的异常堆栈跟踪是从logcat收集的日志中获取的。似乎异常最终是由React Native引发的,但我不明白为什么。
When an error occurs within an EventEmitter instance, the typical action is
for an 'error' event to be emitted. These are treated as special cases
within Node.js.
If an EventEmitter does not have at least one listener registered for the
'error' event, and an 'error' event is emitted, the error is thrown, a stack
trace is printed, and the Node.js process exits.
const myEmitter = new MyEmitter();
myEmitter.emit('error', new Error('whoops!'));
// Throws and crashes Node.js