Ionic v2 : "You cannot run cocoapods as root" error - ios

I'm trying to build an Ionic 2 app with push notification in iOS.
I added Phonegap plugin push notification with this command line :
cordova plugin add phonegap-plugin-push --variable SENDER_ID=12341234 --save
But when I try to run my project in a device I have this error in xcode :
"GoogleCloudMessaging.h" file not found
I looked for a solution and I had install Cocoapods. I removed platform iOS and I try to add it with this command line :
sudo ionic platform add ios
I had this error :
Installing "phonegap-plugin-push" for ios
Failed to install 'phonegap-plugin-push':undefined
Error: /Library/Ruby/Gems/2.0.0/gems/claide-1.0.2/lib/claide/command.rb:439:in `help!': [!] You cannot run CocoaPods as root. (CLAide::Help)
Usage:
$ pod COMMAND
CocoaPods, the Cocoa library package manager.
Commands:
+ cache Manipulate the CocoaPods cache
+ env Display pod environment
+ init Generate a Podfile for the current directory
+ install Install project dependencies according to versions from a
Podfile.lock
+ ipc Inter-process communication
+ lib Develop pods
+ list List pods
+ outdated Show outdated project dependencies
+ repo Manage spec-repositories
+ setup Setup the CocoaPods environment
+ spec Manage pod specs
+ update Update outdated project dependencies and create new Podfile.lock
Options:
--silent Show nothing
--version Show the version of the tool
--verbose Show more debugging information
--no-ansi Show output without ANSI codes
--help Show help banner of specified command
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.2.1/lib/cocoapods/command.rb:47:in `run'
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.2.1/bin/pod:55:in `<top (required)>'
from /usr/local/bin/pod:23:in `load'
from /usr/local/bin/pod:23:in `<main>'
I tried to run "pod install" directly in platforms/ios folder, but same issue.
So I try to remove sudo in the commande :
ionic platform add ios
But obviously I have this error :
MacBook-Air-de-user:MyApp compagny$ ionic platform add ios
Error during untar for /Users/user/.cordova/lib/npm_cache/cordova-ios/4.3.1/package.tgz: Error: EACCES: permission denied, open '/Users/user/.cordova/lib/npm_cache/cordova-ios/4.3.1/package/package.json'
Error: Failed to fetch platform ios
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
Error: EACCES: permission denied, open '/Users/user/.cordova/lib/npm_cache/cordova-ios/4.3.1/package/package.json'
I really don't know what I have to do to solve that. An Idea ?

Try update Cordova version, remove platforms and add again:
npm install -g cordova
cordova platform remove android
cordova platform remove ios
cordova platform add android
cordova platform add ios
cordova plugin add phonegap-plugin-push --save
I had the same problem and its worked for me.

If anyone is still having issues, I got it to work by running
pod install
in platforms/ios
and you may need to add permissions in that folder before that
sudo chown -R *username* platforms/ios

To allow code executions on your mac without using sudo simply run.
sudo chown -R Username /Users/username/Document/project location

It's working for me
If you use any plugin and platform add please install and add without
"sudo".
If needed permission them go to the project directory and click
setting->Get Info to give "Read & Write" permission then you can install plugin and platform without "sudo"
ionic cordova plugin add cordova-plugin-fcm-with-dependecy-updated#7.5.0
ionic cordova build ios --prod

Related

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

ionic 3 - cannot install onesignal plugin for ios using latest xcode

I cannot create add ios platform for onesignal plugin. With android build its fine.
I did this:
$ ionic cordova platform add ios
the following errors failed.
apple-ios version check failed ("/Users/megasap/Documents/project/railerdotcom/railercom_parent/platforms/ios/cordova/apple_ios_version"), continuing anyways.
Failed to install 'onesignal-cordova-plugin': undefined
Failed to restore plugin "onesignal-cordova-plugin" from config.xml. You might need to try adding it again. Error: /Users/megasap/.rbenv/shims/pod: line 21: /usr/local/Cellar/rbenv/1.0.0/libexec/rbenv: No such file or directory
--save flag or autosave detected
Saving ios#~4.5.4 into config.xml file ...
[ERROR] Exception:
Full execution and error here:
https://gist.github.com/axilaris/a926c54eb515bef5eb2f7019e36aa40f
This used to work, i just update to latest xcode 9.2 to compile other things. Is it something wrong with using the latest xcode ?
install and update cocoapods fix the problem
sudo gem install cocoapods
pod setup
You may need to rm and add ios platform to make it work
The actual issue is here:
Error: /Users/megasap/.rbenv/shims/pod: line 21: /usr/local/Cellar/rbenv/1.0.0/libexec/rbenv: No such file or directory
Just update/install cocoapods to latest version as your xcode is also updated.
sudo gem install cocoapods

The platform "ios" does not appear to be a valid cordova platform

I'm running under cordova#7.1.0, cordova-ios#4.5.2.
Installed platforms: ios 4.5.2.
I run npm install, bower install then cordova prepare ios and i get the following error:
Unable to load PlatformApi from platform. Error: Cannot find module 'unorm'
Error: Unhandled "error" event. (The platform "ios" does not appear to be a valid cordova platform. It is missing API.js. ios not supported.)
The solution is to cordova platform rm ios and cordova platform add ios. But i have to do this each time i checkout my project from git ...
Do you have any suggestion to solve this issue?
Many thanks !
You should not put the platforms (and plugins) folder into source-control. Reinstalling the platform after a fresh checkout is the expected behaviour.
The files in the platforms folder are created dynamically which is why they should not be in source control.

React Native ios build failed on react-native run-ios

getting this error
** BUILD FAILED **
The following build commands failed:
CompileC /Users/karthikn/AwesomeProject/ios/build/Build/Intermediates/React.build/Debug-iphonesimulator/React.build/Objects-normal/x86_64/RCTTabBarItem.o Views/RCTTabBarItem.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
Installing build/Build/Products/Debug-iphonesimulator/AwesomeProject.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, ":CFBundleIdentifier", Does Not Exist
Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/AwesomeProject.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist
Xcode 8.2 still occur same error. Three lines bellow fixed it for me :)
Downgrade react(16.0.0-alpha.12 -> 16.0.0-alpha.6) & react-native(0.45.0 -> 0.44.0)
rm -rf node_modules/react
npm i react#16.0.0-alpha.6 -S
npm i react-native#0.44.0 -S
Then run react-native run-ios
Your build could be failing because of the current node js version installed, or due to your pod files or a number of other reasons.
This error may also be when cloning a react native repository from github.
This solution may work as I was able to recreate this issue(refer to the screen shots):
Solution one:
firstly:
If you have the latest version of node js installed you may have some compatibility issues with some of the dependencies, install the recommended version of Nodejs instead.
after installation, reinstall your dependencies and update your pod files:
npm install
cd ios
pod install
or
pod update
solution two:
this can happen if you haven't installed react native previously on your system and are trying to run a clone react native repository from github.
brew install watchman
sudo gem install cocoapods
then in the rn project clone
cd ios
pod install
Problem:
This is what the error message looks like:
legacy compatibility issues:
Build failed
Solution:
After following the above steps this issue was resolved instantly:
If it's your first project, you may have the same problem than me:
do NOT use space in your project path! 🎉 😄
If your xcode is open, close it
Remove DrivedData
Update your pod files using pod update command
Run npx react-native ios command
its worked for me i hope work for you too
There's a good chance you're running an outdated version of React-Native and your template is no longer compatible.
There are instructions provided on ways to upgrade.
The simplest would be to run react-native upgrade and you'll be prompted with files react-native wants to overwrite. Clicking yes through all the prompts solved this issue for me but if you're concerned about losing any changes, it's recommended to install npm install -g react-native-git-upgrade and merge any conflicts after running react-native-git-upgrade
Try sudo react-native run-ios
This helped me
Check this In Your info.plist Bundle identifier
Or Add this Bundle identifier name as --> com.cmpname.yourapp // change name according
DO NOT use space in project path. It had solved my problem.
Replace Boost C++ Libraries with this one Download Link
/node_modules/react-native/third-party/boost_1_63_0
seems like there is an issue with the react-native version, downgrading the version will resolve the issue. Use the following commands:
rm -rf node_modules/react
npm i react#16.0.0-alpha.6 -S
npm i react-native#0.44.0-alpha.6 -S
react-native run-ios
There are different problems that cause this issue. I'll post here what I did to resolve in my case.
1 - Delete the folder node_modules and the folders of android and ios from project root:
rm -rf node_modules/ ios/ android/
2 - Rebuild the folders:
npm install && react-native upgrade
or (If you have used yarn in the project)
yarn install && react-native upgrade
3 - After that, just run the command again:
react-native run-ios
or
react-native run-android.
I hope it helped =)

IONIC:Unable to install phonegap-plugin-push in ios app

I am new with ionic framework.Currently i am working on ionic iOS app. when i install phonegap-plugin-push i am getting error
Failed to install 'phonegap-plugin-push':undefined Error: /Library/Ruby/Gems/2.0.0/gems/claide-1.0.1/lib/claide/command.rb:439:in `help!': [!] You cannot run CocoaPods as root. (CLAide::Help)
i have searched it but no solution found yet!
I also got same kind of problem. In my case I used sudo ionic platform add ios
This is worked well while building every plugins but phonegap-plugin-push.
phonegap-plugin-push is keep giving above error [!] You cannot run CocoaPods as root. (CLAide::Help)
Then I used ionic platform add ios without sudo This is the actual solution for this. But in this case It is keep giving me the permission related issue code EACCESS.
Then I used followings step to overcome that one.
sudo chown -R $USER /usr/local/
Again added cordoava and ionic
sudo npm install -g cordova
sudo npm install -g ionic
Other informations
phonegap-plugin-push version: 1.10.0
Cordova CLI: 6.5.0
Ionic CLI Version: 2.2.2
Node Version: v7.7.2
Xocde Version: Xcode 8.2.1
CocoaPods Version: 1.2.0
Hope this will help.

Resources