'Android studio flutter project giving pod not installed error

I have already installed cocoapods in my Mac.

Cocoapods

 $ pod --version
1.9.3

$ which pod
/Users/user/.rbenv/shims/pod

$  which gem
/Users/user/.rbenv/shims/gem

$  which ruby
/Users/user/.rbenv/shims/ruby

Problem

But if I add device specific codes like I setup firebase or add geolocator plugin, then clicking on Android studio Run green button, I always get below error:

Launching lib/main.dart on iPhone 11 Pro in debug mode...
Warning: CocoaPods not installed. Skipping pod install.
  CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
  Without CocoaPods, plugins will not work on iOS or macOS.
  For more info, see https://flutter.dev/platform-plugins
To install:
  sudo gem install cocoapods

CocoaPods not installed or not in valid state.
Error launching application on iPhone 11 Pro.

What didn't worked

  • I updated Mac OS Catalina (10.15.6)
  • I re-installed cocoapods couple of times, with different approaches (with homebrew, with system ruby, with rbenv ruby)
  • Updated to latest xcode

It didn't worked

What works

Finally, if I run below command in terminal it is working as expected:

flutter build ios --simulator
flutter run

So, I think its an issue with Android Studio. anyone else facing this issue, and have workaround for this problem?

Requirement

  • I want android studio to run project when I click on Android Studio Run icon.


Solution 1:[1]

This is not a android studio issue, it is a pod version issue for flutter. Please downgrade your cocoapods and try again.

Here is my solution.

sudo gem uninstall cocoapods
sudo gem install cocoapods -v 1.7.5
pod setup
sudo gem install cocoapods

Update: if you got still issue, please open it on xcode project and try run it. once you fixed issue on xcode, it will work on android studio, too

Update 2: please check your flutter sdk path. if there is any Capital letters, it can cause the issue.

Update 3: Try using Android Studio on termnial if all above methods do not work.

open /Applications/Android\ Studio.app 

Solution 2:[2]

Try launching Android Studio from Terminal:

open /Applications/Android\ Studio.app

It would then use another PATH variable than if started with launchpad. And that PATH would contain valid path to CocoaPods.

Taken from https://github.com/flutter/flutter-intellij/issues/4981#issuecomment-751443625

Solution 3:[3]

Yes, It's an Android Studio issue and this worked for me

flutter clean in flutter project dir

In Android Studio: File > Invalidate Caches / Restart > Invalidate and Restart

Now the project should run on Android Studio when you click on the run button.

Solution 4:[4]

this is happened to me on vscode because cocoapods is looking for ruby version 2.6 and what I did to fix it with rbenv

rbenv global 2.6.8
gem install cocoapods

then restart vscode

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Alexey Inkin
Solution 3 heyt0pe
Solution 4 surga