The Flutter error CocoaPods not installed or not in valid state
occurs when the CocoaPods dependency manager is not installed or configured properly on your system. This can prevent Flutter from building and running iOS or macOS apps that use plugins. To fix this error, you need to install and update CocoaPods and make sure it is added to your PATH environment variable.
Install CocoaPods from the terminal
This solution involves using the gem command-line tool to install CocoaPods from the terminal or command prompt. This is the official and recommended way to install CocoaPods, as it ensures that you have the latest and most compatible version of the tool.
The steps:
1. Open a terminal or command prompt and run the following command to install CocoaPods:
sudo gem install cocoapods
If prompted, enter your password and wait for the installation to finish.
2. Restart your terminal or IDE (VS Code, Android Studio, etc) and run the following command to check the version of CocoaPods:
pod --version
3. Run flutter doctor
to check if the error is resolved.
Install CocoaPods from Homebrew
This approach uses the Homebrew package manager to install CocoaPods from the terminal. This is an alternative way to install CocoaPods, especially if you already have Homebrew installed or prefer to use it for managing your packages.
1. Open a terminal and run the following command to install CocoaPods from Homebrew:
brew install cocoapods
Wait for the installation to finish.
2. Run the following command to check the version of CocoaPods:
pod --version
3. As always, the final step is to run flutter doctor
to make sure things work as expected.