CocoaPods Not Installed or Not in Valid State
When working with Flutter iOS development, you may encounter the error: "CocoaPods not installed or not in valid state." This occurs when there's a mismatch between the Ruby environment used to install CocoaPods and the one Flutter is attempting to use.
Problem Overview
The error typically manifests as:
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 issue stems from version inconsistencies in your Ruby environment, incorrect installation methods, or IDE-related path configuration problems.
Primary Solutions
1. Reinstall CocoaPods with Homebrew
For most users, installing CocoaPods via Homebrew provides the most stable solution:
brew install cocoapods --build-from-source
brew link --overwrite cocoapods
WARNING
During Ruby installation via Homebrew, watch for path instructions in the installation log. You may need to add something like /opt/homebrew/opt/ruby/bin
to your shell configuration file (~/.zshrc
or ~/.bashrc
).
2. Verify Ruby Version Consistency
Check that both your project root and ios
directory use the same Ruby version:
# Check Ruby version in project root
cd your_project_directory
ruby --version
# Check Ruby version in ios directory
cd ios
ruby --version
If versions differ, use a version manager like rbenv
to maintain consistency:
# Install and set default Ruby version
rbenv install 3.1.3
rbenv global 3.1.3
3. Install CocoaPods with User Install Flag
For systems where you don't have administrative access or want to avoid system-wide installations:
# Add Ruby gem path to your environment
echo 'export PATH="$HOME/.gem/ruby/X.X.0/bin:$PATH"' >> ~/.zshrc
# Replace X.X with your Ruby version (e.g., 3.2.0)
source ~/.zshrc
# Install cocoapods for the current user
gem install cocoapods --user-install
4. IDE-Specific Fixes
If the issue is IDE-related (particularly with Android Studio or VS Code):
Invalidate Caches and Restart:
- Android Studio:
File → Invalidate Caches / Restart
- VS Code: Completely quit and restart the application
- Android Studio:
Launch IDE from Terminal:
bash# For Android Studio open /Applications/Android\ Studio.app # For VS Code code .
Additional Troubleshooting Steps
Clear CocoaPods Cache and Reinstall
If the above solutions don't work, try a complete clean reinstall:
# Remove existing cocoapods installations
sudo gem uninstall cocoapods
sudo gem uninstall cocoapods-core
sudo gem uninstall cocoapods-downloader
# Clear cache directories
rm -rf ~/Library/Caches/CocoaPods
rm -rf ios/Pods
# Reinstall cocoapods
gem install cocoapods
Check ActiveSupport Version Compatibility
Some users report issues with specific ActiveSupport versions:
# Check if ActiveSupport is causing issues
sudo gem uninstall activesupport
sudo gem install activesupport -v 7.0.8
Verify Xcode Command Line Tools
Ensure Xcode command line tools are properly installed:
xcode-select --install
Project Directory Considerations
Avoid spaces in project directory names, as they can cause path resolution issues:
# Avoid this:
/my project/flutter_app
# Prefer this:
/my-project/flutter_app
Environment Path Configuration
Verify your shell configuration includes the correct paths:
# Check current PATH
echo $PATH
# Ensure Homebrew paths are included (if using Homebrew)
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Verification
After applying any solution, verify CocoaPods is working correctly:
# Check CocoaPods version
pod --version
# Run Flutter doctor to verify iOS toolchain
flutter doctor
When All Else Fails
If none of the above solutions work:
- Run your app directly from Xcode by opening the
ios
folder in Xcode - Execute
flutter run
from terminal instead of your IDE - Consider creating a new Flutter project and migrating your code
TIP
The most common cause of this issue is Ruby version mismatches. Using a version manager like rbenv
or rvm
can prevent future occurrences by maintaining consistent Ruby environments across your system.
By following these solutions, you should be able to resolve the CocoaPods installation issue and continue with your iOS Flutter development.