react-native run-android hangs - reactjs

I am starting a fresh app with react-native, and following the getting started tutorial here. I have installed Android Studio, the sdk and avd files, and the react-native init seems to work ok...
react-native init myapp
>>
Installing React...
Installing Jest...
npm WARN deprecated minimatch#2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
Then I try and run the app
react-native run-android
And it just hangs there (even left it overnight).
If I do an strace
...lots of stuff then
read(12, "HTTP/1.0 200 OK\r\nServer: Motion/3.2.12+git20140228\r\nConnection: close\r\nMax-Age: 0\r\nExpires: 0\r\nCache-Control: no-cache, private\r\nPragma: no-cache\r\nContent-Type: multipart/x-mixed-replace; boundary=--BoundaryString\r\n\r\n", 65536) = 217
epoll_wait(5, [{EPOLLIN, {u32=12, u64=12}}], 1024, -1) = 1
read(12, "--BoundaryString\r\nContent-type: image/jpeg\r\nContent-Length: 4235\r\n\r\n\377\330\377\340\0\20JFIF\0\1\1\0\0\1\0\1\0\0\377\341\0\224Exif
And then keeps cycling with the line...
read(12, "--BoundaryString\r\nContent-type: image/jpeg\r\nContent-Length: 4235\r\n\r\n\377\330\377\340\0\20JFIF.....
I have tried things like reinstalling react-native, the sdks etc, but error persists.
I have also seen a similar error linked to watchman with react-native init, but I don't think this would apply, as I don't currently have that installed (have tried with it installed previously).
I am using Linux Mint 18
4.4.0-51-generic #72-Ubuntu SMP Thu Nov 24 18:29:54 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Ok, it was a camera application using port 8081 that was causing the issue.
If I kill that process it works. I checked the ports in use by
netstat -tulpn
look for port 8081 in there, then
kill -9 <pid>
Assuming it's something you are happy not to have running, and change its config.
Would be handy if react-native checks for a port in use and reports it if it is, to save others having the same issue.

If you're on Windows, you can try:
Ctrl + Alt + Delete to bring up the Task Manager
Select the "Node.js: Server-side Javascript" process
Click the "End Task" button
Then try the react-native run-android command again.
I hope it helps.

ran from Command Prompt as Administrator (that got the react-native start to run)
Then in the other command prompt when run-android I got after an extremely long wait: Could not determine java version from 10.
I upgraded gradlew in the [project]/gradle/wrapper/gradle-wrapper.properties to
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-src.zip
Then waited a long time for it to finish, seemingly doing nothing.
Got a filenullpointer exception in findLauncherJar...
Read further and changed to
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-all.zip
Then it hung with a message:
gradle refresh failed could not find com.android.tools buildg
Found SO 38702032 which suggested changes to the file Android/build.gradle and corrected the gradle version to 4.3.0
Got another error and went to http://jcenter.bintray.com/com/android/tools/build/gradle/ to see what versions existed. Found that the last was 2.3.3
Put it back to what it was and added mavenCentral
Also checked that I have the paths (C:\Users\MyUsername\AppData\Local\Android\Sdk\platform-tools;C:\Users\MyUsername\AppData\Local\Android\Sdk\tools)
and the three environment variables (c:\program files\java\sdk-10) and that I have the two ANDROID_HOME and ANDROID_SDK_HOME (c:\users\MyUsername\AppData\Local\Android\Sdk) ...
rebooting and works.

Related

Ionic build failed without specific error

After cloning my Ionic React project to my server, I ran npm install and all dependencies were installed as expected.
But when I tried to build my app running sudo ionic build --verbose, it tooks much more time than usual and ended like this :
eslint:lint-result-cache Persisting cached results: /var/www/html/ms-users-front/node_modules/.cache/.eslintcache +0ms
eslint:cli-engine Linting complete in: 4827ms +48ms
//It stay here for at least 10min before to failed while it tooks 1min in my local machine.
The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process.
[ERROR] An error occurred while running subprocess react-scripts.
react-scripts build exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
ionic:utils-process onBeforeExit handler: 'process.exit' received +0ms
ionic:utils-process onBeforeExit handler: running 1 functions +1ms
ionic:utils-process processExit: exiting (exit code: 1) +44ms
My server is an ec2 instance with httpd installed and everything was working great before I tried to build a new version yesterday.
With exactly the same process, the app is building perfectly on my local machine...
I tried npm update, delete eslint cache, and build but without success.
I tried to downgrade Typescript to 4.1 because I had a warning saying that Typescript should be >4.5 and it was 4.7. But after some tests on local, it looks like this has no incidence on the build process.
I'm totally stuck and I absolutly don't know what to try.

sudo npm run start Admin permissions error?

I am trying to run react application as sudo on port 443 but it is throwing permissions error as follows. I tried running the react script with root privileges too but get the same error.
Command used is
sudo npm run start
Error
? Admin permissions are required to run a server on a port below 1024. Probably:
/Applications/Google Chrome.app/Contents/Frameworks/Google Chrome Framework.framework/Versions/91.0.4472.114/Helpers/Google Chrome Helper.app/Contents/MacOS/Google Chrome Helper --type=utility --utility-sub-type=network.mojom.NetworkService --field-trial-handle=1718379636,2199499938256335430,15968884667410910440,131072 --enable-features=BlockInsecurePrivateNetworkRequests,CookieSameSiteConsidersRedirectChain,CriticalClientHint,CrossOriginEmbedderPolicyCredentialless,CrossOriginIsolated,CrossOriginOpenerPolicyAccessReporting,CrossOriginOpenerPolicyReporting,DocumentPolicyNegotiation,EnableNewCanvas2DAPI,ExperimentalContentSecurityPolicyFeatures,FeaturePolicyForClientHints,LangClientHintHeader,OriginIsolationHeader,OriginPolicy,SchemefulSameSite,UserAgentClientHint --lang=en-US --service-sandbox-type=network --enable-experimental-web-platform-features --metrics-client-id=22a9279b-1648-45cf-a03c-0ce68df69ad5 --shared-files --seatbelt-client=27 (pid 887)
in /
Would you like to run the app on another port instead? (Y/n)
I checked port 443 and it is available to listen. I also wrote a script to listen on port 443 on localhost and it is able to bind on this port as a sudo user. No luck with the react app though.
I was able to run react app earlier in the same laptop but something changed and I don't know what. The error is anyway about permissions but I ruled out this possibility.
I feel it has something to do with Google Chrome Helper which react-scripts is trying to run without Admin Privilege.
Also, it could be some other package I installed which may have caused the issue.
I am at a loss here and am not sure how to debug it further. Googling the problem didn't help either. Any help to debug or fix the issue is greatly appreciated. Thanks in advance.
Mac OS Big Sur - version 11.4
npm version 7.18.1
I was able to get around this issue, by using this package.json command:
{
"scripts": {
"start-https": "sudo PORT=443 HTTPS=true react-scripts start"
}
}
I met the same issue, and solved by downgrading the node version from 16 to 14, don't know why but works.
The only way I found it to work (especially when you install node and npm using nvm) is to call react-scripts directly:
sudo node ./node_modules/.bin/react-scripts start
This assumes you are in the project / repository directory containing .node_modules. Nevertheless, it is different question whether its correct to npm start with sudo. I was just experimenting to run the dev server on port 80 and it was giving error
Admin permissions are required to run a server on a port below 1024.
And I was unable to fix it with various solutions specified on these links: 1, 2, 3, 4. From these links I mostly tried configuration related solutions as I did not wanted to reinstall node (without nvm).

React Native: XCode: Build failed with error "EMFILE: too many open files, watch"

– MackBook Air M1
– macOS 11.3
– XCode 12.5
– react native 0.64.1
– node 16.0.0
– npm 7.15.1
– watchman 2021.05.31.00
When I try to archive a project or build one for a device, Xcode stops building with an error:
/Users/aptyp/Projects/Proffmylife/Client/node_modules/metro-hermes-compiler/src/emhermesc.js:81
throw ex;
^
Error: EMFILE: too many open files, watch
at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:204:21)
Emitted 'error' event on NodeWatcher instance at:
at NodeWatcher.checkedEmitError (/Users/aptyp/Projects/Proffmylife/Client/node_modules/sane/src/node_watcher.js:143:12)
at FSWatcher.emit (node:events:365:28)
at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:210:12) {
errno: -24,
syscall: 'watch',
code: 'EMFILE',
filename: null
}
Command PhaseScriptExecution failed with a nonzero exit code
But for the simulator, the build works fine.
I have tried to reinstall node_modules, Pods, watchman with brew. Also I've created files limit.maxfiles.plist, limit.maxproc.plist into dir /Library/LaunchDaemons/ and now ulimit -a shows processes 2000 and file descriptors 524288. Restarting computer and unlock Keychain.
On my PC with Hackintosh I don't have this problem.
This error is because of a bug in module fsevents for mac m1 silicon. See the thread: https://github.com/facebook/metro/issues/668
It got fixed with new version of watchman. Upgrade your watchman through brew. Delete your project and download from git and rebuild everything along with pod install and then it should archive no problem.
Facebook guy admitting to the bug and fixing it
I created a new project with the same name, installed all the latest packages and copied the code. Only after that the project was built success.

The app build fails when using React Native CLI

I am very fustrated. The React Native CLI is failing when building the app.
** BUILD FAILED **
The following build commands failed:
CompileC /~/Library/Developer/Xcode/DerivedData/third-eknrlzcnsdfzrlhgyioqgsamgxub/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/ConnectionContextStore.o /~/Projects/reactnativetest/third/ios/Pods/Flipper/xplat/Flipper/ConnectionContextStore.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC /~/Library/Developer/Xcode/DerivedData/third-eknrlzcnsdfzrlhgyioqgsamgxub/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/FlipperConnectionManagerImpl.o /~/Projects/reactnativetest/third/ios/Pods/Flipper/xplat/Flipper/FlipperConnectionManagerImpl.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC /~/Library/Developer/Xcode/DerivedData/third-eknrlzcnsdfzrlhgyioqgsamgxub/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/FlipperClient.o /~/Projects/reactnativetest/third/ios/Pods/Flipper/xplat/Flipper/FlipperClient.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC /~/Library/Developer/Xcode/DerivedData/third-eknrlzcnsdfzrlhgyioqgsamgxub/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/FlipperRSocketResponder.o /~s/Projects/reactnativetest/third/ios/Pods/Flipper/xplat/Flipper/FlipperRSocketResponder.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
(4 failures)
I did uninstall Xcode and install it fresh but did not make any difference, I got exactly the same error. The errors seem to be related with the Flipper library, but Flipper is installed as a pod in the ios/Pods directory.
Yesterday I tried Expo. The installation of the expo CLI took forever and it got hanging in the iTerm window, so I kill it. But then, when typing “expo whoami”, it gave me the asnwer of “Not logged in”, which means that Expo was installed. I was able to run the app in the ios simulator.
Today, when I tried to run the app again, I got the message that Expo was not installed. Weird, since I used it yesterday. I did the Expo cli installation again today and it did the same than yesterday. It has been more than 3 hours hanging in the terminal. But when I type “expo whoami”, I get the correct answer and I am able to run the app.
Also, today I did install the latest version of Android Studio 4.1.2 (I had version 1.3). After installation, Android Studio opens a window and then quits. I researched and it seems like Android Studio does not work on Mac version greater than 10.14 (Mac OS Mojave).
Why I am having so many problems just to run the app?. Anybody else having these problems?. Any solutions?.
If you are not using flipper just comment it out on the Podfile, that fixed the issue for me,
How to do it,
open podfile and make sure all this is commented,
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
# use_flipper!
# post_install do |installer|
# flipper_post_install(installer)
# end
update pods
pod update
That will fix it,
If you need flipper you'll have to specify use_flipper!({ 'Flipper-Folly' => '2.3.0' }) version and run pod install

Expo XDE for Windows hangs when i create a new project as react-native

11:19:13 PM
Starting React Native packager...
11:19:21 PM
Scanning 535 folders for symlinks in C:\data\TodoList\tasklist\node_modules (16ms)
11:19:21 PM
Loading dependency graph.
11:19:21 PM
Running packager on port 19001.
11:19:21 PM
11:19:38 PM
Dependency graph loaded.
when i create new project i get the aforesaid on console and then it hangs ? is there any prerequisits for this to run why i may have not installed ?
i assumed its the virus guard because kaspersky prompted a warning, but it still hangs even after the disabled it [the virus guard].
I solved this problem by this all. following are all required and after installing them expo-xde started.
1)Disable secure boot in BIOS
2)Enable Virtualization in BIOS.
3)Reinstalled Expo-XDE
4)Installed Python and JDK which is required according to documentation
5)Installed react-native cli using npm.
Restart your machine now.
6)Even if this doesn't work then install Genymotion as Android virtual device API-23 Marshmello, which comes with by-default Expo app and you can run npm run android from command line and enter url in Expo app in Genymotion.
complete steps of Genymotion(step 6), I followed from here.

Resources