Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app crashes after integrating React Native with NoClassDefFoundError: com.facebook.react.bridge.JSPackagerWebSocketClient

I integrated React Native into an existing Android project. The code compiles fine, but when I get to the part of my app that initializes React Native, the app crashes.

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.

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.

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:

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.

like image 258
Liron Yahdav Avatar asked Mar 09 '17 07:03

Liron Yahdav


1 Answers

I get that error sometimes when I previously had "Debug JS Remotely" enabled, in the debug menu, when I run my project.

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.

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.

like image 100
CodeYute Avatar answered Nov 02 '22 09:11

CodeYute