Getting Building iOS bundle error when trying to build an android app - expo -react-native - react-native

I was able to build app using expo build:android previously. However, after upgrading to latest expo version I get following error:
connect ECONNREFUSED 127.0.0.1:19001
Set EXPO_DEBUG=true in your env to view the stack trace.
I also see the following lines in the log:
Publishing to channel 'default'...
Building iOS bundle
I don't added ios to my app.json, I only need to build an android apk. To do that I use expo build:android -t app-bundle
I also removed package-lock.json and node_modules and run npm install, but I get the same error.
I run expo start on another cmd and then run expo build:android -t app-bundle still get same error
Also when I clear expo cache, see the following log:
Restarting Metro Bundler...
Starting Metro Bundler on port 19001.
Couldn't adb reverse: adb.exe: error: Invalid source port: 'undefined'

I had faced same issue myself and found the solution. Expo is looking for localhost:19001 which is not running. Just follow following steps and it should work as expected:
Run expo start no terminal and once it opens up the
browser where you will find this line written Starting Metro
Bundler on port 19001.
Now open another terminal instance and run expo build:android.

Related

Expo won't start the simulator / emulator

I always used to start my Expo project by typing in the terminal expo start and then i (for iOS simulator). The day after iOS 16 got released, Expo started to behave differently. After running expo start it gave me a warning: This command is being executed with the global Expo CLI. Learn more: https://blog.expo.dev/the-new-expo-cli-f4250d8e3421
To use the local CLI instead (recommended in SDK 46 and higher), run:
› npx expo start and after pressing i it threw the following error:
Error running xcrun simctl help: You may need to run sudo xcode-select -s /Applications/Xcode.app and try again.
XDLError: You may need to run sudo xcode-select -s /Applications/Xcode.app and try again.
Unable to verify Xcode and Simulator installation. After this I killed the terminal and in a new one I decided to follow the command it gave me in the warning (after running expo start). I ran npx expo start and then i and it threw me a new error which was:
Unable to run simctl:
Error: xcrun exited with non-zero code: 72
CommandError: xcrun is not configured correctly. Ensure sudo xcode-select --reset works before running this command again., but this time it didn't gave me a warning before pressing i. I also tried to run the commands shown in the errors and re-run the app, but still the same errors were thrown. I updated my OS, XCode and also deleted and cloned the project again so i could re-install dependencies just in case something was wrong with them.
I have attached the GitHub repo link of one of my projects so you can test it as well. It's not just this project, it's all of the projects I use Expo, even the new ones won't start.
If anyone has any idea how to fix this and why this happens, I would really appreciate it :)
Uninstalled and re-installed Expo globally. Updated the simulator to iOS 16 and opened the simulator before running expo start. It works as it did before.

How to run react-native app on Android emulator (or a physical device) in Android Studio?

I'm trying to run my react native app on either an Android Studio emulator or my physical device. I've followed the instructions at https://reactnative.dev/docs/environment-setup under the React Native CLI Quickstart tab, and initialised the 'AwesomeProject' app from that page, but I'm finding the instructions unclear. For instance it says do the following on the command line: npx react-native start which starts up a process of some sort. Then it says to enter: npx react-native run-android, but the command line is blocked by the previous process. If I try the latter either in another command prompt or without first running the former command, I get an error Unrecognized command "run-android". I should say I have an emulator running from Android Studio before doing all this.
So failing getting it running via the react-native CLI, how do I get it running from within just Android Studio? I've never used Android Studio before, so I have no idea what the process is. Googling hasn't helped either. But as I said, I have managed to get an emulator installed and running.
Any help getting this going either via react-native CLI or from within Android Studio would be greatly appreciated.
edit: I've found how to run my app in Studio, but it pops up an 'Edit configuration' dialogue and says there's no Module selected. But in the module dropdown box there's nothing to select.
You can try following the below steps:
Make sure that you have 2 environment variables set in your system.
ADB variable which is set to the path of "platform-tools" in your system like below:
ANDROID_HOME variable set to SDK path, where android was installed.
Now execute below commands in command prompt and start you emulator or connect your phone which has development settings ON before this:
Open your command prompt in admin mode.
Delete node_modules folder
Execute: npm install
Execute: npm install -g react-native && npm install -g #react-native-community/cli
Execute: npx react-native init
Go to android folder in your react-native project and execute: npx gradlew clean
Come back to main folder and execute: adb reverse tcp:8083 tcp:8083. (You need to check the status of your connected devices by executing adb devices. It will show you the connected devices.)
You also need to make sure that your index.bundle is created. If not than you may create it by executing: npx react-native bundle --platform android --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --dev false --reset-cache --assets-dest android/app/src/main/res/
Finally execute: npx react-native run-android --port=8083

"could not connect to development server" error running React Native tutorial with Expo, suspecting Watchman

New to react native and mobile dev, running into this problem:
I am running the React Native hello world from the Facebook Website using Expo CLI as the build tool. What I did was to install Expo, run expo init test, install cocoapods, and cd into the test directory and run expo start.
When I open the app on iOS simulator or my iPhone, I get "Could not connect to development server" after about 3-5 minutes in white screen (see screenshot).
In the Expo logs. It is notable that upon every startup I get the following error logs:
2019-08-25T21:49:21,474: [cli] Failed to open /Users/nsadeh/Library/LaunchAgents/com.github.facebook.watchman.plist for write: Not a directory
ERROR
21:49
Watchman: watchman --no-pretty get-sockname returned with exit code=null, signal=SIGABRT, stderr= 2019-08-25T21:49:21,474: [cli] Failed to open /Users/nsadeh/Library/LaunchAgents/com.github.facebook.watchman.plist for write: Not a directory
I have already tried un- and reinstalling Watchman as well as Expo. Not sure what else to do.
To reproduce:
macOS Mojave 10.14.6
node v10.16.3
expo 3.0.10
Watchman 4.9.0
react-native 0.59.10
Run expo init and from the top directory expo start.
Solution: turns out that postgreSQL left an unrelated LaunchAgents.plist file in my Library that was confusing Watchman. Renaming it resolved the issue.

Failed to load bundle - Could not connect to development server

I've been looking for a solution to this issue for a day now but couldn't fix it.
I have not used react native for a month when everything was working fine.
Now, if I try to run an existing project that used to work (react native 0.59.5) or a brand new project (react native 0.59.9) with the iOS simulator on my mac, I get the error:
Failed to load bundle - Could not connect to development server
Any idea how I can fix this?
Ok found the issue. Was thinking it might be watchman related issue and wanted to use the command brew reinstall watchmanto reinstall it. By running this command, I found an error
Error: Xcode alone is not sufficient on Mojave. Install the Command Line Tools: xcode-select --install
Looks like the command line tools for xCode was not available anymore.
I launched the command xcode-select --install and then reinstalled watchman just in case. It is now working!
Couldn't connect to development server error
This error is received when the metro bundler isn't running in port 8081. To start the bundler, from project folder run:
npm start
Now, try reloading your app (ctrl + R for iOS / r+r for Android).
Also, check your terminal in case the project failed initial build due to some error.

native_modules.gradle file is deleting as soon as react-redux is installed

I have created an app in react native for my project. When I copy my projects file in the app folder then run the app it said that in node_module react-redux does not exist then I installed react-redux using npm install react-redux#7.0.3 in my app folder after that when I run run-android command in command prompt for this project it is telling that -
Could not read script 'E:\AppFolder\MyApp\node_modules\#react-native-community\cli-platform-android\native_modules.gradle' as it does not exist. .
After that, I wiped the data of emulator and run run-android, but it is still giving me the same error and app is not installing in the emulator.
Here is the error which command prompt is displaying :
info Building and installing the app on the device (cd android && gradlew.bat app:installDebug)...
Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details
FAILURE: Build failed with an exception.
* Where:
Settings file 'E:\AppFolder\MyApp\android\settings.gradle' line: 4
* What went wrong:
A problem occurred evaluating settings 'TribeBond'.
> Could not read script 'E:\AppFolder\MyApp\node_modules\#react-native-community\cli-platform-android\native_modules.gradle' as it does not exist.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 10s
error 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:
https://facebook.github.io/react-native/docs/getting-started.html
error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details.```
Here I follow these steps to solve my problem-
I build a new app and run it using react-native run-android command.
Then I installed all dependencies one by one, which is going to use in the app.
Then run npm install command in the project.
After that, I re-build the app using react-native run-android.
And Tada! the app is re-built without any error.