iosswiftflutterflutter-dependenciespodfile

Which is the right way to generate a Podfile in flutter?


For me, there are two ways to generate a pod file after deleting it the first one is by running flutter pub get and then a pod file will be generated in the following form after some editing

# Uncomment this line to define a global platform for your project
 platform :ios, '10.0'
pod 'Firebase/Analytics' #ATTENTION PLEASE SHOULD I ADD THESE PODS HERE?
pod 'Firebase/Auth'
pod 'Firebase/Firestore'
pod 'Firebase/Database'
pod 'Firebase/Messaging'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |pi|
    pi.pods_project.targets.each do |t|
      t.build_configurations.each do |config|
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0’
      end
    end
end

then running pod install


And the other implementation is when I run pod init i get the following after some editing:

# Uncomment the next line to define a global platform for your project
 platform :ios, '10.0'
pod 'Firebase/Analytics'
pod 'Firebase/Auth'
pod 'Firebase/Firestore'
pod 'Firebase/Database'
pod 'Firebase/Messaging'

target 'Runner' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for Runner

end

post_install do |pi|
    pi.pods_project.targets.each do |t|
      t.build_configurations.each do |config|
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0’
      end
    end
end

then run pod install... which is the right way to use flutter and build and run ios apps, as I am so confused and I can't run my app in ios form. more details are in this issue I would be pleased if someone helps me


Solution

  • Alright, in flutter you don't have to install the pods in your Podfile like pod 'Firebase/Messaging' just put them in your pubspec file, run pod cache clean --all, delete your Podfile then run flutter pub get and flutter will generate the Podfile for you, then you should just uncomment the second line and run pod install and run your app