CocoaPods not installed or not in valid state

IosFlutterDart

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

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

Solution 2 - Ios

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.

Solution 3 - Ios

I had the same issue. Following worked for me

  1. Clean projct
  2. User terminal to flutter run
  3. Its an IDE related issue not flutter or cocoapods

Solution 4 - Ios

Reinstalling the flutter extension on visual code fixed this

Solution 5 - Ios

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

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

Solution 6 - Ios

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

Solution 7 - Ios

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.

Solution 8 - Ios

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

Solution 9 - Ios

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

  1. flutter clean
  2. restart vscode

Solution 10 - Ios

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

Solution 11 - Ios

Try with:

pod setup
brew link --overwrite cocoapods

after commands, restart IDE

Solution 12 - Ios

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

Solution 13 - Ios

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

Solution 14 - Ios

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

Solution 15 - Ios

Try doing this,

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

And check,

flutter doctor

Solution 16 - Ios

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.

Solution 17 - Ios

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.

Solution 18 - Ios

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.

Solution 19 - Ios

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.

Solution 20 - Ios

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

Solution 21 - Ios

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.

Solution 22 - Ios

for me; reinstall ruby and cocoapods

rvm install ruby --latest

And

sudo gem install cocoapods --pre

Solution 23 - Ios

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/

Solution 24 - Ios

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

brew uninstall fastlane
gem install fastlane

Solution 25 - Ios

below code work for me on terminal:

> flutter run

Solution 26 - Ios

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.

Solution 27 - Ios

Uninstall the existing cocoapods, if is any, and Reinstalling again

There is two way to install cocoapods by using homebrew & gem.

If you had install cocoapods using gem run following.

  1. sudo gem uninstall cocoapods
  2. sudo gem uninstall -n /usr/local/bin cocoapods
  3. cocoapods pod install

If you had used brew please using the following to uninstall

  1. Reinstall cocoapods brew uninstall cocoapods

If you see the error message after you reinstall cocoapods by brew reinstall go to step 2.

  1. To solve conflicting files brew link --overwrite cocoapods

If you get -bash: pod: command not found error, all instances are removed properly. Else, you may need to remove cocoapods related files manually from this directory ~/.rvm/rubies/ruby-2.5.3/lib/ruby.

  1. sudo gem update --system
  2. gem install cocoapods

Solution 28 - Ios

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

Solution 29 - Ios

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

Solution 30 - Ios

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

Solution 31 - Ios

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.

Solution 32 - Ios

brew uninstall cocoapods

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

Solution 33 - Ios

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 !

Solution 34 - Ios

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionrahul rawatView Question on Stackoverflow
Solution 1 - IosAgyakwalfView Answer on Stackoverflow
Solution 2 - IosBeethoventhepoetView Answer on Stackoverflow
Solution 3 - IosMuhammad AbdulSalamView Answer on Stackoverflow
Solution 4 - IosshrhawkView Answer on Stackoverflow
Solution 5 - IosSaurav PantheeView Answer on Stackoverflow
Solution 6 - IosBasanthView Answer on Stackoverflow
Solution 7 - IosheymonkeyriotView Answer on Stackoverflow
Solution 8 - IosYonatan NaorView Answer on Stackoverflow
Solution 9 - IosfigureaiView Answer on Stackoverflow
Solution 10 - IosAshwin PrabhuView Answer on Stackoverflow
Solution 11 - IosMattiaView Answer on Stackoverflow
Solution 12 - IostonymontanaView Answer on Stackoverflow
Solution 13 - IosC. SwansonView Answer on Stackoverflow
Solution 14 - IosGJJ2019View Answer on Stackoverflow
Solution 15 - IosAshwin BalaniView Answer on Stackoverflow
Solution 16 - IosaabiroView Answer on Stackoverflow
Solution 17 - IosAustris CirulnieksView Answer on Stackoverflow
Solution 18 - IosPaul KastelView Answer on Stackoverflow
Solution 19 - IosMaksym KovalenkoView Answer on Stackoverflow
Solution 20 - IosbubbaspikeView Answer on Stackoverflow
Solution 21 - IosErsin AkşarView Answer on Stackoverflow
Solution 22 - IosAazidomView Answer on Stackoverflow
Solution 23 - IoshardangerView Answer on Stackoverflow
Solution 24 - IosHashem AboonajmiView Answer on Stackoverflow
Solution 25 - Iosalireza daryaniView Answer on Stackoverflow
Solution 26 - IosmcgraphixView Answer on Stackoverflow
Solution 27 - IosParesh MangukiyaView Answer on Stackoverflow
Solution 28 - IosjonView Answer on Stackoverflow
Solution 29 - IosBamideleView Answer on Stackoverflow
Solution 30 - IosGauravView Answer on Stackoverflow
Solution 31 - IosDavid JosephView Answer on Stackoverflow
Solution 32 - IosisaView Answer on Stackoverflow
Solution 33 - IosAx MView Answer on Stackoverflow
Solution 34 - IosAndrey GordeevView Answer on Stackoverflow