[英]Android app crashes after integrating React Native with NoClassDefFoundError: com.facebook.react.bridge.JSPackagerWebSocketClient
I integrated React Native into an existing Android project.我将 React Native 集成到现有的 Android 项目中。 The code compiles fine, but when I get to the part of my app that initializes React Native, the app crashes .
代码编译得很好,但是当我到达初始化 React Native 的应用程序部分时,应用程序崩溃了。
Relevant part of the backtrace:回溯的相关部分:
java.lang.RuntimeException: Requested enabled DevSupportManager, but DevSupportManagerImpl class was not found or could not be created
Caused by: java.lang.RuntimeException: Requested enabled DevSupportManager, but DevSupportManagerImpl class was not found or could not be created
at com.facebook.react.devsupport.DevSupportManagerFactory.create(DevSupportManagerFactory.java:77)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at com.facebook.react.devsupport.DevSupportManagerFactory.create(DevSupportManagerFactory.java:70)
Caused by: java.lang.NoClassDefFoundError: com.facebook.react.bridge.JSPackagerWebSocketClient
at com.facebook.react.devsupport.DevServerHelper.<init>(DevServerHelper.java:108)
at com.facebook.react.devsupport.DevSupportManagerImpl.<init>(DevSupportManagerImpl.java:141)
The key part is关键部分是
java.lang.NoClassDefFoundError: com.facebook.react.bridge.JSPackagerWebSocketClient.
I'm not sure why this class wouldn't be found.我不确定为什么找不到这个类。 The location where this crash happens in the React Native source code is here .
在 React Native 源代码中发生这种崩溃的位置在这里。
UPDATE: If it's relevant, I was getting compile-time errors before this that I fixed with the solution here (which excludes okhttp-ws) which I wonder may be causing this.更新:如果相关,在此之前我遇到了编译时错误,我在此处使用解决方案(不包括 okhttp-ws)进行了修复,我想知道这可能是导致此问题的原因。
UPDATE 2: I'm starting to think this is related to excluding okhttp-ws since I noticed in JSPackagerWebSocketClient.java
there are imports such as:更新 2:我开始认为这与排除 okhttp-ws 相关,因为我注意到在
JSPackagerWebSocketClient.java
有一些导入,例如:
import okhttp3.ws.WebSocket;
So I guess the real question is what is the real fix for the original issue I was having, which is:所以我想真正的问题是我遇到的原始问题的真正解决方案是什么,即:
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: okhttp3/internal/ws/RealWebSocket$1.class
I'm using React Native v0.31.0.我正在使用 React Native v0.31.0。
I get that error sometimes when I previously had "Debug JS Remotely" enabled, in the debug menu, when I run my project.当我以前在调试菜单中启用“远程调试 JS”时,有时会遇到该错误,当我运行我的项目时。
First, close the previous web browser tab that the app was connected to, and then in the app dismiss the error then disable "Debug JS Remotely" and reload.首先,关闭应用程序连接到的上一个 Web 浏览器选项卡,然后在应用程序中关闭错误,然后禁用“远程调试 JS”并重新加载。
This is 1 solution to my described common JSPackagerWebSocketClient error, but I am unsure of all your conditions around your issue though, such as your integration process, your android configs, how you ran the app, or maybe it's an issue with an older RN version.这是我描述的常见 JSPackagerWebSocketClient 错误的 1 个解决方案,但我不确定您的问题的所有条件,例如您的集成过程、您的 android 配置、您如何运行应用程序,或者它可能是旧版 RN 的问题.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.