Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Android crashes when trying to debug in Chrome

I've got a React Native app that is working for iOS and am trying to get it up and running for Android. I have the app up and running in the emulator and I would like to debug it in Chrome to figure out some issues.

The problem occurs when I open up the in app dev tools and click the Debug in Chrome option the app crashes for a couple seconds and I get an alert message that says "Unfortunately MyApp has stopped." then right after that the app comes back up with the red screen and says "Unable to connect with remote debugger".

I believe I've set up everything as the directions said on this page.

Has anyone seen this kind of issue and if so is there a way to fix it?

Thanks!

like image 643
jasonmerino Avatar asked Dec 18 '15 19:12

jasonmerino


2 Answers

Same problem here on Android. I've just started a project with react-native init and begun to follow the Facebook tutorial.

When I run the app without debugging, it works fine. If I enable Debug JS remotely, it crashes after 1 minute (doing nothing).

Testing on Samsung Galaxy S5, react-native-cli 0.2.0, react-native 0.32.1, Windows 7, Chrome 53.

In Android Studio I've found this stacktrace:

09-08 13:25:06.322 31080-3735/com.tutorialproject W/libc: pthread_create failed: couldn't allocate 1064960-byte stack: Out of memory
09-08 13:25:06.322 31080-3735/com.tutorialproject E/art: Throwing OutOfMemoryError "pthread_create (1040KB stack) failed: Try again"
09-08 13:25:06.332 31080-3735/com.tutorialproject E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
    Process: com.tutorialproject, PID: 31080
    java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again
        at java.lang.Thread.nativeCreate(Native Method)
        at java.lang.Thread.start(Thread.java:1063)
        at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:920)
        at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1338)
        at okhttp3.ConnectionPool.put(ConnectionPool.java:135)
        at okhttp3.OkHttpClient$1.put(OkHttpClient.java:149)
        at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:188)
        at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:129)
        at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:98)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
        at okhttp3.RealCall.access$100(RealCall.java:33)
        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:120)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)
09-08 13:25:06.372 31080-31080/com.tutorialproject D/SensorManager: unregisterListener ::   
09-08 13:25:06.852 31080-31185/com.tutorialproject W/unknown:React: Tried to enqueue runnable on already finished thread: 'native_modules... dropping Runnable.
09-08 13:25:06.852 31080-31185/com.tutorialproject W/MessageQueue: Handler (com.facebook.react.bridge.queue.MessageQueueThreadHandler) {246b7490} sending message to a Handler on a dead thread
       java.lang.IllegalStateException: Handler (com.facebook.react.bridge.queue.MessageQueueThreadHandler) {246b7490} sending message to a Handler on a dead thread
           at android.os.MessageQueue.enqueueMessage(MessageQueue.java:325)
           at android.os.Handler.enqueueMessage(Handler.java:631)
           at android.os.Handler.sendMessageAtTime(Handler.java:600)
           at android.os.Handler.sendMessageDelayed(Handler.java:570)
           at android.os.Handler.post(Handler.java:326)
           at com.facebook.react.bridge.queue.MessageQueueThreadImpl.runOnQueue(MessageQueueThreadImpl.java:61)
           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)
09-08 13:25:06.862 31080-3792/com.tutorialproject W/ContextImpl: Failed to ensure directory: /storage/extSdCard/Android/data/com.tutorialproject/cache
09-08 13:25:11.362 31080-31088/com.tutorialproject W/art: Suspending all threads took: 5.930ms

It's a really simple project, with just a couple of text components, so I'm not doing any request. All the network communication is due the remotely debugging.

Since it's an OutOfMemory problem I've tried to add android:largeHeap="true" to Manifest.xml, but nothing changes. The app reaches the 32Mb consumption and dies.

I've modified the app, so it loads a component with an image 5000 times. With the debugging disabled, the app allocates up to 70Mb and works fine. I can scroll all over the screen and nothing crashes. When I enable the remote debugging, I works for a while, until it tries to allocate more memory and crashes again. I can start again the app with the debugging enabled, and it starts well, but again crashes after a while.

IMHO the React Native remote debugging feature has a problem for allocating new memory (and for some reason it consumes a lot of memory even when the app is stopped).

like image 136
rolgalan Avatar answered Oct 25 '22 09:10

rolgalan


I had this problem as well (which is why I came across your post). Have you by any chance based your project on the React Native Material Kit Demo? I had, and was having exactly the same problem with crashing when launching devtools.

I've now rebuilt my project from the ground up using react-native init and the problem seems to have gone away.

like image 40
shankie_san Avatar answered Oct 25 '22 08:10

shankie_san