211
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.
5
  • 2
    have you tried to run the command from the error message sudo gem install cocoapods Commented Jun 26, 2020 at 11:44
  • Try same command sudo gem install cocoapods still have same issue , Commented Jun 27, 2020 at 13:23
  • 2
    flutter doctor 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. Commented Jun 27, 2020 at 13:28
  • 2
    I am using macbook air M1 chip. I am facing this issue since so long. Can someone help me with this? Commented Feb 4, 2022 at 5:18
  • Just restarting the IDE worked.. Commented Mar 12, 2023 at 16:37

55 Answers 55

203

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

Sign up to request clarification or add additional context in comments.

15 Comments

Simply restarting my IDE fixed it for me.
Trick was to close VS Code completely, for me.
This does not work for me. Strangely enough, running flutter run and through Xcode works but not from Android Studio.
@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.
@DeliciaFernandes do you know whats the reason? I am facing also same issue.
|
119

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.

11 Comments

Starting from the command line fixed the issue but I'm really curious how I can fix this for real...
Same thing, how to fix this for good? It's not a problem to run it from the terminal but....
Oddly enough running "flutter run" from the terminal in Android Studio works but click the play button does not.
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.
Worked for me '' open /Applications/Android\ Studio.app '' thanks
|
51

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

5 Comments

works like charm after replacing intel mac studio to m1 mac studio! thanks [:
flutter run works for me but not with Android Studio and I have no clue how to fix it now.
@Zenko Workaround is to start Android Studio via terminal: open /Applications/Android\ Studio.app
This works, but how can we fix it for good?
Don't works for me :(
44

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

5 Comments

Worked for my mac + android studio
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.
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.
This was the answer it worked for me on MacOS using flutter doctor
brew link --overwrite cocoapods was the key. Thanks
42

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

  1. flutter clean
  2. flutter pub get
  3. Reload VSCode
  4. flutter run

3 Comments

After I did flutter run from the command line, it worked normally.
its works for me flutter run
Perfect ! simple asf and work like a god !
30

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.

1 Comment

Don't forget to restart the editor if you modified the PATH variable COCOAPODS
28

Reinstalling the flutter extension on visual code fixed this

2 Comments

^ I look at this answer and try updating Flutter plugin on my IDEA. It works. @MyKoryto it should not be in the comment.
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
27

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

3 Comments

cocoapods is for iOS, not Android.
@HammadKhan It is used via Flutter.
@DarShan yes per my understanding it is used only for iOS inside Xcode, not for Android. So Flutter will include cocoa only for iOS and not for Android because Xcode requires it.
27

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

3 Comments

correctly, almost half day clean ad get... (:
I spent nearly 1.5 hours trying to figure out before I found your comment. Thank you!
Ah, that is the stupidest thing! Thanks though!
22

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

4 Comments

This will break any Fastlane builds just fyi.
I struggled for days to fix my broken cocoapods but this did it. Also, only use it as a last resort after everything else has failed.
@KennethMurerwa Glad, it worked for you!
that's what did it for me, too (didn't have to add --build-from-source, though. gem install cocoapods didn't work for some reason
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

Comments

8

Try with:

pod setup
brew link --overwrite cocoapods

after commands, restart IDE

Comments

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 ❗️❗️❗️

Comments

7

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.

1 Comment

Those who are facing issues with fastlane, this is the fix.
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

Comments

5

Try doing this,

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

And check,

flutter doctor

Comments

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.

Comments

4

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

1 Comment

This helped, thanks!
4

Same issue and fixed with the next steps:

  1. pod install
  2. restart vscode

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
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

Comments

2

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

Comments

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!

Comments

2

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

Comments

2

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

1 Comment

Followed the instruction from[[ guides.cocoapods.org/using/getting-started.html#installation | here]] and then I had to add the following to .zshrc instead of bashrc ``` export GEM_HOME=$HOME/.gem export PATH=$GEM_HOME/bin:$PATH ```
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.

1 Comment

PATH is my case which after mac migaration.
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.

Comments

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

Comments

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.

Comments

1

for me; reinstall ruby and cocoapods

rvm install ruby --latest

And

sudo gem install cocoapods --pre

Comments

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/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.