React Native failed to compile giving Error on the Device - android

I'm new to the React Native application development. When I after creating project and configured my device, It gives error like below and stop responding.
BUILD SUCCESSFUL in 27s
26 actionable tasks: 1 executed, 25 up-to-date
'C:\Users\Amila' is not recognized as an internal or external command,
operable program or batch file.
info Starting the app (C:\Users\Amila Eranda\AppData\Local\Android
\Sdk/platform-tools/adb shell am start -n
com.awesomeproject/com.awesomeproject.MainActivity...
Starting: Intent { cmp=com.awesomeproject/.MainActivity }
It shows build is success but there is an error on the Device saying
Unable to load script. Make sure you're either running a metro server...
running the adb devices command shows there is a device connected to my PC. But it fails running it in the Device.

That error on your device means that your device cannot connect to the metro server running on your computer to get the js bundle. The app on your device is a temporary app used by react native to quickly download the javascript code from your computer and convert it to code your device can understand each and every time you make changes to your code. Your device must be connected to your computer either on the same wifi network (with metro bundler running in a terminal window on your computer) or through a usb cable (with usb debugging enabled on your device and adb reverse set on a command prompt on your computer).
Read this from the android documentation to find out how to enable developer options on your android device: https://developer.android.com/studio/debug/dev-options
If your android device lets you, you can create a hotspot and have your computer connect to it if you do not have wifi available and usb debugging does not work for you.
Read this from the react native documentation: https://facebook.github.io/react-native/docs/running-on-device#connecting-to-the-development-server-1

Related

"Error connecting to the service protocol: failed to connect to http://..." after running adb reverse command

I have a flutter app that I debug on real device, and it runs fine in the debug mode.
I got to a point when I created a backend server that runs in a localhost:8080 only machine, so in order to make it accessible from my real phone device also, I ran:
adb reverse tcp:8080 tcp:8080
and it worked exactly as I expected where the app was running.
But, after this, if I re-rerun the app again in the real device ( unplug and plug again the USB in the machine ), it got to the point of showing the √ Built build\app\outputs\flutter-apk\app-debug.apk. and this error got thrown and it terminate/close the debug process of the app :
Error connecting to the service protocol: failed to connect to http://127.0.0.1:61410/DHX5GEb2kn4=/
I did try to kill the adb.exe command with:
adb kill-server
supposing that this will undo the adb reverse command but the same error gets thrown
well, I found a painful fix, which is restarting the device, but this takes much time and is painful.
I want to know what should I turn on/off while debugging my flutter app
I finally managed to fic the issue, and get my app debugging properly again.
What I did wrong ?
When I needed the adb, I thought it's not installed on my laptop since when I runned adb command in command line tool (cmd), it tells me that it's not recognized, so the smart me did downloaded the android platforms-tools separatly from Here
, and I runned the :
adb reverse tcp:8080 tcp:8080
from it's folder, which runned, and I thought I solved the issue, but what I just learned is that the Dart VM server uses an internal installed another adb.exe which have a different version (39) that what I run the command with (41).
so when I re-debug the flutter project, the error happens.
How did I fix it?
I did simply searched for the internal adb.exe, you can find in the Android folder, ...\Android\SDK\platforms\tools\adb.exe.
I Paste the new adb.exe with the height version inside the folder.
Run the command from that folder
For 3., you can set the path of that folder in the PATH in environment variables, so you can run the adb commands from anywhere.

react-native run-android not detecting emulator or device

When I run react-native run-android to run my React Native app I get this error and then the build fails:
'C:\Users\Alex\AppData\Local\Android\Sdk/platform-tools/adb' is not recognized as an internal or external command,
operable program or batch file.
error Failed to launch emulator. Reason: Emulator exited before boot..
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
I get this error whether I run the command with my phone connect by USB or if I run it with the emulator open from Android Studio. However, when I run adb devices both the emulator and my device show up.
I am pretty sure it is not a problem with the React Native code because I have tried running multiple different apps and get the same error.
Does anyone know what could be the problem and why the device and emulator aren't detected?
The problem was that my computer's antivirus had deleted adb.exe so once I reinstalled the platform tools folder containing adb.exe, react-native run-android worked as normal and my connected device was detected.

Running Emulators on Different Device for React Native Applications

Since Xcode and Android studio consume a lot, I am having storage and processing capacity issues on my Mac, while developing React Native Applications.
My Question is that is there any way to run emulators (in my case android emulator) on another PC, while I am coding on Mac?
Thank you
I tried once the solution below, it might also work for you. And the source is in this repo.
If you want to write and compile an Android application on one machine and debug it remotely on the emulator launched on another follow the instructions below:
Preparation
First of all you need to install SSH server on your remote machine.
Ubuntu
You can use OpenSSH.
sudo apt install openssh-server
Windows
You can install OpenSSH on Windows following this link.
Connection
Now you must connect local machine to remote server using SSH tunnel.
The emulator listens on two TCP ports per instance: 5554 for the telnet interface and 5555 for control communication with tools like DDMS. So you could probably get away with only forwarding port 5555. Each subsequent emulator takes the next available even+odd port number tuple.
Note that you need to enter the ip address of emulator running on remote server instead of emulator-ip and also remote machine username and hostname instead of myuser and remote-server.
Ubuntu
On the local machine try:
ssh -NL 5554:emulator-ip:5554 -L 5555:emulator-ip:5555 myuser#remote-server
Windows
Follow this link instructions and add two source ports and destinations below:
Source port: 5554
Destination: emulator-ip:5554
Source port: 5555
Destination: emulator-ip:5555
then connect to remote server.
ADB
The emulator tries to notify a local adb server at startup; hence you need to restart adb in order for it to probe the local 5554+ ports.
adb kill-server; adb devices
adb devices shows a new emulator — emulator-5554 — and you can use it as if it is running on your local machine.
Running
Finally run:
react-native run-android
the app should be installed on emulator, but you may face an error:
error: more than one device/emulator
Could not run adb reverse: Command failed: path/to/sdk/adb -s emulator-5554 reverse tcp:8081 tcp:8081
you need to specify your debug host IP and port in app's Developer menu -> Dev settings -> Debug server host & port, that is your local machine ip address and 8081 for port.
Note that after APK installation you don't need to do any of these steps. You can just start the npm server: npm start in the project directory of your local machine, run the app on the emulator in remote machine and then reload.
if there was another error:
Exception in thread "Device List Monitor" java.lang.NullPointerException
try:
react-native run-android --deviceId

Generic Ionic app doesn't load in AVD

My android virtual device starts up fine. But when it goes to load my ionic app it says: "app-name has stopped", "Open app again" after opening the app several times it says: "app-name keeps stopping close app". My app is the base tabs ionic app.
Ionic even says launch success...
I've tried different AVDs but none have worked. Here are the stats on my current one.
I've tried running it in with ionic run android -c -1 but all it says is
emulator: Requested console port 5584: Inferring adb port 5585.
emulator: Listening for console connections on port: 5584
emulator: Serial number of this emulator (for ADB): emulator-5584
EDIT: it works on Ionic serve just doesn't load on the android virtual device.
check if you have a service using that port or a program like skype that uses that port, then close or change the port it uses.
i had to close xampp in order to emulate android.
Checking use host GPU in the android SDK manager solved the problem for me.

React Native Android app failed to boot up : can't find variable

I don't modify any part of app; I just exec following cmds on macOS:
react-native init ***
cd ***
react-native run-android
I tested on both emulator and Samsung Galaxy note 3 both are the same.
also tried adb reverse.
My $PATH is
/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/mohammad/Documents/sdk/platform-tools/:/Users/mohammad/Documents/sdk
Then I get these errors in app (as in image):
ReferenceError: Can't find variable: require (http://10.0.3.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:15)
Try the following to fix the issue:
• Ensure that the packager server is running
• Ensure that your device/emulator is connected to your machine and has USB debugging enabled - run 'adb devices' to see a list of connected devices
• Ensure Airplane Mode is disabled
• If you're on a physical device connected to the same machine, run 'adb reverse tcp:8081 tcp:8081' to forward requests from your device
• If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:8081
loadScript
JSBundleLoader.java:66
runJSBundle
CatalystInstanceImpl.java:177
call
XReactInstanceManagerImpl.java:906
call
XReactInstanceManagerImpl.java:899
run
MessageQueueThreadImpl.java:74
handleCallback
Handler.java:739
dispatchMessage
Handler.java:95
dispatchMessage
MessageQueueThreadHandler.java:31
loop
Looper.java:135
run
MessageQueueThreadImpl.java:196
run
Thread.java:818
The problem is cannot connect the packager server of react native and device (or) simulator.
To solve this problem, need to connect the packager server and device (or) simulator.
react native is default use adb reverse tcp:8081 tcp:8081 to connect the packager server and device (or) simulator.There has a some problem in under android 5.0 because adb reverse is not support under android 5.0. However, react native is also support with using same wi-fi network.
To Solve
android 5.0 (or) Above
Need to check the packager server is running or not. ( Some OS not run automatically like ubuntu, but you can run react-native start in your project directory. )
Need to connect device (or) simulator. ( If your using devices, need to connect your device and computer, and sure to open USB debugging mode. If your using simulator, sure to open simulator. ), ( You can check is step complete or not using adb devices command )
Run again react-native run-android (or) open dev menu of react native and press Reload.
below android 5.0
Need to check the packager server is running or not. ( Some OS not run automatically like ubuntu, but you can run react-native start in your project directory. )
Need to connect your device and computer on same wi-fi network. And add packager server IP on your device's dev menu > Dev Settings > Debug server host & port for device like xxx.xxx.xxx.xxx:port)
Run again react-native run-android (or) open dev menu of react native and press Reload.
Open Dev Menu
Devices
Press Menu button (or) shake device.
Simulator
Press Ctrl + M (or) Cmd + M.
Find Packager Server Host
Computer's IP. ( On unix use ifconfig in terminal (or) On Window use ipconfig. )
Port ( Can find on Packager Server Terminal like localhost:8081 )

Categories

Resources