176
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.
Ashwin Prabhu
  • 9,285
  • 5
  • 49
  • 82
rahul rawat
  • 1,878
  • 2
  • 7
  • 6

47 Answers47

159

usually this happens due to visual studio or IntelliJ not able to find the path or associated plugin or extension.

here is the solution:

  1. sudo gem uninstall cocoapods && sudo gem install cocoapods
  2. restart IDE or Editor

the last step should solve the issue if not close the project entirely

AngDrew
  • 136
  • 6
Agyakwalf
  • 1,674
  • 1
  • 5
  • 8
  • Yes....I had run CleanMyMac X, but did not restart IDE afterwards. Restarting IDE seems to have worked. – King Leon Mar 05 '21 at 16:33
  • 48
    Simply restarting my IDE fixed it for me. – Stefan Galler Nov 17 '21 at 08:49
  • 3
    Thanks. Simply restarting IDE worked for me – Bishal Paudel Jan 16 '22 at 20:15
  • 5
    Trick was to close VS Code completely, for me. – LacOniC Jan 26 '22 at 01:55
  • 15
    This does not work for me. Strangely enough, running `flutter run` and through Xcode works but not from Android Studio. – Zenko Jan 28 '22 at 03:57
  • 4
    @Zenko SAME! It's the same for me. When I run the command ```flutter run``` from the command line it works too. But just not on Android Atudio. – Delicia Fernandes Feb 04 '22 at 11:50
  • 1
    @DeliciaFernandes do you know whats the reason? I am facing also same issue. – pavel Feb 28 '22 at 17:45
  • It is bad practice to install gems with sudo Why? Because it means that you use system ruby, which you really shouldn't. And with ruby managers you don't need sudo for any gem installation to use sudo –  vrnvorona Mar 18 '22 at 08:33
  • Make sure to completely quit Android Studio. Just closing the window is not enough, you have to kill the app. If you're on Mac, you click on the dock and select "Quit". – Jack' May 24 '22 at 09:21
  • most of the time I have to do the same. Do we have any other workaround? – Tapas Pal Jun 25 '22 at 17:44
  • Restarting Android Studio did the trick for me! – Henrique Nov 02 '22 at 14:15
  • I my case didn't worked restart the IDE after uninstall and install cocoa pods. But when I executed the `flutter run` command the error was displayed: *Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies. To update the CocoaPods specs, run: pod repo update* And executing `pod repo update` worked for me. – M. Massula Nov 15 '22 at 19:17
  • Once again this answer saved us :) – Tapas Pal Aug 23 '23 at 06:05
112

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.

ouflak
  • 2,458
  • 10
  • 44
  • 49
Beethoventhepoet
  • 1,221
  • 1
  • 3
  • 4
  • This fixed it for me. I've installed Ruby with `asdf` and use `zsh` so I'm assuming one of the two of those caused this issue. Using `open` in terminal tells AS to use the correct path (for some reason). – Kyle Venn Jan 28 '22 at 20:16
  • 6
    Starting from the command line fixed the issue but I'm really curious how I can fix this for real... – Gyuri Majercsik Jan 31 '22 at 08:11
  • 1
    Same thing, how to fix this for good? It's not a problem to run it from the terminal but.... – fkvestak Feb 01 '22 at 13:11
  • 4
    Oddly enough running "flutter run" from the terminal in Android Studio works but click the play button does not. – Craig Howell Feb 02 '22 at 13:09
  • I only update the flutter plugin and everything is fixed. – M Karimi Feb 05 '22 at 09:00
  • 6
    After running `open /Applications/Android\ Studio.app` once, in my case the paths seem to be fixed such that there is no need to run from command line again and running from the play button is fixed. – plam Feb 05 '22 at 11:35
  • 1
    Worked for me '' open /Applications/Android\ Studio.app '' thanks – Vaibhav pandey Apr 01 '22 at 14:41
  • Worked for IntelliJ Idea – Roddy R Jun 01 '22 at 17:04
  • This is working for me!!! I don't think I'm updating my Android Studio or doing anything different, but one day my Android Studio just stop being able to compile to iOS simulator and giving me the error above... – Chen Li Yong Jun 03 '22 at 06:44
  • Thanks! Spent a few hours down a blackhole just for this to simply fix everything – Edgar J. Oct 04 '22 at 00:36
41

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
Johngorithm
  • 371
  • 2
  • 8
36

I was having similar issues. I just did the following things.

  1. flutter clean
  2. flutter pub get
  3. Reload VSCode
  4. flutter run
Saurav Panthee
  • 589
  • 5
  • 8
26

This problem might be because you have multiple versions of cocoapods installed.

You can check and resolve it running:

  • gem list check to see if multiple versions of cocoapod are installed
  • sudo gem uninstall cocoapods it will prompt you to select which one to uninstall, or if you want to uninstall all
  • sudo gem install cocoapods

Additional step if you uninstalled all cocoapods

  • Change to the iOS directory of your Flutter project
  • pod install

That should then allow you to run an xcode build to an iOS device.

heymonkeyriot
  • 306
  • 3
  • 10
25

Reinstalling the flutter extension on visual code fixed this

shrhawk
  • 621
  • 7
  • 10
  • 14
    ^ I look at this answer and try updating Flutter plugin on my IDEA. It works. @MyKoryto it should not be in the comment. – Simon Pham Dec 13 '20 at 08:22
  • 2
    it'w work also with AndroidStudio, i've had the same problem on Android Studio when i had updated my Xcode to Xcode 13.2, my project was run perfectly on Xcode but not in Android Studio – Chakib Temal Dec 20 '21 at 14:16
25

On Android Studio, "Invalidate Caches / Restart.." worked for me.

Basanth
  • 737
  • 8
  • 16
20

I spend about an hour trying everything here.

Finally, I figured out that on Mac you must quit VS code from the top menu and not just close the open windows.

Hopefully, it will save someone some frustration..

Yonatan Naor
  • 1,367
  • 18
  • 19
15

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

Ashwin Prabhu
  • 9,285
  • 5
  • 49
  • 82
11

use brew to install cocoapods

  1. sudo gem uninstall cocoapods
  2. brew install cocoapods
  3. brew link --overwrite cocoapods

if need unlink & link again brew unlink cocoapods && brew link cocoapods

GJJ2019
  • 4,624
  • 3
  • 12
  • 22
  • Worked for my mac + android studio – C.K. May 27 '22 at 21:09
  • In M1 Macbook and Xcode 14.1 it worked... My issue was that I was able to run app from xcode but not from VSCode.. Note:- Use `Flutter doctor` to check if coacoapod is fine. – Kudos May 10 '23 at 08:04
  • This worked for me. I was experiencing the issue described in the comments of other answers to this question; where running "flutter run" from the terminal in Android Studio works but click the play button does not. – Benoît Cerise Jun 13 '23 at 12:28
9

I had the same issue, I can run in xcode but not within vscode. Following worked for me.

  1. flutter clean
  2. restart vscode
figureai
  • 101
  • 1
  • 1
8

Try with:

pod setup
brew link --overwrite cocoapods

after commands, restart IDE

Mattia
  • 344
  • 4
  • 6
7

If you are using Visual Studio Code for Flutter development, the issue may be related to Resolving shell environment fails:

enter image description here

Many times, when running from UI (Spotlight, Dock, etc), Visual Studio Code fails to load shell environment variables on time (doesn't matter which shell you are using - bash, zsh, etc). As a result, the PATH and other environment variables are not loaded (properly) which can result in "CocoaPods not installed or not in valid state" error.

A workaround is to run Visual Studio Code from Terminal (instead of launching it from the UI) and then proceed with MacOS/iOS compilation as usual, i.e.

open -a "Visual Studio Code"

(or just code if you followed this guide and added Visual Studio Code to PATH environment variable)

❗️❗️❗️ No need for CocoaPods/Flutter plugin reinstall whatsoever ❗️❗️❗️

tonymontana
  • 5,728
  • 4
  • 34
  • 53
6

I tried the solution proposed by heymonkeyriot, but that was not sufficient. What worked for me was uninstalling both cocoapods (respond Y when asked about deleting pods) and cocoapods-core, then reinstalling cocoapods and running pod install:

sudo gem list
sudo gem uninstall cocoapods
sudo gem uninstall cocoapods-core
sudo gem install cocoapods

Changed to ios directory for my project

pod install
C. Swanson
  • 81
  • 1
  • 6
4

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.

Paul Kastel
  • 913
  • 1
  • 13
  • 22
4

Try doing this,

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

And check,

flutter doctor

Sangram Shivankar
  • 3,535
  • 3
  • 26
  • 38
Ashwin Balani
  • 745
  • 7
  • 19
4

In the terminal navigate to your project root and enter:

cd ios

pod install

Note: Make sure to rebuild your project (in Xcode) before trying to run the application.

If this does not work, then try brew install cocoapods or sudo gem install cocoapods.

aabiro
  • 3,842
  • 2
  • 23
  • 36
3

if you are using fastlane and still complaining about cocoapods, even cocoapods is installed properly, reinstall fastlane again:

brew uninstall fastlane
gem install fastlane
Hashem Aboonajmi
  • 13,077
  • 8
  • 66
  • 75
2

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
Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162
2

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!

redbasecap
  • 31
  • 3
1

After longer investigation, I identified two error-causing points.

Firstly,

Changing linker flags in ios/Runner.xcodeproj/project.pbxproj . In Xcode, navigate to Project Runner -> Build Settings -> Other Linker Flags & change all the blob that there with:

$(inherited)
-framework
Flutter

Other Linker Flags

Secondly,

VS Code entry in my PATH variable was incorrect. After changing it accordingly to the documentation here he error was no longer present.

Austris Cirulnieks
  • 1,099
  • 11
  • 18
1

I faced with this issue with Android Studio, so i tried all of manipulations with gem and cocoapods stuff and it didn't helped. I fixed it with Android Studio settings: File -> Invalidate Caches / Restart.

1

Ran into a similar issue. Here's how to get around it.

  1. Uninstall cocoapods, mentioned before but gem uninstall cocoapods just in case. Also the cocoapods troubleshooting page has a few steps to look into.

Option 2.A - If you need the system ruby 2.6, in mac os 10.15, you can install an older version of cocoapods with this sudo gem install cocoapods -v 1.8.4 source: https://apple.stackexchange.com/a/384384

Option 2.B - If you can, install rbenv, with say ruby 2.7.2, set it rbenv global 2.7.2 and then get the most recent version of cocoapods gem install cocoapods

bubbaspike
  • 101
  • 6
1

I had the same problem after upgrading my Mac from older version to macOS Catalina 10.15.7. This failed.

flutter doctor -v

command. I tried many solutions but nothing worked. Finally, I solved by opening android studio and accepting the file access. After that

run flutter doctor -v command and it worked.

Ersin Akşar
  • 29
  • 1
  • 6
1

for me; reinstall ruby and cocoapods

rvm install ruby --latest

And

sudo gem install cocoapods --pre
Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39
Aazidom
  • 11
  • 1
1

So after weeks and weeks of struggling with this issue, this is what worked for me as turns out a Ruby gem source was out of date (if you get a gem source related error when trying to install Cocoapods, you likely have the same issue):

  1. Ensure that Cocoapods have been fully removed via: gem list --local | grep cocoapods | awk '{print $1}' | xargs sudo gem uninstall

  2. List your current gem sources with gem sources -l

  3. Remove any current sources which are causing an issue using gem sources --remove URL_HERE, such as gem sources --remove https://rubygems.org/

  4. Add this mirror instead gem sources -a https://gems.ruby-china.com/

  5. If installing Cocoapods on a Mac before Mac OS X 10.11: sudo gem install cocoapods, if newer, use: sudo gem install -n /usr/local/bin cocoapods

That's it! A big thank you to https://www.programmersought.com/article/10015547501/

hardanger
  • 2,349
  • 1
  • 16
  • 23
1

After uninstalling and installing cocoa pods the issue isnt fixed. Go into your ios folder delete the podfile.lock and run pod install inside the ios folder. Then completely quit and close your editor and start it again. Then try running the app again.

1

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
yshean
  • 331
  • 3
  • 9
1

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

Esmaeil Ahmadipour
  • 840
  • 1
  • 11
  • 32
GTG
  • 21
  • 6
0

I was having this same issue and this example from (https://guides.cocoapods.org/using/getting-started.html) worked for me

$ cd ios
$ gem which cocoapods
/usr/local/lib/ruby/gems/2.7.0/gems/cocoapods-1.9.3/lib/cocoapods.rb
$ /usr/local/lib/ruby/gems/2.7.0/bin/pod install

The issue for me was that although cocoa pods was installed, the pod executable was not on my path (apparently). Note that the pod install needs to be run from inside the ios directory.

mcgraphix
  • 2,723
  • 1
  • 11
  • 15
0

I was able to resolve this by closing Android Studio and reopening it. ‍♂️

jon
  • 3,202
  • 3
  • 23
  • 35
0

Cocoapods latest version release depends on the new release of Ruby which does not work well with macOS mojave. All you have to do is to install lesser version of cocoapods.

sudo gem install cocoapods -v 1.8.4

Try it out

Bamidele
  • 1
  • 1
0

I use brew on macOS and following steps helped me -

  1. start Xcode and close (this because Xcode may update itself)
  2. brew update
  3. brew upgrade
  4. flutter upgrade (optional if there is a long gap or a stable update is available)
  5. sudo gem update
Gaurav
  • 41
  • 4
0
brew uninstall cocoapods

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

isa
  • 599
  • 7
  • 18
0

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 !

Ax M
  • 330
  • 3
  • 15
0

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

Phuc Tran
  • 7,555
  • 1
  • 39
  • 27
0

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

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

0

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.

saif aly
  • 545
  • 7
  • 8
0

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.

Ash
  • 5,525
  • 1
  • 40
  • 34
0

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.

Manjunath Bilwar
  • 2,215
  • 19
  • 16
0

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)

DoruChidean
  • 7,941
  • 1
  • 29
  • 33
0

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.

Christian X
  • 1,919
  • 1
  • 15
  • 21
0

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
0

Flutter framework

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

enter image description here

Usama Elgendy
  • 506
  • 4
  • 8
0

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 has 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).

ccpizza
  • 28,968
  • 18
  • 162
  • 169
-1

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

slackgate
  • 57
  • 2
  • 7
-1

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