Related
When I start my Expo project with
expo start --clear --localhost --dev
Expo is starting the Metro Bundler and a short time later it is up and running. => "Metro Bundler ready"
But after maybe 30-60 seconds this notification pops up:
I've already tried reinstalling nodejs and expo. I've also tried just running 'expo start'. But nothing worked for me.
The only error I get is:
[08:07:54] Could not access packager status at http://127.0.0.1:19001/status. Are you sure the packager is running and reachable?
The funny thing is that the first time I tried 'expo start' it worked.
If you are on windows, use ipconfig on cmd, get the ip address of the network you are connected to and run, using my ip address as an example, run
set REACT_NATIVE_PACKAGER_HOSTNAME=192.168.200.63
use "sudo npm install"
then use "sudo expo start"
I solved my problem using these commands
I'm setting up my development environment for React Native with a custom Android Emulator (Nox).
I followed the steps on this website:
How to connect Android Studio with Nox App Player
But when I type: adb devices it still shows nothing.
So when I try to run my app with react-native run-android it says that there is no Android simulator running.
Is there something I missed or someone with the same problem?
Open terminal and type adb connect 127.0.0.1:62001. type adb devices to make sure your emulator is connected.
Go to your project, type react-native run-android --deviceId 127.0.0.1:62001, waiting for the project to finish compiling, and the you will see a red error screen.
Open the developer menu, Go to Dev Settings β Debug server host for device, Assume your local ip is 192.168.1.121, then type: 192.168.1.121:8081
Use developer menu to reload your app,then close the app, and reopen it.
Open terminal and type adb connect 127.0.0.1:62001. type adb devices
to make sure your emulator is connected.
Go to your project, type react-native run-android --deviceId 127.0.0.1:62001, waiting for the project to finish compiling, and then you will see a red error screen.
Open the developer menu, Go to Dev Settings β Debug server host for device, Assume your local ip is 192.168.1.121, then type:
192.168.1.121:8081
Use developer menu to reload your app,then close the app, and reopen it.
Just in step 2 type react-native run-android (if you don't work with android >10 add prefix) --no-jetifier. It works for me!
it mean for android v 4.1.1 in nox emulator adb connect 127.0.0.1:62001
for android v 5.1.1 in nox emulator adb connect 127.0.0.1:62025
adb connect localhost:62001
react-native run-android --deviceId localhost:62001
I'm using React.JS and when I do react-native run-android (with my device plugged in) I see a blank page. When I shake the device and select Debug JS Remotely from the option list I see the following screen.
FYI:
OS: Ubuntu 16.04
Node version is: v4.6.2
java version "1.8.0_111"
react": "15.4.1
react-native": "0.38.0
In my case the issue was that the emulator was making a request to:
http://10.0.2.2:8081/debugger-ui
instead of:
http://localhost:8081/debugger-ui and the request was failing.
To solve the issue: Before enabling remote debugging on your emulator, open http://localhost:8081/debugger-ui in chrome. Then enable remote debugging and go back to the chrome page where you should see your console logs.
Solved the issue following:
Press Cmd + M on emulator screen
Go to Dev settings > Debug server host & port for device
Set localhost:8081
Rerun the android app: react-native run-android
Debugger is connected now!
I solved it doing adb reverse tcp:8081 tcp:8081 and then reload on my phone.
In my case, selecting Debug JS Remotely launched Chrome, but did not connect with the android device. Normally, the new Chrome tab/window would have the debugging URL pre-populated in the address bar, but in this case the address bar was blank. After the timeout period, the "Unable to connect with remote debugger" error message was displayed. I fixed this with the following procedure:
Run adb reverse tcp:8081 tcp:8081
Paste http://localhost:8081/debugger-ui into the address field of my Chrome browser. You should see the normal debugging screen but your app will still not be connected.
That should fix the problem. If not, you may need to take the following additional steps:
Close and uninstall the app from your Android device
Reinstall the app with react-native run-android
Enable remote debugging on your app.
Your app should now be connected to the debugger.
I had a similar issue that led me to this question. In my browser debugger I was getting this error message:
Access to fetch at 'http://localhost:8081/index.delta?platform=android&dev=true&minify=false' from origin 'http://127.0.0.1:8081' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
It took me awhile to realize I was using 127.0.0.1:8081 instead of localhost:8081 for my debugger.
To fix it, I simply had to change Chrome from:
http://127.0.0.1:8081/debugger-ui/
to
http://localhost:8081/debugger-ui/
My case is that when I tap enable remote JS debugging, it will launch chrome, but can not connect to it.
I have tried to run:
adb reverse tcp:8081 tcp:8081
, did but not work.
I uninstalled my chrome totally and install a new one. And it works.
The other answers here were missing one crucial step for me. In AndroidManifest.xml I needed to add usesCleartextTraffic:
<application
...
android:usesCleartextTraffic="true">
You probably don't want to keep this in the production release of your app though, unless you want to support insecure http requests.
After I added this to my AndroidManifest.xml, then I followed Tom Aranda's answer, and the emulator was finally able to connect to the debugger.
Make sure that the node server to provide the bundle is running in the background. To run start the server use npm start or react-native start and keep the tab open during development
react-native start --reset-cache in one tab and react-native run-android in another
adb reverse tcp:8081 tcp:8081 ( so you could add it to your scripts and just run yarn run adb-reverse)
If you're using android, Instead of shake your phone a great tip is run adb commands.
So you can run:
adb shell input keyevent 82 (menu option )
adb shell input keyevent 46 46 ( reload )
I did #sajib s answer and used this script to redirect ports:
#!/usr/bin/env bash
# packager
adb reverse tcp:8081 tcp:8081
adb -d reverse tcp:8081 tcp:8081
adb -e reverse tcp:8081 tcp:8081
echo "π§ React Native Packager Redirected π§"
uninstall your application, then run react-native run-android. then click debugging end in chrome replace http://localhost:8081/debugger-ui/, end run react-native run-android. if you still haven't succeeded try again
Inculding all impressive answers the expert developers specially Ribamar Santos provided, if you didn't get it working, you must check something more tricky!
Something like Airplane mode of your (emulated) phone! Or your network status of Emulator (Data status and Voice status on Cellular tab of Emulator configuration) that might be manipulated to don't express network! for some emulation needs!
I've overcome to this problem by this trick! It was a bit breathtaking debug to find this hole!
in my case it also need to install it's npm package
so
npm install react-native-debugger -g
Try adding this
package.json
devDependencies: {
//...
"#react-native-community/cli-debugger-ui": "4.7.0"
}
Terminate everything.
npm install
npx react-native start
npx react-native run-android
Reference: https://github.com/react-native-community/cli/issues/1081#issuecomment-614223917
Trouble shooting React native with React Cli and Typescript/js (Android Emulator)
Check if 'android/src/mai/assets/index.android.bundle' is available. If no Create index.android.bundle file in 'android/src/main/assets'
If above path not available then create the path then file
3.Run for bundling : react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
4.a. By default development server runs on 8081 port. Run 'react-native start' then on browser check if 'http://localhost:8081' and 'http://yourIP:8081' works. If yes then
Open application in Android Emulator (react-native run-android)
Click Ctrl + M
Select Settings
Select Debug Server Host and Port For Device
Add 'YourIPAddress:8081' e.g. 10.0.2.2:8081
4.b If http://localhost:8081 not working then run react-native port=8088(or any port)once successfully executed. Check on browser http://localhost:8088 and http://yourIP:8088 works. Yes then Open application in Android Emulator (react-native run-android)
Click 'Ctrl + M'
Select Settings-
Select Debug Server Host and Port For Device-
Add 'YourIPAddress:8081' e.g. 10.0.2.2:8088
YourIPAddress : Open command promt -> write 'ipconfig' -> copy IPv4 address
As for my own case , i was using the expo go and my android phone for my emulator and it was giving me this error.
so what i did was to clear the expo go app cache & data on my android device. it was working just fine
TL;DR:
If you created the app with expo cli with some native code or libraries not supported by expo, try this command in case the other solutions do not work.
npx expo run:android
Docs
My scenario:
I tried to run one of my old expo applications by building the app from Android studio and faced this issue. The other solutions mentioned didn't work. When I tried to use Expo Go to scan the QR, I got to know the error. Since I had used react-native-mmkv, I couldn't use expo-cli, I had to eject. So I ran npx expo run:android and everything started working fine.
The solution is to clear the expo go application data to solve the problem. Ref to: How to disable Remote JS Debugging in React-Native
Trying to create a react-native project on Android 4.4.2 I get this error screen
and couldn't find any way to resolve it. I tried restarting packager, reconnecting device, even reinstalling react native and starting new project. On 6.0.0 and later versions it works just fine.
A possible solution for this is that you most probably not bundling your application first, perform the following steps and then deploy your app-debug.apk to your device
$ cd myproject
$ react-native start > /dev/null 2>&1 &
$ curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
(if the folder assets does not exists create it)
Then run from project root
$> (cd android/ && ./gradlew assembleDebug)
install the created apk to you device, from location: android/app/build/outputs/apk/app-debug.apk
let me know if that fixes your issue
EDIT:
You can simply put it to your package.json as a script to automate it, I believe it will be fixed in upcoming releases of react-native and will be executed prior assembling the final APK, hence this won't be needed (I hope as well)
put :
"scripts": {
"build": "(cd android/ && ./gradlew assembleDebug)",
"start": "node node_modules/react-native/local-cli/cli.js start",
"bundle-android": "react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --sourcemap-output android/app/src/main/assets/index.android.map --assets-dest android/app/src/main/res/"
},
or as mentioned the curl equivalent, but for most cases the above is more robust
I came across this issue as well.
What I did was force kill the app on my device, then I opened up another console and ran
react-native start
and then I opened the app again from my device and it started working again.
EDIT: If you are using an android device via USB and have unplugged it or your computer went to sleep, you may have to first run
adb reverse tcp:8081 tcp:8081
Just got this error. Here's what I did to fix:
I selected Dismiss, Went into the Developer menu, then Dev Settings,
Choose Debug server host & port for device, I added my computers IP address and the port: 192.168.0.xx:8xxx, use whatever your developer machines assigned IP address is on your wifi network. The port is usually :8081
Once I did this, all went well. Also, while you're in the dev menu remember to select Enable Live Reload and Debug JS Remotely, it makes your life much-much easier while debugging.
This is what worked for me (After trying every other solution i found ...):
Run adb reverse tcp:8081 tcp:8081 inside \Android\sdk\platform-tools
I got this also when I started for the first time with React Native, using a physical device. If that's the case, you need to do some extra things before you can get started. You have to enter some information about your development machine in the 'Dev Settings' of React Native.
When you see the error, shake your device. A dialog will popup, the last option will be 'Dev Settings'. Select 'Debug server hot & port for device' and enter your local IP and the used port (usually 8081).
See the last paragraph of https://facebook.github.io/react-native/docs/running-on-device-android.html
If none of the solution work for you try this:
I found that my <root>/android/app/build/intermediates/assets/debug folder was empty and by running cd android && ./gradlew assembleDebug was not creating those files required, which are later used by javascript thread in our react native apps.
I ran manually the following command which the debug build command should have created ideally.
node node_modules/react-native/local-cli/cli.js bundle --platform android --dev true --reset-cache --entry-file index.android.js --bundle-output /<path to dir>/android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest /<path to dir>/android/app/build/intermediates/res/merged/debug
After running these commands I found two bundle files in this directory <root>/android/app/build/intermediates/assets/debug
And then a I ran again cd android && ./gradlew installDebug my app started working again.
Will debug more and would update what is failing actually.
In a separate terminal, connect your device to the computer and run the following commands:
react-native start
cd user/Library/Android/sdk/platform-tools/
./adb reverse tcp:8081 tcp:8081
Application terminal:
react-native run-android
install apk on your device from this location android/app/build/outputs/apk/app-debug.apk
It's little too late but this really works for me.
react-native run-android.
react-native start.
First command will build apk for android and deploy it on your device if its connected. When you open the App it will show red screen with error. Then run second command which will run packager and build app bundle for you.
see issue:
1.react-native start
2.click Reload(R,R) on your device.
Try this command in terminal and then reload. It worked for me
adb reverse tcp:8081 tcp:8081
restart the genymotion
run react-native run-android
the problem was solved
I was having the same exception on the device Z3 Compact D5803 - 6.0.1
I went opened the .buckconfig file and changed the line:
target = Google Inc.:Google APIs:23
to
target = Google Inc.:Google APIs:24
Because i saw in SDK Manager that Android 6.X has api level 24.
For me, it's because adb was not in the PATH. It's located /Users/man/Library/Android/sdk/platform-tools for me, it may be somewhere else for you, but anyway, find it and add it to your path to see if that help.
Since you are using Android < 5.0 you can't use the default adb reverse method, but Facebook has added official documentation to connect to the development server via Wi-Fi, which would support your version. Quoting the instructions for MacOS, but they also have them for Linux and Windows:
Method 2: Connect via Wi-Fi
You can also connect to the development server over Wi-Fi. You'll first need to install the app on your device using a USB cable, but once that has been done you can debug wirelessly by following these instructions. You'll need your development machine's current IP address before proceeding.
You can find the IP address in System Preferences β Network.
Make sure your laptop and your phone are on the same Wi-Fi network.
Open your React Native app on your device.
You'll see a red screen with an error. This is OK. The following steps will fix that.
Open the in-app Developer menu.
Go to Dev Settings β Debug server host for device.
Type in your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081).
Go back to the Developer menu and select Reload JS.
It had this issue "randomly" and took me sometime to realize what was wrong in my scenario.
After I have updated to React-native-cli 2.0.1, there was a message output to the log which helped me to dig and find the root cause:
JS server not recognized, continuing with build...
After researching some links I found this one:
Unable to recognize JS server
Since IΒ΄m on windows, I ran netstat and found out that my VLC player was also running on port 8081 causing the issue.
So, in my case, if I started the vlc server prior to the react-native server it wouldnΒ΄t work.
This same log message wasnΒ΄t output on previous versions of the react-native-cli, making it fail silently.
TL, DR: check if thereΒ΄s anything running on the same port as the package manager (8081 by default)
someone suggested the following one
react-native run-android
react-native start --reset-cache,
But in my case, I just close the cli command prompt window and used the following.
npx react-native run-android
and it worked fine.
My way are:
react-native start
After that in your device using:
click to Reload.
See in console react-native, it will be fetch js bundle data.
My issue was that I went through my AndroidManifest.xml file and had removed the line
<uses-permission android:name="android.permission.INTERNET" />
because my app will not need internet. However, the react native debugging app does need internet access (to access the packager) Whoops. :)
I had the same problem. When I did create a react native project via create-react-native-app AwesomeProject it worked well in Expo app on phone. After that I wanted to use that quickstart project for developing my project and got same error as you do.
After some research I find out it's better to start new project with react-native init AwesomeProject (with all setting in react native docs) Then run this command:
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
That should fix the thing with bundle (--dev false is not showing warnings)
All you need to do for app to run on your virtual / real device is:
react-native run-android
And it should be working just fine. At least it worked for me.
Try to clean cache
react-native start --reset-cache
Please check if you have following error when you run react-native run-android:
adb server version (XX) doesn't match this client (XX); killing...
In that case make sure /usr/local/opt/android-sdk/platform-tools/adb and /usr/local/bin/adb are pointed to the same adb
In my case one was pointed to /Users/sd/Library/Android/sdk/platform-tools/adb (Android SDK), but another was pointed to /usr/local/Caskroom/android-platform-tools/26.0.2/platform-tools/adb (Homebrew)
And issue have been fixed after both of them pointed to /Users/sd/Library/Android/sdk/platform-tools/adb (Android SDK)
I got this error too, really confused. cuz all answers does not work.
Just after add adb to path.
For me, I had side-sync enabled and active. Closing it imediately made the issue go away. It might be worth closing this or any other communication between PC and device
I ended up having to open up the port that I was using (8081 by default). On Linux, you can do the following
sudo iptables -A INPUT -p tcp --dport 8081 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 8081 -m conntrack --ctstate ESTABLISHED -j ACCEPT
You can test to see whether you actually need to do this. Just navigate to your dev server in Chrome on your Android device. If it doesn't respond, then this might be what you need. If it does respond, then this won't help you.
For me the problem was that 'adb' was not recognised - check this answer.
To fix this add C:\Users\USERNAME\AppData\Local\Android\sdk\platform-tools to Environment Variables
Most of us face this problem for the first time, when we start react native project#1.
Few simple steps solved my problem:
I created a sample project using command:
react-native init ReactProject1
Solution
The fix is to help local-cli\runAndroid\adb.js to find adb.exe, the same way as local-cli\runAndroid\runAndroid.js:
find replace statement under projectname(whatever you have given)\node_modules\react-native\local-cli\runAndroid
Replace:
const devicesResult = child_process.execSync('adb devices');
By:
const devicesResult = child_process.execSync( (process.env.ANDROID_HOME ? process.env.ANDROID_HOME + '/platform-tools/' : '') + 'adb devices');
after doing above replacement, just run react-native run-android in your cmd, it will bundle apk and at first try to install js bundle locally in your device. (Got Success)
"npm start"
I just closed the terminal and open a new one. Went to project location by cd command. And then just simply type - "npm start". and then 'r' for reload. Everything just vanished. I think everybody should try this at once.
I tried many of the suggestions above/below, but ultimately, the issue I faced was a permissions one with watchman, which was installed using homebrew earlier. If you look at your terminal messages while trying to use the emulator, and encounter 'Permission denied' errors with regards to watchman along with this 'Could not get BatchedBridge" message on your emulator, do the following:
Go to your /Users/<username>/Library/LaunchAgents directory and change the permissions settings so your user can Read and Write. This is regardless of whether or not you actually have a com.github.facebook.watchman.plist file in there.
I found that I needed to also add in a
react-native upgrade
to get the application to run correctly.
I got the same issue but it was a stupid mistake from myself...
From Android studio, I was launching installDebug/installRelease gradle script from app projet instead of root projet.
I'm trying to run AwesomeProject on my Nexus5 (android 5.1.1).
I'm able to build the project and install it on the device. But when I run it, I got a red screen saying
Unable to download JS bundle. Did you forget to start the development server or connect your device?
In react native iOS, I can choose to load jsbundle offline. How can I do the same thing for Android? (Or at least, where can I configure the server address?)
Update
To run with local server, run the following commands under your react-native project root directory
react-native start > /dev/null 2>&1 &
adb reverse tcp:8081 tcp:8081
please take a look at dsissitka's answer for more details.
To run without a server, bundle the jsfile into the apk by running:
create an assets folder under android/app/src/main
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
please take a look at kzzzf's answer for more details.
To bundle JS file into your apk while having your server running (react-native start) download bundle into assets directory of your app:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
With the next release (0.12) we'll fix react-native bundle command to work with android projects as expected.
The following made it work for me on Ubuntu 14.04:
cd (App Dir)
react-native start > /dev/null 2>&1 &
adb reverse tcp:8081 tcp:8081
Update: See
Running On Device (Android)
Device warning suppressed?
Update 2: #scgough We got this error because React Native (RN) was unable to fetch JavaScript from the dev server running on our workstations. You can see why this happens here:
https://github.com/facebook/react-native/blob/42eb5464fd8a65ed84b799de5d4dc225349449be/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java#L116-L137
If your RN app detects that you're using Genymotion or the emulator it tries to fetch the JavaScript from GENYMOTION_LOCALHOST (10.0.3.2) or EMULATOR_LOCALHOST (10.0.2.2).
Otherwise it presumes that you're using a device and it tries to fetch the JavaScript from DEVICE_LOCALHOST (localhost).
The problem is that the dev server runs on your workstation's localhost, not the device's, so in order to get it to work you need to either:
Forward traffic from (Device's localhost):8081/tcp to (Workstation's localhost):8081/tcp. That's what that adb command does.
Tell your RN app where it can find your dev server.
Ok, I think I've figured what the issue is here. It was to do with the version of watchman I was running.
In a new shell, run brew update
then: brew unlink watchman
then: brew install watchman
now, you can run react-native start from your project folder
I leave this shell open, create a new shell window and run: react-native run-android from my project folder. All is right with the world.
ps. I was originally on version 3.2 of watchman. This upgraded me to 3.7.
pps. I'm new to this so that might not be the swiftest route to the solution but it has worked for me.
* MORE INFO FOR RUNNING/DEBUGGING ON A DEVICE *
You might find that if you deploy your app to your Android device rather than an emulater you get a red screen of death with an error saying Unable to load JS Bundle. You need to set the debug server for your device to be your computer running react...either its name OR IP address.
Press the device Menu button
Select Dev Settings
Select Debug server host for device or Change Bundle Location
Type in your machine's IP and Reload JS plus the react port e.g. 192.168.1.10:8081
More info: http://facebook.github.io/react-native/docs/running-on-device-android.html
From your project directory, run
react-native start
It outputs the following:
$ react-native start
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Running packager on port 8081. β
β β
β 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
/home/user/AwesomeProject
React packager ready.
[11:30:10 PM] <START> Building Dependency Graph
[11:30:10 PM] <START> Crawling File System
[11:30:16 PM] <END> Crawling File System (5869ms)
[11:30:16 PM] <START> Building in-memory fs for JavaScript
[11:30:17 PM] <END> Building in-memory fs for JavaScript (852ms)
[11:30:17 PM] <START> Building in-memory fs for Assets
[11:30:17 PM] <END> Building in-memory fs for Assets (838ms)
[11:30:17 PM] <START> Building Haste Map
[11:30:18 PM] <START> Building (deprecated) Asset Map
[11:30:18 PM] <END> Building (deprecated) Asset Map (220ms)
[11:30:18 PM] <END> Building Haste Map (759ms)
[11:30:18 PM] <END> Building Dependency Graph (8319ms)
An easy solution that works for me with Ubuntu 14.04.
react-native run-android
The emulator (already launched) will return: Unable to download JS Bundle; start again the JS server:
react-native start
Hit Reload JS on the emulator.
It worked for me. Hope it will help
In the app on android I opened Menu (Command + M in Genymotion) -> Dev Settings -> Debug server host & port for device
set the value to: localhost:8081
It worked for me.
After trying out a combination of the answers here, this is what is working for me.
I'm using Genymotion as my emulator.
1 Start up Genymotion emulator.
2 From a terminal
cd AwesomeProject
react-native run-android # it loads in genymotion and fails with bundle error
react-native start > /dev/null 2>&1 & # from dsissitka
adb reverse tcp:8081 tcp:8081 # from dsissitka
3 Reload from emulator.
It loads!
I can now begin developing.
Delete the App from your phone! I tried several steps, but that did it eventually.
If you tried to run your app before but failed, delete it from your android device.
Run $ react-native run-android
Open the React Rage Shake Menu from within your app on your android device, go to Dev Settings and then to Debug server host & port for device. There enter your server IP (IP of your computer) and host 8081, e.g. 192.168.50.35:8081. On a mac you can find the IP of your computer at System Preferences -> Network -> Advanced... -> TCP/IP -> IPv4 Address.
Open the Rage Shake Menu again and click Reload JS.
Apparently adb reverse was introduced in Android 5.0
Getting "error: closed" twice on "adb reverse"
I guess we have to go ahead with kzzzf's answer
I don't have enough reputation to comment, but this is referring to dsissitka's answer.
It works on Windows 10 as well.
To reiterate, the commands are:
cd (App Dir)
react-native start > /dev/null 2>&1 &
adb reverse tcp:8081 tcp:8081
Here are the simple steps to run your app on android(release):
1. Go to your application root.
2. Run this command.
react-native bundle --platform android --dev false --entry-file
index.android.js --bundle-output
android/app/src/main/assets/index.android.bundle --assets-dest
android/app/src/main/res
All your files are copied.
3. Create signed APK.
Open android studio.
Build > Generate Signed APK > [Fill required details, keystroke has to be generated before this step]
Your APK should be generated without any errors. Install on your device and this should work without any issues.
You can also connect your device and directly hit Run icon on android studio for testing.
Generating Keystroke:
Goto C:\Program Files\Java\jdkx.x.x_x\bin
Run
keytool -genkey -v -keystore d:\my_private_key.keystore -alias
my-key-alias -keyalg RSA -keysize 2048 -validity 10000
It will probably ask you to fill in some details. Do it and your have your keystroke file(my_private_key.keystore) which can be used to sign your apk.
I was getting this on Linux after stopping down the react-native run-android process. Seems the node server is still running so the next time you run it, it won't run properly and your app can't connect.
The fix here is to kill the node process which is running in an Xterm which you can kill by ctrl-cing that window (easier) or you can find it using lsof -n -i4TCP:8081 then kill -9 PID.
Then run react-native run-android again.
Check your wifi connection.
Another possibility could be you are either not connected to wifi, connected to the wrong network, or the ip address is wrong in your dev settings. For some reason, my android disconnected from the wifi and I started to get this error, unknowingly.
Running on device
I have found another answer.
adb reverse: only work on Android 5.0+ (API 21).
Another: Open the Developer menu by shaking the device, go to Dev Settings, Go to Debug server host for device, type in your machine's IP address and the port of the local dev server
An update
Now on windows no need to run react-native start. The packager will run automatically.
One important thing to check that no one has mentioned so far:
Check your local firewall, make sure it's turned OFF.
See my response here:
https://stackoverflow.com/a/41400708/1459275
I am using Ubuntu and Android only, and I was unable to get it running. I found a really simple solution which is to update your package.json file, changing this lines:
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
},
to
"scripts": {
"start": "adb reverse tcp:8081 tcp:8081 && node node_modules/react-native/local-cli/cli.js start"
},
And then you run the server by typing
npm run start
This ensures the android device looks for the node server on your computer instead of locally on the phone.
The initial question was about reloading the application in a phyisical device.
When you're debugging the application in a physical device (ie via adb), you can reload the JS bundle by clicking on the top left "action" button of your device. This will open the option menu (Reload, Debug JS remotely...).
Hope this helps.
This error can easily resolved by following steps:
//run the command at /android sdk / platforms-tool folder
adb reverse tcp:8081 tcp:8081
//now come to root folder of your app
1. npm start
2. create 'assets' folder inside rootApp/android/app/src/main/
3. curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
4. make sure anyone physical or virtual device attached is running.
5. react-native run-android
You can follow the instruction mentioned on the official page to fix this issue. This issue occur on real device because the JS bundle is located on your development system and the app inside your real device is not aware of it's location.
In new React Native (for sure 0.59) debug config is inside android/app/src/debug/res/xml/react_native_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="false">localhost</domain>
<domain includeSubdomains="false">10.0.2.2</domain>
<domain includeSubdomains="false">10.0.3.2</domain>
</domain-config>
</network-security-config>
Start the two terminal on the same and 1st terminal run react-native start and second terminal react-native run-android this problem are solve in simply way. And best of luck
I found this to be weird but I got a solution.
I noticed that every once in a while my project folder went read-only and I couldn't save it from VS. So I read a suggestion to transfer NPM from local user PATH to system-wide PATH global variable, and it worked like a charm.
### Here is my solution
None of the above solutions can solve my problem but only follow the below steps working for me.
Add in network-security-config.xml file
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
</domain-config>
...
Then update AndroidManifest.xml file with
<application
+ android:networkSecurityConfig="#xml/network_security_config"
...
Hey I was facing this issue with my react-native bare project, the IOS simulator works fine but android kept giving me this error. here is a possible solution which has worked for me.
step 1, check if the adb device is authorized by running in your terminal : adb devices
if it is unauthorised run the following commands
step 2, sudo adb kill-server
step 3, sudo adb start-server
then check if the adb devices command shows
list of devices attached
emulator-5554 device
instead of unauthorized if it is device instead of unauthorized
step 4, run npx react-native run-android
this has worked in my instance.
Running npm start from react-native directory worked out for me.