React Native app keeps closing on android emulator

13,155

Solution 1

It turns out that if you are upgrading React Native, be wary that the upgrade process does not necessarily update all the required files (at the time of writing, upgrading to RN 0.32.0). It turns out this is a known issue (https://github.com/facebook/react-native/issues/8215). Until that's resolved, you'll need to manually update the AndroidManifest.xml file located at ./android/app/src/main/AndroidManifest.xml. I would recommend creating a sample react native project, and using the newly created AndroidManifest.xml from there to manually update the one in your existing project. Also, whenever you upgrade, do a diff between a newly created RN project and your own to verify that no other files need to be updated.

Solution 2

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

Solution 3

To solve your problem, add these two lines in android\app\build.gradle file under dependencies`:

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'

Solution 4

I've had the same issue,

TLDR: metro won't show all the errors you have to use native tools such as XCode and Android Studio to see that error.

How-to-fix: Try running the react-native application on android studio, steps as below,

  1. yarn start or npx start
  2. open /android folder on Android Studio and click on run icon (green play icon)

Hopefully, once it ran you will find your error, react native metro alone won't show those errors.

Share:
13,155
Uzair Faisal
Author by

Uzair Faisal

Updated on July 22, 2022

Comments

  • Uzair Faisal
    Uzair Faisal almost 2 years

    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.

  • Felix Htoo
    Felix Htoo almost 3 years
    "open /android folder on Android Studio". This instruction helps me a lot, and I could trace error why occurred.