简体   繁体   中英

Could not install the app on the device on react-native run-android

I am unable to run any react-native project. It says there is already a process running. The port 8081 is taken by McAfee antivirus running on my MAC. And in no way I am able to kill it (even though I should not be killing it, I tried it, and looks like it never dies! SUDO has no power after all!)

Referring to #7308 #9145 and stackoverflow , I tried to run on port 8082. Server starts up, but, run-android still fails saying no device found. I have both my device (Galaxy S7 Edge with Debug mode on) and Genymotion open.

React Native version details -

SATJAGAN-M-T0HZ:react-native-card-modal satjagan$ react-native -v
react-native-cli: 1.0.0
react-native: 0.37.0

Genymotion active and available -

bozzmob:Twitter bozzmobusr$ adb devices
List of devices attached
192.168.57.101:5555 device

Terminal Logs of running the app- (Interestingly it says JS Server not recognized , is there any problem there)?

bozzmob:Twitter bozzmobusr$ react-native start --port 8082
Scanning 712 folders for symlinks in /Users/satjagan/collection/work/github/reactnative/react-native-card-modal/node_modules (15ms)
 ┌────────────────────────────────────────────────────────────────────────────┐ 
 │  Running packager on port 8082.                                            │ 
 │                                                                            │ 
 │  Keep this packager running while developing on any JS projects. Feel      │ 
 │  free to close this tab and run your own packager instance if you          │ 
 │  prefer.                                                                   │ 
 │                                                                            │ 
 │  https://github.com/facebook/react-native                                  │ 
 │                                                                            │ 
 └────────────────────────────────────────────────────────────────────────────┘ 
Looking for JS files in
   /Users/satjagan/collection/work/github/reactnative/react-native-card-modal 

[Hot Module Replacement] Server listening on /hot

React packager ready.

[11/26/2016, 2:47:25 PM] <START> Initializing Packager
[11/26/2016, 2:47:25 PM] <START> Building in-memory fs for JavaScript
[11/26/2016, 2:47:25 PM] <END>   Building in-memory fs for JavaScript (184ms)
[11/26/2016, 2:47:25 PM] <START> Building Haste Map
[11/26/2016, 2:47:25 PM] <END>   Building Haste Map (425ms)
[11/26/2016, 2:47:25 PM] <END>   Initializing Packager (741ms)



bozzmob:Twitter bozzmobusr$ react-native run-android
**JS server not recognized, continuing with build...**
Running adb -s 192.168.57.101:5555 reverse tcp:8081 tcp:8081
Building and installing the app on the device (cd android && ./gradlew installDebug...
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment.
Go to https://facebook.github.io/react-native/docs/getting-started.html
and check the Android tab for setup instructions.

Unfortunately uninstalling McAfee is not an option :( I would have done it first if I had the freedom.

React-Native is still trying to connect to the packager on 8081. Usually you open the development menu and specify a different port, but in your case you can't even get started.

It doesn't appear that you can specify a port otherwise. I think you may have two options:

  1. Temporarily kill McAfee, install, and change the port via the development menu, as mentioned here: https://facebook.github.io/react-native/docs/troubleshooting.html#terminating-a-process-on-port-8081

  2. Change this file: https://github.com/facebook/react-native/blob/292cc82d0ebc437a6f1cdd2e972b3917b7ee05a4/Libraries/Core/Devtools/getDevServer.js

I had similar problem. I couldn't not stop the McAfee process via kill command. This was because it was running as a service. It could be stopped however by via lanuchctl tool. Try this:

cd /Library/LaunchDaemons sudo launchctl unload com.mcafee.agent.macmn.plist

It wil stop the McAfee process that is taking 8081 port.

Here's what you should do to specify a non-default packager location:

(Physically shake the device) > Dev Settings > Debug server host & port for device > IP:Port

在此输入图像描述

Notes:

  • Obviously, this requires the app to be installed on the device first. If you cannot do this automatically, just copy the created .apk manually onto the device and proceed with the instructions after installation.
  • AFAIK, at the time of writing, this option is unavailable in react-native for iOS .
  • To open the debugging menu on an emulator, you can play around with gyro/accelerometer sliders to simulate a shake (I tested it on the stock emulator on Windows, not GenyMotion). Perhaps there's an easier way to do it, but I am yet to find one.

I find in almost all cases when you know the app should run with your current project settings and code, if it doesn't work, try:

killall -9 node

because the Metro Bundler node process is what is probably having the issue. Sometimes it gets bunged up.

That's what I do, but you can more-specifically look at what processes are holding port 8081 and kill those. (try a command like sudo lsof -n -i4TCP:8081 (cite: lsof definition ). If you are running some node.js APIs on your localhost, you should perhaps be more careful with killing all node processes, but if you are just doing React Native dev, you can safely do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM