When I run 'npx cap sync' the terminal just hangs - ios

I run the following commands on my M1 Macbook in my terminal to prepare a build for my phone to test it on xcode. First I do ionic build which works fine. Then I run npx cap sync which works until it gets to this line:
⠙ update ios [info] Found 5 Cordova plugins for ios:
com.adjust.sdk#4.30.0
cordova-plugin-email-composer#0.10.0
cordova-plugin-globalization#1.11.0
cordova-plugin-ionic#5.5.2
cordova-sqlite-storage#6.0.0
⠹ Updating iOS native dependencies with pod install
Then the terminal just hangs, there's no error message. I've tried leaving it but nothing seems to happen. I experience this issue regularly which is frustrating as I need to test my code on my device.
I've tried running sudo arch -x86_64 gem install ffi and then arch -x86_64 pod install in ios/App which both run fine but doesn't seem to fix the above issue.
Sometimes if I delete the ios folder, run npx cap sync then reinstall the ios folder using npx cap add ios. I'll be able to get a build on my phone but this only works sporadically.
I'm looking for a consistent solution to the problem.

Since it is an ionic project one other thing you can try is to run ionic sync command:
ionic cap sync

For me the solution was to reinstall Xcode and delete all Xcode related files. It still takes time to sync but now works consistently.

I actually found since I asked this that moving to a more powerful macbook pro with more RAM actually solved the issue and my terminal no longer hangs. I think my old machine just couldn't handle doing the builds and xcode with the juice it required. Occasionally it will throw an error along the lines of cocoapods but running sudo arch -x86_64 gem install ffi and then arch -x86_64 pod install in ios/App solves this.

Related

React Native iOS build keeps randomly failing since moving from Intel/Big Sur to M1/Monterey

I've got a MacBook Pro with M1/Monterey which fails to build an RN project.
The build failure doesn't always manifest in the same component, it could be one of several, here's a couple of examples:
Pods.build/Release-iphoneos/FBReactNativeSpec.build/Script-5F4C70EF7D90A5A5BDAEB55666d9F232A.sh:
line 60: 53999 Killed: 9 "$NODE_BINARY"
"$CODEGEN_CLI_PATH/lib/cli/combine/combine-js-to-schema-cli.js"
"$GENERATED_SCHEMA_FILE" $JS_SRCS Command PhaseScriptExecution
failed with a nonzero exit code
When the failures start I've tried dozens of different things to attempt to see what might fix it. Sometimes one thing might fix it, but then next time it won't, sometimes a combination of things might fix it, but then next time that same combination won't. There's no repeatable pattern of steps that will fix the issue. Here's some of the things I'll do, usually all or many of them at once in-between builds:
Clean build folder in Xcode
Delete derived data
Close and re-lauch Xcode
Terminate Metro
Run "yarn start --reset-cache"
Delete the pods and node_modules folders
Run all commands natively and launch Xcode using not using Rosetta i.e. run "yarn -install" and "pods install" etc.
Run all commands with x64 and launch Xcode using Rosetta i.e. run "arch -x86_64 yarn install" and "arch -x86_64 pod install" etc.
Run "rm -rf ios/build/"
Run "kill $(lsof -t -i:8081)"
Run "brew reinstall gettext"
Run "brew reinstall pcre2"
Run "brew reinstall git"
Run "brew install watchman
Run "nvm alias default some node version"
Tried different versions of node
Rebooting the laptop
and more
For 2 weeks I've been trying everything and anything once a build starts to fail to experiment to see what might make the build work again. After all that time there's nothing that does. Its just seemingly random if it starts working again.
I can literally spend hours trying all of the above and the build just won't succeed. Then maybe I'll repeat a step again, and it will. Then things will be fine for a few hours, then it'll start failing again.
I'm using Monterey 12.2.1 and Xcode 13.2.1.
If I build the same project using on my old laptop and also using Xcode 13.2.1 I don't have any of these problems.
This is driving me insane, does anybody have any idea what the problem could be? My new laptop is effectively useless.
I dont know if this might help but I've added the following to my npm scripts in package.json because of how often I run it:
watchman watch-del-all && cd ios && rm -rf Pods Podfile.lock && pod install && cd ..

React Native Invalid Podfile file: [!] Unable to locate the executable node

I'm using Macbook pro-2020 apple M1 Chip, I have created a new ReactNative project and it runs fine on the simulator but if i have to install any other plugins, and have to install pods. it gives me errors like this.
i have installed all the requirements app running fine but once it comes pod installs it fails each and every time. any help would be much appericiated.
I believe this has been answered in how-to-running-cocoapods-on-apple-silicon-m1
I recommend following the updated answer for 2022. If you haven't already, use Homebrew, even tho it's not recommended by the maintainers. M1 with ARM architecture is amazing but many libraries are still not compatible and need to be run in x86 mode.
I would uninstall everything, including and gems you used originally, and run the following Homebrew commands and link them all....
brew install node
brew install yarn
brew install cocoapods
Reinstalling those should now work when you run pod install inside your ios file. This is what worked for me. Hope this helps.
I was facing the same error, this is what worked for me:
I first reinstalled the node, yarn, CocoaPods, after that I run the following commands:
brew link cocoapods
If still gives you error, remove old linked pod using following command:
rm '/opt/homebrew/bin/pod'
Now run this command again:
brew link cocoapods
Once the above command works successfully, then move to your project's iOS folder and run the following command:
pod install

Build is failing for older projects for React-Native iOS XCode Version 12.5

It is very new to me see this problem which started happening recently. Previously my app used to work fine on the iOS simulator by running this command react-native run-ios. Now I have done a lot of research and made my app run via XCode. But somehow the metro bundler is not linked when the app runs via XCode.
I tried running the app via react-native run-ios and every time I am seeing this error. It is too big to copy paste every error here, but here are some of them:
Undefined symbols for architecture x86_64:
"Swift._ArrayBuffer._copyContents(initializing: Swift.UnsafeMutableBufferPointer<A>) -> (Swift.IndexingIterator<Swift._ArrayBuffer<A>>, Swift.Int)", referenced from:
generic specialization <serialized, Swift._ArrayBuffer<Swift.Int8>> of Swift._copyCollectionToContiguousArray<A where A: Swift.Collection>(A) -> Swift.ContiguousArray<A.Element> in libMixpanel-swift.a(AutomaticProperties.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
** BUILD FAILED **
The following build commands failed:
Ld /Users/careerlabsdev/Library/Developer/Xcode/DerivedData/CareerLabs_Elev8-gxcfanteiuxazegkgwkjkrjxbdmw/Build/Products/Debug-iphonesimulator/CareerLabs.app/CareerLabs normal
(1 failure)
I have done a lot of things to make it to work. The only success I got here is, while running the command react-native run-ios, it opens up the metro bundler server. After that it fails with giving a 1000 lines of error. I picked the error which had some cream part. Some key words to pick from the error:
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Did not understand the word Ld, which is listed under BUILD FAILED
What I did is as follows:
Deleting node_modules, Pods. Cleaning the build from XCode. Running npm install and then cd ios && pod install and then ran the command react-native run-ios
Deleting Pods, Podfile.lock. Did pod install and then in the root react-native run-ios
Doing these:
rm -rf ~/Library/Caches/CocoaPods
rm -rf Pods
rm -rf ~/Library/Developer/Xcode/DerivedData/*
pod deintegrate
pod setup
pod install
cd ..
react-native run-ios
Restarted the system, and ran the command again react-native run-ios
Added arm64 in the Excluded Architecture from XCode. Please note, this enabled me to build and run the app successfully on XCode. But it doesn't get attached to the metro bundler server. Looks like it runs the release mode only.
Updated my package react-native-gesture-handler to the latest one which is 1.10.3, to see if that removes my problem. But no luck.
My Podfile look like this:
platform :ios, '10.0'
use_flipper!({'Flipper' => '0.81.0'})
post_install do |installer|
flipper_post_install(installer)
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
end
end
end
I am out of options now, and waiting for some insight to be given. It is indeed frustrating to see an error on something which never created a problem. I am using Apple M1 Chip Macbook.
Update V1.0
I have tried commenting down the use_flipper!(), from the /ios/Podfile, and then redid the same things, like removing Pods, Podfile.lock. Running this command, pod update && pod install && cd.. && npm run ios. Ran into multiple issues. I don't know what the issue is with XCode and React Native on Apple M1.
Update V2.0
I have found some significant places where the developers are complaining about the same. XCode has forced updated my version to 12.5, without my notice. And now XCode is creating a problem with RN Older projects. Here are the supportive links for the same:
Flipper doesn't build with XCode 12.5 (GitHub)
Do I need Flipper? (Reddit)
I hope this may give some insight to the developers who are confused like me. Please take a look, and looks like Facebook is fixing it, but don't know when. Have to keep an eye on it :/
The one hacky thing which I did to make my app run again like before, is to downgrade the XCode Version to the previous stable one, that is Version 12.4. I knew about the problem later, cos, XCode force updated my version which started behaving weird with my already existing project. So the only viable option I saw is to downgrade the version to the previous one, and everything worked like before.
Please Note: This issue exists majorly with Apple M1 along with XCode v12.5 and BigSur OS. So go ahead keeping these things in your mind.
For this, I had to do these things:
Uninstall the XCode completely from the Mac. To do that efficiently, considering XCode does caches a lot of things on your Mac, use Mac App Cleaner. If by any chance, you have just removed the XCode without using the link, then use this Completely remove Xcode from Mac.
Install the XCode from this resource XCode Releases. Please Note: This is a legit source which takes you directly to the Apple's download pages, and no unreliable thing. So you can just go ahead and download the previous stable version of the XCode, with which your app was working fine.
Please Note: Installing the XCode from App Store will again install the latest version of the XCode which is buggy v12.5. So please don't download and install the same from Apple Store. Use the above mentioned source only for best results.
Install it when the file is downloaded. Make sure you follow this Setting up development environment React Native, to avoid any mishaps.
Run the app again.
It will work for you, as it did work for me, and now I am continuing my work on my project without any hassle. Cheers!
I am guessing all third party Pods will need to update their RN Pod Specs to use XCFrameworks. That's what I just did and it seems to work ok.
This means that you, as an RN package user, you will either need to wait for the package authors to update their podspecs to use XCFrameworks or add a build config that excludes the 'arm64' arch (but then will not work on M1 macs).
Alternatively, you can visit the node_modules/<package>/thrid-party.podspec and update it yourself. But that means you will need to build the XCFrameworks yourself too. So.....

I have error in run react-native for ios on macbook [duplicate]

I've build a react-native application and suddenly I get this error message on my terminal during run of the command react-native run-ios.
The same code work fine 10 minutes ago and suddenly I get this error message.
Please help...
If you don't have cocoa pods installed you need to sudo gem install cocoapods
run cd ios
run pod install
cd ..
delete build folder
run react-native run-ios
if the error persists,
delete build folder again
open the /ios folder in x-code
navigate File -> Project Settings -> Build System -> change (Shared workspace settings and Per-User workspace settings): Build System -> Legacy Build System`
You should be good to go.
delete the build/ folder in ios/ and rerun
if that doesn't do any change then
File -> Project Settings (or WorkSpace Settings) -> Build System -> Legacy Build System
Rerun and voilà!
In case this doesn't work, don't be sad, there is another solution to deeply clean project
Delete ios/ and android/ folders.
Run react-native eject [Edit: deprecated, so skip this step]
Run react-native link
react-native run-ios
This will bring a whole new resurrection for your project
SOLVED: Always be sure to update your Xcode folks!
Protip: And don't do it from the apple store (but always do it from an official apple website of course)
tip from: http://ericasadun.com/2016/03/22/xcode-upgrades-lessons-learned/
official apple download page: https://developer.apple.com/download/more/
For those who are unable to resolve with above method
Go to project settings in Xcode. Menu File->Project Settings
Go to per-User Project Settings section.
Click on advanced.
Select Xcode Default option. previously this used to be Legacy for my project.
I have analysed on similar lines and concluded that clean is causing the archive to fail. So, the new build system is not clearing the custom/legacy build directory.
delete the build/ folder in ios/ and rerun if that doesn't do any change then
File -> Project Settings (or WorkSpace Settings) -> Build System -> Legacy Build System
Rerun and voilà!
If it still Fails you need to clean full project
Do the following:
Delete ios dir manually
Clean cache Run npm cache clean --force
Run react-native eject
Re-install all packages npm install
Run the link command react-native link
Finally run react-native run-ios
cd ios && rm Podfile.lock && pod install worked for me.
And perhaps few updates if the first didn't help as much, as:
sudo gem install cocoapods
rm Podfile.lock && pod install --repo-update
For me it caused by installing react-native-vector-icons and linking by running the react-native link react-native-vector-icons command.
I just unlinked the react-native-vector-icons by following commands
react-native unlink react-native-vector-icons
cd ios
pod install
cd ..
react-native run-ios
As I already installed an other icon library.
After upgrading react-native, you may have stale dependencies. The steps below should fix it.
cd ios
delete Podfile.lock
pod deintegrate && pod install
Navigate back to package.json directory
run react-native run-ios
In Xcode you can build your project again too
I did this after upgrading to react-native 0.61
Should always start with the simplest first, after wasting hours and days on this error.
And after an extensive amount of research,
Simply
RESTART YOUR MACHINE
This resolved this error.
I'm on
react-native-cli: 2.0.1
react-native: 0.63.3
If you don't have cocoa pods installed you need to:
sudo gem install cocoapods
Then run:
cd /ios
pod install
delete the build folder in ios folder of your react native project
run:
react-native run-ios
if error persists:
delete build folder again
open the /ios folder in Xcode
navigate File -> Project Settings -> Build System -> change (Shared
workspace settings and Per-User workspace settings): Build System -> Legacy Build System
This problem may occur after installing react-native-vector-icons
Open the project in Xcode.
Go to build phases.
go to Copy Build resources.
Remove all .ttf files from here.
Run the application.
I had the same error, but it was caused by the package manager process port being already used (port 8081).
To fix, I just ran the react-native by specifying a different port, see below.
react-native run-ios --port 8090
A popular reason to builds failing and error code 65 is a missmatch between cached pod files and current packages used. Here is how to remove the cache and recreate the pods.
1. Delete Derivate Data - Remove data that includes cached info of the project Example how to do it: https://www.youtube.com/watch?v=f8bTvx0Aoyo
2. Delete .xcworkspace file from ios folder - This is the Xcode project file that gets created when you run pod install we want to recreate it in step 4. This project file uses pods and has a white coloured icon instead of the blue coloured base project without pods.
3. Delete Podfile.lock - Remove old dependencies info so we can recreate them in the next step.
Do a pod-install in ios folder or npx pod-install in root with (React native) - Here we download the pod dependencies again and the pod files only the ones that are used from the current packages are downloaded. A .xcworkspace is regenerated
In my case, the issue was with my Xcode build scheme. When you run react-native run-ios you may see something like,
info Found Xcode workspace "myproject.xcworkspace"*
info Building (using "xcodebuild -workspace myproject.xcworkspace -configuration Debug -scheme myproject -destination id=xxxxxxxx-xxxxx-xxxxx-xxxx-xxxxxxxxx -derivedDataPath build/myproject")*
In this case, there should be a scheme named myproject in your ios configurations. The way I fixed it is,
Double clicked on myproject.xcworkspace in ios directory (to open workspace with Xcode)
Navigate into Product > Scheme > Manage Schemes...
Created a Scheme appropriately with name myproject (this name is case-sensitive)
Ran react-native run-ios in project directory
In case you are using a Mac M1 architecture it is not directly compatible with Cocoapods. If you encounter issues when installing pods, you can solve it by running:
sudo arch -x86_64 gem install ffi
arch -x86_64 pod install
These commands install the ffi package, to load dynamically-linked libraries and let you run the pod install properly, and runs pod install with the proper architecture.
Source: https://reactnative.dev/docs/environment-setup see "Note for Mac M1 users"
run pod install inside ios folder then go back to root folder and run npx react-native run-ios
What worked for me was to rename the project by removing the special characters.
Example: "project_marketplace" to "projectmarketplace"
In this case, I redid the project with react-native init and copied the src and package.json folder.
If you encountered issues with M1.
Try installing the ffi package and running install again.
sudo arch -x86_64 gem install ffi
cd ios
arch -x86_64 pod install
Another solution that I found here works great, basically installing cacoapods with brew (and passing -arm64).
sudo gem uninstall cocoapods
arch -arm64 brew install cocoapods
cd ios
pod install
This could also be due to having custom named schemes, in that case:
cd ios
xcodebuild -list
Find your's, it might have a -dev suffix. Then:
cd .. (root of the app)
npx react-native run-ios --scheme custom-scheme-name
In my case everything solved after re-cloning the repo and launching it again.
Setup:
Xcode 12.4
Mac M1
In my case, none of the answers resolved it, since am not able to open .xcworkspace at all. But the legacy comment hinted to a RN to Xcode <> compatibility issue, so i tried all the previous RN Versions and all below RN#0.64 seem to work with xcode 11.3.1
npx react-native init projectName --version 0.62.0
Thanks
Below work for me though I encounter error code 65 due to I rename an existing project name to a new name which I did for all the files within the project.
My solution was :-
At ios folder level open xworkspace with xcode.
Click on file tab then click on workspace settings.
I clicked on advance then I select xcode default then I clicked on close button.
I clicked on scheme tab which is beside the stop button at the right then I clicked on edit scheme.
When the edit scheme opened I clicked on build tab then I click on manage scheme button.
I selected scheme of my project name then I clicked the minus(-) button to delete it then I clicked on close
I clicked on clean build folder then when its complete I clicked on build tab to rebuild the project.
I clicked on play button which i selected the simulator I want then everything work perfectly again.
I too had an issue with react-native-vector-icons causing this. I still wanted to use the icons though, and I was using VSCode
Workaround was to more or less the same as the manual instructions from the docs but a little different.
npm install --save react-native-vector-icons
copy the .tff files you want to use in node_modules -> react-native-vector-icons -> fonts
create a new folder "fonts" in src -> ios
...paste the .tff files in there
open 'info.plist' in src -> ios -> mobile
on the line above </dict> paste:
<array>
<string>AntDesign.ttf</string>
<string>Entypo.ttf</string>
<string>EvilIcons.ttf</string>
<string>Feather.ttf</string>
<string>FontAwesome.ttf</string>
<string>FontAwesome5_Brands.ttf</string>
<string>FontAwesome5_Regular.ttf</string>
<string>FontAwesome5_Solid.ttf</string>
<string>Foundation.ttf</string>
<string>Ionicons.ttf</string>
<string>MaterialIcons.ttf</string>
<string>MaterialCommunityIcons.ttf</string>
<string>SimpleLineIcons.ttf</string>
<string>Octicons.ttf</string>
<string>Zocial.ttf</string>
<string>Fontisto.ttf</string>
</array>
...or whatever fonts you selected.
I ran react-native run-ios and it worked like a charm.
Some changes in Podfile haven't been updated. Maybe one of your native dependencies has changed.
expo prebuild --clean
cd ios
pod install
yarn ios
In a React Native app, I removed some font assets that I previously linked. For some reason, they didn't get deleted from the Xcode project. I deleted them manually and then it worked.
For our project, we had to run the npx react-native link command in order to get the react native vector icons to show up on Android phones. But that added code to the ios/yourprojectname.xcodeproj/project.pbxproj file.
And that caused the build to fail, throwing an error code 65 and listing out all the fonts that were duplicated.
So, to fix the error, we just removed all of the new code that was added by the npx react-native link command.
If you've built/run your app previous from Xcode and want to go back to using the terminal you need to clean your build folder.
Go to product -> Clean Build Folder
In my case it was an issue between different installations of npm installed via nvm and homebrew which somehow messed up my setup.
Building via Xcode usually works without solving the initial problem. I have solved it as follows. Notice, that this guide is suitable if you want to use nvm.
First, we remove a possible installation of npm and yarn using brew as follows.
brew uninstall npm
brew uninstall yarn
We might want to remove nvm as well.
rm -rf "$NVM_DIR"
Next, we reinstall nvm by executing the following command.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | <ShellOfYourCoice>
Replace <ShellOfYourCoice> with bash if you are using bash, with zsh if you are using zsh.
Add the following content to ~/.bash_profile (.bashrc) for bash or to ~/.zshrc for zsh (you might need to create these files).
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
For zsh, we might need to fix some permissions. Execute the following command.
compaudit | xargs chmod g-w
Then, source the shell of your choice. Verify the installation by executing the following.
nvm --version
which npm
The last command should print something similar to the following.
/Users/<userName>/.nvm/versions/node/v16.10.0/bin/npm
If yarn were installed using npm previously, we first remove it.
npm uninstall yarn
Next, we reinstall it.
npm i -g yarn
These steps fixed the issue for me.
For macOS, make sure that none of the names of the directories has a space character ' ' in their names. I spent hours figuring out the problem and the problem was so small.
error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65
That was my error and i resolve this error with the following commands:-
1- Uninstall Ruby with: brew uninstall ruby --force
2-Uninstall CocoaPods. At first, try to list all CocoaPods versions / components with gem list --local | grep cocoapods. Then uninstall them one by one, in my case:
1- sudo gem uninstall cocoapods
2- sudo gem uninstall cocoapods-core
3- sudo gem uninstall cocoapods-downloader
,cocoapods-plugins
,cocoapods-search
,cocoapods-trunk
,cocoapods-try
etc.
3- As a next step I was able to reinstall ffi and then CocoaPods with:
i) sudo arch -x86_64 gem install ffi
ii) sudo arch -x86_64 gem install cocoapods
Once done, I could run pod install as expected. Note that I had the Terminal open all the time in standard mode - no Rosetta required.
If you're like me and tried to change the name of the TestApp-folder. Notice the last line in the warning:
xcodebuild: error: The workspace named "TestApp2" does not contain a
scheme named "TestApp-tvOS". The "-list" option can be used to find
the names of the schemes in the workspace.
Not changing the TestApp name in the command nor after from this, helped me get rid of the message and the app was built:
react-native init TestApp --version=react-native#npm:react-native-tvos#latest
there was some issue while creating the app
so in my case i just deleted the package-lock.json and did npm i
after that
cd ios/ and pod install

Unable to resolve module react/lib/ReactUpdates

I'm cloning a proyect:
The steps are:
npm i
react-native link
When i run it react-native run-ios i have a problem with RCTWebSocket library. This problem is easy to resolve if you search a little just need remove 2 compiler flags, in Custom Compiler Flags.
Later just i run again react-native run-ios and works fine, but when the app is open, show the next error:
Searching i found that is related to upgrade, source here
but i'm using that command and not works.
When this command is executed, it starts showing me some overrides to some files and at the end of this process, the problem persists.
My react info:
react-native-cli: 1.0.0
react-native: 0.32.1
I'm running in Xcode 8 and ios 10.0
PDTA: When I start a new project works perfect
UPDATES:
When clone on another mac works, I am ensuring to have the same versions of both xcode and node.
Could it be some mac configuration problem?
The only difference between the 2 macs is the cli version:
`react-native-cli: 1.1.0` --> my mac
`react-native-cli: 1.2.0` --> the other mac
Will this be enough to cause all this problem?
With React 0.32~0.37: The problem is most likely that you are using React 15.4.x instead of 15.3.x. One of the changes between 15.3 and 15.4 was that many of the modules under react/lib were moved to react-dom/lib, which is why the packager can't find react/lib/ReactUpdates.
Ensure that your package.json file locks React to 15.3.x:
"dependencies": {
"react": "~15.3.2"
}
Then delete your node_modules folder and run yarn or npm install again. Verify that you installed React 15.3.x:
$ npm ls react
app#1.0.0 /code/app
└── react#15.3.2
Last, restart the React Native server and load your bundle again.
This has been fixed!
Update your dependencies and use react-native ^0.38.0 or newer.
Run react-native upgrade after all react-native version upgrades.

Resources