Android 应用程序在将 React Native 与 NoClassDefFoundError 集成后崩溃:com.facebook.react.bridge.JSPackagerWebSocketClient
2022-08-31 23:43:29
我将 React Native 集成到一个现有的 Android 项目中。代码编译良好,但是当我到达初始化 React Native 的应用程序部分时,应用程序崩溃了。
回溯的相关部分:
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)
关键部分是
java.lang.NoClassDefFoundError: com.facebook.react.bridge.JSPackagerWebSocketClient.
我不确定为什么找不到这个类。React Native 源代码中发生此崩溃的位置在这里。
更新:如果相关,我在此之前遇到了编译时错误,我在这里用解决方案修复了(不包括okhttp-ws),我想知道这可能会导致这种情况。
更新2:我开始认为这与排除okhttp-ws有关,因为我注意到有进口,例如:JSPackagerWebSocketClient.java
import okhttp3.ws.WebSocket;
所以我想真正的问题是,对于我遇到的原始问题,真正的解决方案是什么,那就是:
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: okhttp3/internal/ws/RealWebSocket$1.class
我正在使用 React Native v0.31.0。