10

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.

3
  • 2
    Look at the logcat. There should be a stack trace. Commented Sep 5, 2016 at 2:27
  • @GabeSechan - thanks for the quick response. Fairly new to mobile app development so had to do a quick google search to figure out what logcat is - I'll update the question with the stack trace results. Thanks! Commented Sep 5, 2016 at 2:35
  • 2
    Check out github.com/facebook/react-native/issues/8215 Commented Sep 5, 2016 at 2:51

7 Answers 7

17

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

Sign up to request clarification or add additional context in comments.

Comments

4

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.

Comments

3

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.

1 Comment

"open /android folder on Android Studio". This instruction helps me a lot, and I could trace error why occurred.
2

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'

Comments

1

add this (for Release apk)

**android:usesCleartextTraffic="true"**

in ./android/app/src/main/AndroidManifest.xml

and in debug case remove this line from (gradle.properties) if add added so...

**hermesEnabled=true**

And remove this from (node_modules/react-native-reanimated/android/build.gradle) hope it will work

if ((REACT_NATIVE_MINOR_VERSION >= 71&& appProject?.hermesEnabled?.toBoolean())|| appProject?.ext?.react?.enableHermes?. toBoolean()) { return "hermes" }

Comments

0

I had same issue, after trying lots of things, this fixed this issue for me:

1: added googlePlayServicesVersion=12.0.1 to gradle.properties (I guess it's unnecessary)

2: added following to android/build.gradle:

 allprojects {
    repositories {
    //start here
    configurations.all {
 resolutionStrategy.eachDependency { DependencyResolveDetails details ->
   def requested = details.requested
       if (requested.group == 'com.google.android.gms') {
          details.useVersion '12.0.1'
       }
       if (requested.group == 'com.google.firebase') {
          details.useVersion '12.0.1'
         }
       }
     }
    //end
     jcenter()
       maven {
         url "https://maven.google.com"
       }
     }
 }

I've found this in https://github.com/idehub/react-native-google-analytics-bridge/wiki/Solution-for-Android-build-failure-issues

Comments

0

In my case I had given targetSdkVersion as 30 in android/build.gradle and emulator that I was trying to execute the application, had requirement lesser then this version, changing that to 28 helped me in building application. If your application is fine having 28 as build version then you too can try this approach.

targetSdkVersion = 30 // Before
targetSdkVersion = 28 // After

Disclaimer: This is just one of the reason for this issue and downgrading to 28 may not be suitable option for everyone, please be sure on that before implementing this solution.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.