Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'React native run android' stop immediatelly after start the app in emulator

I'm trying to test my Android application but when I start it with react-native run-android command after it is start on the device inmediatelly stop without error.

I got this:

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html
Running adb -s emulator-5556 reverse tcp:8081 tcp:8081
Starting the app on emulator-5556 (adb -s emulator-5556 shell am start -n com.app/.MainActivity)...
Starting: Intent { cmp=com.app/.MainActivity }

After I get back the prompt but not always, if I keep on try it is sometimes running properly, but I have to run this 10-15 times. The SDK version is 25 and I followed the React Native Getting Started installation guide.

  • OS: Fedora 24
  • React-native: 0.42.0

UPDATE:

I tryed out with react-native start and it was said for me Loading dependency graph... ERROR Packager can't listen on port 8081 but I don't understand why the previous command didn't said it for me. In this case I can change the port with the --port 9000, but I didn't found any other flag for the in the react-native run-android command.

UPDATE 2:

It seems the problem occured because the remote debugger switched on on the device and it's connected to the remote debugger on the :8081 port and the adb wanted to create a new server for the mobile app through the :8081 for a while the old remote debug is still occupy the :8081 port, so it wasn't allow to create a new one. I switched off the remote debugger and it is running without problem. I'm not sure about that it's possible it was the problem.

like image 682
PumpkinSeed Avatar asked Mar 10 '17 12:03

PumpkinSeed


People also ask

Why React Native app keeps stopping?

Storage Issue is another cause that leads to this sudden crashing of the Android Apps. As it happens, a lot of apps require a subsequent amount of storage space failing which might lead the app to close abruptly thus disrupting your work.

Which Android emulator is best for React Native?

React Native recommends the Genymotion emulator out of the box. For many developers (and corporations), the price tag on Genymotion is not worth the expense. We'll be using the free Android Studio emulator for this walkthrough.


2 Answers

i was having the same problem in ubuntu what worked for me is that i closed terminal removed my device from usb restarted. first of all would suggest you add these lines inside your packages.json replace scripts with this

"scripts": {
"prepare-repository": "npm i -g react-native-cli yarn;yarn install; react- native link",
"emulator": "emulator -avd Nexus5V6L23_x86_64 -scale 1.0",
"install": "react-native run-android",
"start": "react-native start --reset-cache",
"android": "npm run install && npm run start",
"clean": "watchman watch-del-all && npm cache clean && cd android && ./gradlew clean && cd ..",
"test": "jest"
}

After that save it and then go to the folder where u created project. lets say mine home/workspace/demo. Inside that run script

 npm run clean //this will clear all cache

after that

npm run android 

It will run app in device as well as start-reset cache.Let me know if it helps.

Sometimes adding

adb reverse tcp:8081

before running npm run android does the trick I will recommend you to enable Gradle daemon it really makes your build faster. To enable it goto android->gradle.properties and inside that file write

org.gradle.daemon=true
like image 91
Nitesh Mishra Avatar answered Sep 19 '22 14:09

Nitesh Mishra


I had the same issue and problem is described here port already in use. So just kill the process occupying the port.

sudo lsof -i :8081

kill -9 <PID>

like image 44
Bardolf Avatar answered Sep 18 '22 14:09

Bardolf