Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native app keeps closing on android emulator

I'm trying to run a react native app on the android emulator (react-native run-android), however it keeps crashing with the error message "MYAPP has stopped". I'm trying to figure out where I can debug this further (error messages, logs, etc). I don't exactly see any error messages on the terminal nor on the emulator itself. So besides trying to resolve why the app won't deploy ... where does one look to further debug app deployment issues on an android emulator?

enter image description here

Side note: I upgraded from version 0.31.0 to 0.32.0 and ran the react-native upgrade command, which also required that some files be over-written (I chose the option to overwrite all files). Should I be worried that the latest changes from upgrade to 0.32.0 are not working or incomplete? Any steps I can take to verify that the latest changes are there?

Update: I created a new sample react native project just to see if there was something wrong with RN's latest version. It worked fine. Then took the sample code in index.android.js and overwrote it in my project's index.android.js and re-ran. Still getting the same issue with trying to deploy it to an Android emulator. Removed the node_modules directory, reran, still same issue. I'm now thinking this has something to do with the upgrade process... this is very frustrating.

Update v2: Thanks to @GabeSechan for the hint and direction, here's the stack trace that I found:

09-04 03:24:41.297  5008  5008 E AndroidRuntime: FATAL EXCEPTION: main
09-04 03:24:41.297  5008  5008 E AndroidRuntime: Process: com.helpr, PID: 5008
09-04 03:24:41.297  5008  5008 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.helpr/com.helpr.MainActivity}: java.lang.ClassCastException: android.app.Application cannot be cast to com.facebook.react.ReactApplication
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at android.app.ActivityThread.-wrap12(ActivityThread.java)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:154)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:6077)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
09-04 03:24:41.297  5008  5008 E AndroidRuntime: Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.facebook.react.ReactApplication
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at com.facebook.react.ReactActivity.getUseDeveloperSupport(ReactActivity.java:89)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:96)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at android.app.Activity.performCreate(Activity.java:6664)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
09-04 03:24:41.297  5008  5008 E AndroidRuntime:    ... 9 more

After a quick google search, it seems this is an existing issue when it comes to upgrading React Native. I'll post an answer, answering my own question.

like image 748
Uzair Faisal Avatar asked Sep 05 '16 02:09

Uzair Faisal


1 Answers

If you have recently changed anything inside your gradle configurations or androidmanifest.xml such as package name etc.. then you must clean gradle files:

To solve this problem:

cd android
./gradlew clean

This should delete your old build directory and generate a new one

like image 96
Ahmad Khudeish Avatar answered Oct 07 '22 22:10

Ahmad Khudeish