iosflutterpodfile

How to add pod dependencies in a flutter project manually


I created a flutter project and a Podfile was generated automatically. I need to add the following dependencies into my project,

pod 'GMGdtAdapter-Beta', '4.15.40.1'
pod 'GMKsAdapter-Beta', '3.3.76.1'

May I ask if I should add these two lines at the end of the auto-generated Profile? like

... ...

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

pod 'GMGdtAdapter-Beta', '4.15.40.1'
pod 'GMKsAdapter-Beta', '3.3.76.1'

Or if I should add them in the Runner target like,

... ...

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  pod 'GMGdtAdapter-Beta', '4.15.40.1'
  pod 'GMKsAdapter-Beta', '3.3.76.1'

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
  target 'RunnerTests' do
    inherit! :search_paths
  end
end

... ...

Thanks in advance!


Solution

  • The short answer is: You should add it inside Runner target.

    ---------------

    To manually add a CocoaPods dependency to an iOS Flutter project, follow these steps:

    ✅ 1. Open your iOS Podfile

    In your Flutter project, navigate to:

    your_flutter_project/ios/Podfile
    

    ✅ 2. Add your Pod inside the target 'Runner' do block

    For example, to add SDWebImage:

    target 'Runner' do
      use_frameworks!
      use_modular_headers!
    
      flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
    
      # Add your pod here
      pod 'SDWebImage', '~> 5.0'
    end
    

    ✅ 3. Run pod install

    After saving the Podfile:

    cd ios
    pod install
    

    ✅ 4. (Optional) Clean and rebuild

    Sometimes it's useful to clean and rebuild your Flutter project:

    flutter clean
    flutter pub get
    flutter run
    

    ⚠️ Notes