Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android application keeps stopping . Does not work react-native-navigation on Android #2989

Closed
sinevitch opened this issue Apr 7, 2018 · 58 comments

Comments

@sinevitch
Copy link

sinevitch commented Apr 7, 2018

Issue Description

Does not work react-native-navigation on Android
Starting : Intent { …MainActivity }.

Did everything as indicated in the documentation. I launch the Android Studio emulator.

image
On iOS, the same code works fine
index.ios.js
import App from './App';

index.android.js
import App from './App';

app.js:

   import { Navigation } from "react-native-navigation";
   import AuthScreen from "./src/screens/Auth/Auth";
   // Register Screens
   Navigation.registerComponent("awesome-places.AuthScreen", () => AuthScreen);

   // Start a App
     
   Navigation.startSingleScreenApp({
              screen: {
               screen: "awesome-places.AuthScreen",
               title: "Login"
            }
    });

auth.js:

import React, { Component } from 'react';
import { View, Text } from 'react-native';

class AuthScreen extends Component {
    render () {
        return (
            <View>
                <Text>Auth Screen</Text>
            </View>
        );
    }
}
export default AuthScreen;

settings.gradle

 rootProject.name = 'rncourse'

 include ':app'



include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, 
'../node_modules/react-native-vector-icons/android')

include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, 
'../node_modules/react-native-navigation/android/app/')

build.gradle

dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"
    compile project(':react-native-vector-icons')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"
    compile project(':react-native-navigation')  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}


project.ext.vectoricons = [
    iconFontNames: [ 'Ionicons.ttf'] // Name of the font files you want to copy
]

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

MainActivity.java

 import com.reactnativenavigation.controllers.SplashActivity;

 public class MainActivity extends SplashActivity {

 }

MainApplication.java

package com.rncourse;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.oblador.vectoricons.VectorIconsPackage;
import com.reactnativenavigation.NavigationApplication;

import java.util.Arrays;
import java.util.List;


public class MainApplication extends NavigationApplication {

     @Override
     public boolean isDebug() {
         // Make sure you are using BuildConfig from your own application
         return BuildConfig.DEBUG;
     }

     protected List<ReactPackage> getPackages() {
         // Add additional packages you require here
         // No need to add RnnPackage and MainReactPackage
         return Arrays.<ReactPackage>asList(
             new VectorIconsPackage()
         );
     }

     @Override
     public List<ReactPackage> createAdditionalReactPackages() {
         return getPackages();
     }
 }

I tried to use the version of "react-native": "^ 0.49.5",
The same thing happens
Android does not work
IOS works


Environment

  • React Native Navigation version: "^1.1.434",
  • React Native version: "0.54.0",
  • Platform(s) : Android 8.1
  • Device info : Android Simulator
  • Android Studio version 3.1
@peakyDicers
Copy link

peakyDicers commented Apr 7, 2018

I am having a very similar issue. My project builds successfully, but a blank screen appears in the android emulator, and the developers menu cannot be accessed. I've posted my setup and screenshots in this similar thread. #2687

@sinevitch sinevitch changed the title Starting : Intent { …MainActivity }. Does not work react-native-navigation on Android Android application keeps stopping . Does not work react-native-navigation on Android Apr 9, 2018
@chinmaygit
Copy link

Try this,
stop the packager.
adb reverse tcp:8081 tcp:8081
start the packager.

@sinevitch
Copy link
Author

adb reverse tcp:8081 tcp:8081

Did not help

image

@chinmaygit
Copy link

@sinevitch Open Logcat while you are opening the app, and look for crash log and share it here.

@sinevitch
Copy link
Author

image

@AmaruNozomi
Copy link

Same here :
Starting: Intent { cmp=com.XXX/.MainActivity }

and

"Unfortunately, Application has stopped" message on the emulator

trying adb logcat in terminal but can't locate the error source !!

any updates on the issue?

@ghost
Copy link

ghost commented May 15, 2018

Facing the same issue. any fix?

@ashifa454
Copy link

Any update on this issue?

@ghost
Copy link

ghost commented May 17, 2018

In android, changed react-native dependeny to
compile('com.facebook.react:react-native:0.51.1') { force = true }

Version should be exact same as in package.json
Cleaned and rebuilt project and it worked.

@SirPhemmiey
Copy link

Any update on this issue?

@guyca
Copy link
Collaborator

guyca commented May 31, 2018

The single crash log which was posted here has nothing to do with RNN. I'm closing as we really can't help you resolve this issue.

@guyca guyca closed this as completed May 31, 2018
@NySiya
Copy link

NySiya commented Oct 17, 2018

I am having this very same problem :(

@MaciekLeks
Copy link

The same issue after linking with react-native-firebase. No logs. It's just crashing on the physical device.

@wijaksanapanji
Copy link

The same issue after linking with react-native-firebase. No logs. It's just crashing on the physical device.

any solution for your problem, im new to react-native, i got the same problem after adding react-native-firebase

@MaciekLeks
Copy link

MaciekLeks commented Oct 28, 2018

I've got it. The problems lies in the android/app/build.gradle dependency versions. Try to put there all the new one version numbers looking at (in this case for Android):

Then, the immediate shutting down should no longer appears. Then you probably see other exceptions but just follow any other tips.

@wijaksanapanji
Copy link

The same issue after linking with react-native-firebase. No logs. It's just crashing on the physical device.

any solution for your problem, im new to react-native, i got the same problem after adding react-native-firebase

i just moved google() in android/build.gradle to the top, and it worked

repositories {
    google()
    mavenLocal()
    jcenter()
    maven {
      // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
      url "$rootDir/../node_modules/react-native/android"
    }
  }
}`

@marcosgallardo
Copy link

@sinevitch

Try by changing your MainActivity.java to:

package com.rncourse; //<- App package name goes here

import com.reactnativenavigation.controllers.SplashActivity;

public class MainActivity extends SplashActivity {

}

@potatokoosh
Copy link

potatokoosh commented Apr 1, 2019

Corriendo un app con react-native
tube el mismo problema, me estuvo saliendo el mensaje de App keep stopping, el emulador no me mostraba la app,, lo solucione con los siguientes pasos

  1. abrir el proyecto en android studio
  2. ejecutar el play o el emulador (aqui no me abre el proyecto sale app keep stopping)
  3. desde la terminal das react-native run-android

espero ayude

@potatokoosh
Copy link

adb reverse tcp:8081 tcp:8081

Did not help

image

try to run from terminal, react-native run-android
but first you have to have open android studio with the project and runing a emulator,, probably the message will apear (app keep stopping),,then in terminal you run react-native run android

this worked for me

i hope it works for you

@mohshbool
Copy link

@potatokoosh It also didn't work for me, but my message is "myApp keeps stopping". Does anybody have any other solutions?

@monaye
Copy link

monaye commented May 3, 2019

having the same error message for the Android release build.
"react": "16.6.3",
"react-native": "0.58.6",

Are there any tools to debug what is going on in the release build?

@ThatoMahlatji
Copy link

In my case the application loads when the phone is connected to the metro-builder, but once the phone is disconnect from the Metro-builder the application crashes.

@AntonioMIN
Copy link

I had the same problem. But I just fixed it by pressing Ctrl + M a few times. I do not know how it works.

@naveenfy
Copy link

I have the same problem. :|

@naveenfy
Copy link

I closed the app and relaunched it from the Android, it worked for me.

@AmeraAbdallah
Copy link

I had a similar problem, I fixed it by removing component from screen that I wanna navigate to it, and it was nativeBase Picker component

@maxjf1
Copy link

maxjf1 commented Jul 26, 2019

I had this problem with the lib react-native-pdf-lib.

With LogCat i figure it out, i had to ask for WRITE_EXTERNAL_STORAGE with PermissionsAndroid

@jgo80
Copy link

jgo80 commented Aug 8, 2019

Occurred to me as well, just like this without adding packages.
I was trying to find a solution, reading a lot, without luck.
I finally desperately wiped the Android Emulator and - tataaa - that was it. Worked for me.

@EdersonJunior
Copy link

I solved this issue (in my case) using this link: https://medium.com/@impaachu/react-native-android-release-build-crash-on-device-14f2c9eacf18.

@gorvinsky
Copy link

I solved this issue (in my case) using this link: https://medium.com/@impaachu/react-native-android-release-build-crash-on-device-14f2c9eacf18.

It seems that there could be different reasons for this to happen and the best way to nail the cause is by using this method. I solved mine with this and for my case, it's because of a library that I installed. I solved it by uninstalling that library.

@raemarcsg30
Copy link

Maybe you don't have index.android.js and index.ios.js with import App from './App'; ?

@diebraga
Copy link

diebraga commented Sep 8, 2019

I could not solve the problem but you can just '' react-native init '' and change app.js from the the old app.

@arthedza
Copy link

arthedza commented Oct 4, 2019

Maybe you should restart Metro bundler

@pedromelo98
Copy link

pedromelo98 commented Oct 31, 2019

same here
"react": "16.8.3",
"react-native": "^0.60.4"
AndroidX

@rajnishcoder
Copy link

I could not solve the problem but you can just '' react-native init '' and change app.js from the the old app.

Does that solved the problem?

@PrateekOraon
Copy link

See that you don't have two react-native versions installed simultaneously. Do :
npm list --depth

If there are two RN versions, there will be a version mismatch and the app will keep stopping.

npm uninstall react-native@<the-version-you-want-to-uninstall>
Then run your code again.

@shahnawazhussain125
Copy link

shahnawazhussain125 commented Dec 16, 2019

build has been complete and emiulator is working then error "Keeps Stoping"

emilator

install
npm list --depth

check error and my be install
npm install eslint
my error remove run project

@yelinag
Copy link

yelinag commented Dec 21, 2019

Debug/run the project in android studio where you will be able to see error logs. For my case, there are a lot of issues as haven't tested in android for a very long time.

@ALashchotka
Copy link

Works for me: evollu/react-native-fcm#998 (comment)

@marcinkieruzel
Copy link

In my case gradlew clean on Windows or ./gradle clean on Linux makes the emulator works again.

@ghost
Copy link

ghost commented Jan 30, 2020

how can i remove this error..

2020-01-30 01:06:07.156 3396-3396/com.dotundo.androiddoctor E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dotundo.androiddoctor, PID: 3396
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dotundo.androiddoctor/com.dotundo.androiddoctor.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2865)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2955)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6747)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:449)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.dotundo.androiddoctor.MainActivity.LoginFunction(MainActivity.java:54)
at com.dotundo.androiddoctor.MainActivity.onCreate(MainActivity.java:33)
at android.app.Activity.performCreate(Activity.java:7025)
at android.app.Activity.performCreate(Activity.java:7016)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1217)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2812)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2955) 
at android.app.ActivityThread.-wrap12(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6747) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:449) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

@MartykQ
Copy link

MartykQ commented Feb 27, 2020

For me the problem was I was following steps from react-native docs instead react-navigation official docs. The first one does not mention this step:


To finalize installation of react-native-screens for Android, add the following two lines to dependencies section in android/app/build.gradle:

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

@PontesVinicius
Copy link

I solved this error by updating the version of Android Studio.

@robauer
Copy link

robauer commented Mar 20, 2020

I solved this error by updating the version of Android Studio.

Updating is what go me into this mess.

@Cmion
Copy link

Cmion commented May 2, 2020

gradlew clean, uninstalling the app then yarn run android solved the problem on windows

@iankressin
Copy link

@Cmion answer works in Ubuntu 20.4 as well

@WadhahEssam
Copy link

what solved it for me was cleaning the project, so it might work for you.
run
git clean -d -x -f

then just run
npm install or yarn

@YDaskaloff
Copy link

YDaskaloff commented Jul 29, 2020

Assuming environment is set up correctly and you are not using Expo, run the following:

~ cd android
~ ./gradlew clean
~ cd ..
~ npm install
~ npm react-native start
~ npm react-native run-android

This worked for me.

@0707236659
Copy link

0707236659 commented Oct 23, 2020

I only met this problem on android 8 but it worked on android 7, 8.1 ,9 and 10

@TomHessburg
Copy link

Just got through this issue after a solid day or two of smacking my face against the wall with it lol. Not sure if this will help anyone, but this was the issue for me:

After ejecting from expo, src/main/java/.../MainActivity.java and MainApplication.java were not generated. For whatever reason, I was still able to run on android using 'expo start' even with this being that case.

When running react-native run-android, I found that first issue (got a bunch of errors saying that there was no MainApplication file). Not a problem, just went ahead and added my own.

After adding my own, I started seeing the issue that this thread is mentioning. I tried a bunch of stuff, but what ended up being the case for me was that the getMainComponentName method inside of MainActivity.java was incorrect (think it was my package name or something, where it was supposed to be "main", at least in my case).

Again, not saying this will be the issue for everyone, but might be worth it to take a look at your src/main/java//... files to see if anything looks off. To figure out what these files are supposed to look like, i just checked out some other projects (for instance the expo bare project templates repo) for reference.

If you're able to run logcat, that'll definitely help, but in my case I don't think the app was even being mounted, thus logcat wasn't showing any errors, so I had to brute force it haha.

@EshaZaheer
Copy link

i was facing he same issue but when I uninstall the app and run it again on my phone then it worked properly

@ronaldmgdev
Copy link

ronaldmgdev commented Aug 24, 2021

I solved it by deleting the node_modules and then re run

@Robogeek95
Copy link

I solved it by deleting the node_modules and then re run

Thanks @mutabazigakuba This worked for me

@engsan710
Copy link

My problem was that one of my styles had the following:
...
padding: '16px',
...
It worked just fine on the web, but the emulator did not like it. The way I found the root cause is I removed all sections until the app started. Then I add one section at a time until I found the one that had the incorrect style.
The correction was to change it to:
...
padding: 16,
...
I hope this helps somebody.

@kyrieLiu3
Copy link

gradlew clean, uninstalling the app then yarn run android solved the problem on windows

It works for me thanks to @iankressin. Actually there is always dependence issues when you install new dependence, so you just clean the cache and restart it. GOOD LUCK!

@piyushrajput45
Copy link

piyushrajput45 commented Apr 7, 2023

It works for me
Add this

android:usesCleartextTraffic="true"

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

@gokulanand-selvan
Copy link

gokulanand-selvan commented May 3, 2023

I'm learning react native for 1week so,i'm sharing my error fix, in my case i debugged and i cleared the things one by one that i added . Atlast there is an svg and i removed the svg, after that the app started to work fine. then i found some libraries to use svg images.

@Sudo-MARY
Copy link

Sudo-MARY commented Jun 22, 2023

In my issues, creating lauchscreen.xml inside layout folder

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/launch_screen" android:scaleType="centerCrop" />
</RelativeLayout>

and it worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests