My steps which I followed till now are,
react-native init FirstApp
cd FirstApp
started emulator from android studio
react-native start FirstApp
App started on emulator all fine
and then i changed on android js file, saved it and pressed rr to reload and then the red screen appears
Things I have tried,
running on different ports
set the ANDROID_HOME variable pointing to sdk folder both for system as well as user variable
I am working on windows os
close all terminals and then try this line in new terminal :
adb reverse tcp:8081 tcp:8081
and then run the project again :
react-native run-android
Related
Issue: This broke with no changes between days. Even though I have metro running npx react-native start when I run npx react-native run-android it starts it's own metro server and does not allow me to do "fast refresh" it basically installs the debug build of the app onto the device. I need it to fast refresh for development purposes.
Already tried the steps on issue: Unable to load script from assets index.android.bundle on windows
To test and debug my android build for a react-native project I had an emulator running in one Powershell window, would start a metro server in a second Powershell window using npx react-native start then run the app in a third powershell window using npx react-native run-android it would go through the build and install the app, then it would "pass" the app to the react-native metro server then that would install it to the emulator. This would allow me to make changes to the code and "fast refresh" the application in the emulator/phone and logs got outputted to the Metro Server.
Versions (executed at project root folder)
npx react-native --version : 6.0.0
npx --version : 7.18.1
Setup:
First Powershell window:
emulator -avd Galaxy_Nexus_Android9 -no-snapshot
Second Powershell window:
Make sure abd device is running
adb devices
result
List of devices attached
emulator-5554 device
run
npx react-native start
result: Metro JS Server Start
Third Powershell Window
run: npx react-native run-android
result: Run Android
I boxed the line where it launches its own JS server instead of using the one that is open.
The app opens fine on the emulator (I initialized a new app to make sure there was nothing wrong with the app) App Running Android
But on the Metro window, it did not install the app and when I try to reload it says it cannot detect any running apps Metro Restart
I've already tried the resolution here to run it on a different port with no success No apps connected. Sending "reload" to all React Native apps failed. Make sure your app is running in the simulator or on a phone connected via USB
Solution:
Run the start metro server and run-android commands on a different port.
I suspect McAfee was using the default port 8081.
Open admin CMD/Powershell and run the following:
Reverse the port that the adb device will listen on:
adb reverse tcp:8081 tcp:8090
Start the Metro server on the same port:
npx react-native start --port 8090
Open another admin CMD/Powershell window and run:
Start the android build/run on the same port:
npx react-native run-android --port=8090
The last command should also start the emulator automatically.
If the metro server errors out after you do the run-android command, just run the npx react-native start --port 8090 again in the same window.
The image describes my current situation properly. Please have a look at it first.
I am running my app on React Native. I have Android simulator on. I give the command to start the app. The app build finishes, but it says that virtual device not found, and in my simulator, if I open the app manually, it says that it cannot connect to Development server. It shows some issues.
Can anyone help?
Try run react-native run-android to connect your app to the emulator
Check USB Debugging is on(mostly running on virtual devices)
Check how you created project(react-native-cli or Expo) and run relevant app run command
Make sure your development server(node.js) is running when you run app. Sometimes it crashes then you have to again run command to run app
If all the step does not solve your issue try to uninstall app from device and run app again. Since react-native is still developing and its wired sometime these tricks works
I was having the same issue in Ubuntu 16.04. In my case the problem was that node packager wasn't running.
To check is packager is running easily you can open the browser and enter
http://localhost:8081/
You must see "React Native packager is running."
If you dont, then you can start packager from console running
react-native start
If you get an error like
" ERROR watch /your/project/path/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values-ru ENOSPC"
Then run first
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Then run react-native start again and press the letter R twice in the emulator to reload.
Looking at the screenshot, seems like you don't have adb installed because there is a clear 'adb: not found error'.
Luckily Android studio ships with adb and is present in platform-tools under your Android SDK. (generally in /home/your-user-name/Android/Sdk/)
You only need to use it. Create a symbolic link in '/usr/bin/' or '/usr/local/bin/' depending how you'd like to use it.
Run the command:
sudo ln -s ~/Android/Sdk/platform-tools/adb /usr/local/bin/
After this run the app.
I have installed the development environment for react native on Windows 7 using the instructions here.
I have installed the following packages:
Python 2.7
node 4.2.4
npm 2.14.12
react-native-cli 0.1.10
react-native 0.18.0-rc
Android SDK
I can generate a skeleton project using the command react-native init Test.
However, when I execute the command react-native run-android, the following error occurs: Unable to install path\to\app-debug.apk.
The device, a Samsung Galuxy running Android 5.0.1, is connected to my PC and USB debugging on the phone has been enabled. When I type adb devices the phone appears in the list.
I can download the apk to the phone manually using the command adb install. However, when I run the app, a red screen appears with the error "Unable to download js bundle." This error persists even after I do the following:
Start the local development server using react-native start
Executing the command: adb reverse tcp:8081 tcp:8081
On the phone, setting the debug server host and port to localhost:8081
Update: I have solved one problem by downloading gradle to version 1.2.3 as described here. However, the red screen still appears with the error Unable to download js bundle.
What could be the problem?
You are working fine. for this problem have added the IP address in device Setting server host. one more thing your machine and device should have on same network.
I'm trying to do the react native 'hello world', and I'm using usb debugging on my android.
I ran react-native run-android, then react-native start.
I can view the js file in localhost, but get 'could not connect to development server' message on my phone.
I followed the instructions to run adb reverse tcp:8081 tcp:8081, then realized that command doesn't exist, so I ran adb forward tcp:8081 tcp:8081 instead.
Still no luck. Using react-native#0.22.0, ubuntu 14.04. My phone is nexus 5 on android 6.0.1.
How can I allow my phone to access my localhost?
By the way, it is working over wifi, but I'd like to get it working over usb.
Just another scenario, this error happened to me when I forgot to run react-native start command. I usually follow the steps here when I start new project. The steps in a nutshell are as follows (Android in my case):
Start Android Studio -> AVD Manager -> select your aVD and click Start from action
inside the directory where you want to create your new project, open your command line and run:
$ react-native init <Your new project name/it is also the registration name>
$ cd <the new directory you created>
$ react-native start //This is the step that I forgot
Open a new command prompt and run the following inside the same directory(you just created) to launch the app on your AVD.
$ react-native run-android
If everything is set up correctly, you should see your new app running in your Android emulator shortly.
You'll find in the file index.android.js in the home directory of your project, the last line contians the App registry using the same name you used in the first command above
adb reverse tcp:8081 tcp:8081 Only works for android 5.0 + for running app on devices with android versions lesser than 5.0 hit following command after npm start is done in Terminal (in app directory folder).
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
now run the app, it will work. Only drawback is that every time you make a change you need to fire the command again and run the app again.
I found the solution :)
I am on ubuntu 16, so, I used command ip addr show which gave me my computer ip address.
I used this ip address and I was able to access localhost on my mobile.
Finally I added the ip address and port no to devsettings of android phone and My app was able to access development server
10 mins ago I had the same problem I guess, and the way I solved this was reading this
https://facebook.github.io/react-native/docs/running-on-device-android.html
and when I did that, I found that I didn't have android-tools-adb installed,
so looking around I found
'No command 'adb' found' error on Ubuntu
which gives me the answer
sudo apt-get install android-tools-adb
and after all this I set
export PATH=${PATH}:~/android-sdk-linux/tools
export PATH=${PATH}:~/android-sdk-linux/platform-tools
then everything works fine, now I can see my app in my Android device.
BTW the option I choose from react native docs was the one that says me
"Using adb reverse
Note that this option is available on devices running Android 5.0+ (API 21).
Have your device connected via USB with debugging enabled (see paragraph above on how to enable USB debugging on your device).
Run adb reverse tcp:8081 tcp:8081
You can use Reload JS and other development options with no extra configuration
I am having seen the same issue, and that's all because the android app don't have this permission:
<uses-permission android:name="android.permission.INTERNET" />
I had a similar problem. I would get this error when trying to get it to run on device. It was working fine on my simulators on my computer.
The problem was when I would do adb devices or react-native run-android I would get "ADB is Not Recognized as an internal or external command".
So my fix was to add the path to adb.exe's parent directory to my Environment Variables and then restart my command prompts. After I did that, adb devices would not throw the "unrecognized internal external blah" and it listed my device. I then ran react-native run-android and on startup no more red screen showing the completely useless error message Error calling AppRegistry.runApplication! :)
So I found ADB was located in my folder:
C:\Users\dell\AppData\Local\Android\sdk\platform-tools\adb.exe
I am on a Windows 10 system. dell is my user name of the computer.
So I went to System Environemnt Variables then found "Path" then clicked "Edit", then clicked "New" and added in "C:\Users\dell\AppData\Local\Android\sdk\platform-tools".
I am using Mac OS X and an Android Phone 4.4.2
When I deploy the sample AwesomeProject app to the phone I get a Red warning screen which says "Unable to download JS bundle. Did you forget to start the development server or connect your device?"
However, I have started the local dev server and connected the phone to the same wifi. Moreover, when I type "adb devices" I can see my device.
Also I added the IP and port of the server under Dev settings.
I found an advice online to type adb reverse tcp:8081 tcp:8081 but my phone is not android 5.0 which is btw minimum required for dab reverse command.
How should I make it start, please help...
Follow this steps carefully.
Note : All commands need to run inside a project only.
Run below command first
npm react-native start
open other window in same project and Run below command
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
This will create index.android.bundle in assets folder.
Run below command
npm react-native run-android
Now you can get apk in build folder which will work fine.