rahul rawat
rahul rawat

Reputation: 2150

CocoaPods not installed or not in valid state

Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
Warning: CocoaPods is installed but broken. Skipping pod install.
  You appear to have CocoaPods installed but it is not working.
  This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
  This can usually be fixed by re-installing CocoaPods. For more info, see https://github.com/flutter/flutter/issues/14293.
To re-install:
  sudo gem install cocoapods

CocoaPods not installed or not in valid state.
Error launching application on iPhone 11 Pro Max.

Upvotes: 205

Views: 285324

Answers (30)

Uvais
Uvais

Reputation: 173

  1. Open the ios folder in xcode.
  2. Select the scheme and run the app from xcode.

It fixed the issue for me

Upvotes: 0

trqhien
trqhien

Reputation: 812

As the error message suggests, this is likely due to a mismatch between the version of Ruby that CocoaPods was installed with and the version being used to invoke it.

This error commonly occurs when you run flutter run from your root directory. To resolve it, ensure that the Ruby version in the root directory matches the one in the ./ios directory. You can cd into each directory and run gem which cocoapods to verify that both point to the same Ruby installation. In my case, I use rbenv to manage my ruby version, and sometimes I mix up the versions.

. <- same ruby version
├── assets
├── ios <- same ruby version
├── android
├── lib
└── test

enter image description here

Upvotes: 0

Sanjay Bharwani
Sanjay Bharwani

Reputation: 4809

Faced same problem on

  • Mac OS
  • Android Studio

Solution which worked for me sudo gem uninstall cocoapods && sudo gem install cocoapods However Android studio was still not able to perform the pod install as part of app deployment on iOS Simulator.

So, the trick was to perform Invalidate Cache and Restart

File -> Invalidates Cache -> Invalidate and Restart

Upvotes: 0

Ashwin Prabhu
Ashwin Prabhu

Reputation: 7634

The following worked in my case:

brew install cocoapods --build-from-source

then:

brew link --overwrite cocoapods

More information about this issue can be found at: https://github.com/CocoaPods/CocoaPods/issues/8955

Upvotes: 22

Compaq LE2202x
Compaq LE2202x

Reputation: 2386

I got this error when I renamed my folder name that has space.

For example, from folder\flutter_project to new folder\flutter_project.

It sounds silly but I spent few hours scratching my head what's the cause. Don't do the mistake that I did!

Upvotes: 0

nguyendc
nguyendc

Reputation: 67

If none of above answers can fix your case, and if you are received this warning when running flutter:

We strongly recommend running the flutter tool without superuser privileges.

try to fix this warning and it might fix the previous problem aswell.

Give Flutter the proper privileges:

sudo chown -R $USER /Users/YOUR_USER/flutter/
example: sudo chown -R $USER /Users/nguyendc/flutter/

Then, give your project the proper privileges:

sudo chown -R YOUR_USER /LINK_TO_YOUR_PROJECT
example: sudo chown -R nguyendc /Users/projects/flutter-app

Hope this helps someone who is as frustrated as I am.

Upvotes: 1

Choco Li
Choco Li

Reputation: 541

For whom suffered for hours and none of the solution worked, if you can run pod --version with issue, try

sudo gem uninstall activesupport sudo gem install activesupport -v 7.0.8

then pod --version. If that works, try flutter doctor. My XCode cocoapods issue is resolved after install different of activesupport.

Upvotes: 1

Mohamed BH
Mohamed BH

Reputation: 71

Same issue and fixed with the next steps:

  1. pod install
  2. restart vscode

Upvotes: 4

ccpizza
ccpizza

Reputation: 31801

If you have homebrew, and you followed the docs and ran sudo gem install cocoapods then

sudo gem uninstall cocoapods && brew install cocoapods

brew install cocoapods pulls brewed ruby as a dependency, so if you don't already have the brewed ruby it will be automatically installed.

❗️During the ruby installation watch closely the log — it will display the extra path you need to add to your ~/.zshrc or ~/.bashrc for example /opt/homebrew/opt/ruby/bin:$PATH (the correct path will depend on the type of mac you are using).

Upvotes: 2

Usama Elgendy
Usama Elgendy

Reputation: 576

Flutter framework

just restart IDE like android studio with invalidate cash worked with me

enter image description here

Upvotes: 0

Zeinab Kouhkan
Zeinab Kouhkan

Reputation: 152

I run first

sudo gem install cocoapods

or

$ gem install cocoapods --user-install
$ gem which cocoapods
/Users/eloy/.gem/ruby/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods.rb
$ /Users/eloy/.gem/ruby/2.0.0/bin/pod install

but don't work, because command tools of Xcode was not installed. you should run

xcode-select --install

to install command tools of Xcode and then use brew or rvm , ... to install cocoapods.

commands for installing brew:

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

(echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> /Users/edvard/.zprofile

finally you can install cocoapods :

brew install cocoapods

pod install

Upvotes: 0

GTG
GTG

Reputation: 29

To solve this problem you need to install cocoapods using the --user-install flag.

Step 1: add this to your environment path. export

PATH=~/.gem/ruby/3.2.0/bin:$PATH    (remember to change your ruby version)

Step 2: install cocoapods

gem install cocoapods --user-install

Source: https://guides.cocoapods.org/using/getting-started.html#installation

Upvotes: 2

Christian X
Christian X

Reputation: 2187

My problem was, that when I was download the new gems, I had a network outage and one of the .podspec files was not downloaded correctly. In the middle of the json, it simply just stopped and was therefore an invalid token.

Once I found the correct podspec file, I simply had to delete it and run gem install cocoapods again.

If you don't want to search the stecific file, you could also simply just go to the .cocoapods folder, delete all pods and install it again.

This fixed it for me.

Upvotes: 0

Arjun Singh
Arjun Singh

Reputation: 77

My Issue solve and working my project Select gem to uninstall All cocoapods one by one package:

  1. cocoapods-1.11.2
  2. cocoapods-1.11.3
  3. cocoapods-1.12.0
  4. cocoapods-1.12.0

And intsall

sudo gem install cocoapods, sudo gem install rails

Upvotes: -1

Muhammad AbdulSalam
Muhammad AbdulSalam

Reputation: 533

I had the same issue. Following worked for me

  1. Clean project
  2. Use terminal to run flutter run
  3. It's an IDE related issue not flutter or cocoapods

Upvotes: 49

DoruChidean
DoruChidean

Reputation: 8138

This can happen if you switched from bash to zsh (or the other way around) Check your global paths. Run echo $PATH to list them and look for /opt/homebrew/bin.

If missing you need to add it to .zshrc file or .bash_profile (whichever you are using now)

Upvotes: 1

Manjunath Bilwar
Manjunath Bilwar

Reputation: 2353

just change your cocoa pods version to 1.10.2 to solve your problem.

first, uninstall your current version (whatever it is)

In my case, i downgraded from version 1.11.3

$ sudo gem uninstall cocoapods

Then install the stable version (as of Nov 11, 2021)

$ sudo gem install cocoapods:1.10.2

This solved my problem.

Upvotes: 0

Ash
Ash

Reputation: 5712

I had same issue after updating my MAC OS to Monterey 12.6.5, So issue is with Ruby version, Please update the ruby to 3.1.3 , set it default. then run the cocoa pod install commands . So follow below steps :

Move to Ruby 3.1.3

  1. rvm install "ruby-3.1.3"
  2. rvm --default use 3.1.3
  3. Check the ruby version running : "ruby -v" it should display you 3.1.3
  4. gem install cocoapods

and run your workspace

Dont install ruby 3.2.0 with Xcode 14.

Upvotes: 0

saif aly
saif aly

Reputation: 605

first check the ruby version ( command: ruby -v ) it should be the default version of macOS in my case it is ruby 2.6.10.

if you ruby version is not as the default then switch to the default version by command: rvm install "2.6.10"

then run flutter clean

after this you need to install cocapods by command: sudo gem install cocapods

finally command: flutter run and choose iOS simulator.

Upvotes: 0

redbasecap
redbasecap

Reputation: 45

On my mac after i installed a new ruby version (with RVM) seperately:

remove the ruby which was installed with RVM:

rvm list rubies

if it return:

ruby-3.0.2

enter:

rvm remove ruby-3.0.2

to remove the ruby version

then go to your flutter folder and in the terminal enter:

pod deintegrate
sudo gem uninstall cocoapods
sudo gem uninstall cocoapods-core
sudo gem uninstall cocoapods-downloader 
rm -rf ~/Library/Caches/CocoaPods
rm -rf ios/Pods
pod deintegrate
curl -L https://get.rvm.io | bash -s stable
rvm install ruby --latest

In my case the latest was 3.0.0

rvm use ruby-3.0.0 
rvm --default use 3.0.0
sudo gem install cocoapods
flutter clean

That fixed it for me!

Upvotes: 2

Ashwin Balani
Ashwin Balani

Reputation: 781

Try doing this,

sudo gem install -n /usr/local/bin cocoapods

And check,

flutter doctor

Upvotes: 5

seyhmus gumus
seyhmus gumus

Reputation: 116

for me works after open android stdio from terminal Run Android Studio

open /Applications/Android\ Studio.app hope this helps you

Upvotes: 0

slackgate
slackgate

Reputation: 125

I had the same issue. Just update Android studio on VMware MacOS worked for me

Upvotes: -1

yshean
yshean

Reputation: 441

I have encountered this every time I switch the branch of the Flutter project. I had to restart my VS Code (not just reload the window) completely - quit and open again for the Cocoapods error to be gone.

Here are the steps I used and worked:

  1. Run flutter clean and flutter pub get
  2. cd ios and run pod install
  3. Quit and start VS Code

Upvotes: 2

Phuc Tran
Phuc Tran

Reputation: 8083

In my case, I uninstalled both cocoapods and fastalane, then reinstalled them.

Upvotes: 0

Andrey Gordeev
Andrey Gordeev

Reputation: 32529

If you use bundle exec fastlane beta command, make sure you've added gem "cocoapods" to your Gemfile:

source "https://rubygems.org"

gem "cocoapods"
gem "fastlane"

Then execute:

bundle install
bundle exec fastlane beta

Upvotes: 3

Ax M
Ax M

Reputation: 370

I have tried everything but in my case the real problem was that because I had 2 additional versions of ruby installed and was switching between them with chruby however, cocoapods were installed with ruby 3.0.1 and had it set up in my .zshrc so that chruby would autmatically choose the right version of ruby which somehow did not work anymore on VS Code.

What I did to solve this was edit ~/.zshrc by replacing source /usr/local/opt/chruby/share/chruby/auto.sh with chruby ruby-3.0.1 after source /usr/local/opt/chruby/share/chruby/chruby.sh.

This is only for people who use chruby !

Upvotes: 0

isa
isa

Reputation: 784

brew uninstall cocoapods

Apply the above command line, then restart the application Android Studio.

Upvotes: 0

Beethoventhepoet
Beethoventhepoet

Reputation: 1311

Someone I know had this issue, and another person recommended this fix.

Run this command from terminal:

open /Applications/Android\ Studio.app

The issue is that there are 3 possible resource paths where you put paths to your configs....

  • 1st is the ~/.profile
  • 2nd is the ~/.zshrc.
  • 3rd is the ~/.bashrc.

So what happens is that when the path to your configs is not in the ~/.profile file, it can't be accessed from the opening link from the launchpad. Whenever you open a terminal session, all 3 paths are synchronised automatically. That's the difference.

Upvotes: 121

Paul Kastel
Paul Kastel

Reputation: 1147

I had the same problem while executing fastlane command.

Turned out that I installed fastlane using brew and cocoapods were installed with gem. Probably this is why flutter doctor show that everything alright, but when I tried to deploy app, fastlane failed with error above. Installing fastlane and cocoapods with: sudo gem install fastlane; sudo gem install cocoapods and removing both from homebrew resolved problem for me.

Basically make sure that you have both tools installed with the same package manager on macOS.

Upvotes: 7

Related Questions