Firebase setup on iOS (Flutter)

1,118

Solution 1

This is my current Podfile setup, you might want to try it:

platform :ios, '12.0'

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

def flutter_install_ios_plugin_pods(ios_application_path = nil)
  ios_application_path ||= File.dirname(defined_in_file.realpath) if self.respond_to?(:defined_in_file)
  raise 'Could not find iOS application path' unless ios_application_path

  symlink_dir = File.expand_path('.symlinks', ios_application_path)
  system('rm', '-rf', symlink_dir) # Avoid the complication of dependencies like FileUtils.

  symlink_plugins_dir = File.expand_path('plugins', symlink_dir)
  system('mkdir', '-p', symlink_plugins_dir)

  plugins_file = File.join(ios_application_path, '..', '.flutter-plugins-dependencies')
  plugin_pods = flutter_parse_plugins_file(plugins_file)
  plugin_pods.each do |plugin_hash|
    plugin_name = plugin_hash['name']
    plugin_path = plugin_hash['path']
    if (plugin_name && plugin_path)
      symlink = File.join(symlink_plugins_dir, plugin_name)
      File.symlink(plugin_path, symlink)

      if plugin_name == 'flutter_ffmpeg'
          pod 'flutter_ffmpeg/full-lts', :path => File.join('.symlinks', 'plugins', plugin_name, 'ios')
      else
          pod plugin_name, :path => File.join('.symlinks', 'plugins', plugin_name, 'ios')
      end
    end
  end
end

target 'Runner' do
  use_frameworks!
  use_modular_headers!

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

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

Solution 2

I had a the same problem solved it simply by changing target to platform :ios, '14.0' in Podfile

then in your project cd ios to your iOS folder - run :

  1. rm -rf Pods/ Podfile.lock

  2. pod repo update

  3. pod install

for M1 Mac Users - run this instead :

  1. rm -rf Pods/ Podfile.lock

  2. sudo arch -x86_64 gem install ffi

  3. arch -x86_64 pod repo update

  4. pod install

error should be gone

--

But you might then be left with this last error :

[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `Runner` to `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` or include the `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` in your build configuration (`Flutter/Release.xcconfig`).

Set configurations in Xcode as showed in this StackOverFlow Answer to solve it

Share:
1,118
Tamás Pintér
Author by

Tamás Pintér

Updated on December 30, 2022

Comments

  • Tamás Pintér
    Tamás Pintér over 1 year

    I'm trying to setup Firebase on iOS in Flutter by following the original guide, but I get the following message after typing pod install in the terminal:

    [!] CocoaPods could not find compatible versions for pod "Firebase/Auth":
      In snapshot (Podfile.lock):
        Firebase/Auth (= 6.34.0, ~> 6.0)
    
      In Podfile:
        firebase_auth (from `.symlinks/plugins/firebase_auth/ios`) was resolved to 1.4.1, which depends on
          Firebase/Auth (= 8.0.0)
    
    
    You have either:
     * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
     * changed the constraints of dependency `Firebase/Auth` inside your development pod `firebase_auth`.
       You should run `pod update Firebase/Auth` to apply changes you've made.
    

    All I changed in the main.dart file is that I changed the default main function to this:

        Future main() async {
          WidgetsFlutterBinding.ensureInitialized();
          await Firebase.initializeApp();
          runApp(MyApp());
        }
    

    My pubspec.yaml file's relevant part looks like this:

    
        firebase_storage: ^8.0.3
        cloud_firestore: ^1.0.5
        firebase_auth: ^1.1.0
    
    

    I choose these numbers based on a video that used null safety, but tried it with several different ones too like the ones that are mentioned here: https://firebase.google.com/docs/flutter/setup#analytics-enabled, and also the latest ones, but the error was the same.

    I tried reinstalling cocoapods and did the pod repo update, pod setup, pod install multiple times but the output was the same. In the Podfile, I uncommented the ios version number and changed it to 10 as many sources recommended. I would appreciate your help on this one.

    EDIT: This was my original Podfile:

        # Uncomment this line to define a global platform for your project
        platform :ios, '10.0'
        
        # 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 |installer|
          installer.pods_project.targets.each do |target|
            flutter_additional_ios_build_settings(target)
          end
        end
    
    

    SOLUTION: I changed my Podfile to this:

    
        platform :ios, '12.0'
        
        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
        
        def flutter_install_ios_plugin_pods(ios_application_path = nil)
          ios_application_path ||= File.dirname(defined_in_file.realpath) if self.respond_to?(:defined_in_file)
          raise 'Could not find iOS application path' unless ios_application_path
        
          symlink_dir = File.expand_path('.symlinks', ios_application_path)
          system('rm', '-rf', symlink_dir) # Avoid the complication of dependencies like FileUtils.
        
          symlink_plugins_dir = File.expand_path('plugins', symlink_dir)
          system('mkdir', '-p', symlink_plugins_dir)
        
          plugins_file = File.join(ios_application_path, '..', '.flutter-plugins-dependencies')
          plugin_pods = flutter_parse_plugins_file(plugins_file)
          plugin_pods.each do |plugin_hash|
            plugin_name = plugin_hash['name']
            plugin_path = plugin_hash['path']
            if (plugin_name && plugin_path)
              symlink = File.join(symlink_plugins_dir, plugin_name)
              File.symlink(plugin_path, symlink)
        
              if plugin_name == 'flutter_ffmpeg'
                  pod 'flutter_ffmpeg/full-lts', :path => File.join('.symlinks', 'plugins', plugin_name, 'ios')
              else
                  pod plugin_name, :path => File.join('.symlinks', 'plugins', plugin_name, 'ios')
              end
            end
          end
        end
        
        target 'Runner' do
          use_frameworks!
          use_modular_headers!
        
          flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
        end
        
        post_install do |installer|
          installer.pods_project.targets.each do |target|
            flutter_additional_ios_build_settings(target)
            target.build_configurations.each do |config|
                config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
            end
          end
        end
    
    
    • Mariano Zorrilla
      Mariano Zorrilla almost 3 years
      you're using outdated version of all 3 libraries. Please, check on pub.dev the latest versions in order to make it work correctly and post your "flutter doctor -v" for more details about your setup
    • zpouip
      zpouip almost 3 years
      Can you add your Podfile?
    • Tamás Pintér
      Tamás Pintér almost 3 years
      I mentioned that I also tried with those ones too, and got the same result unfortunately.
    • Tamás Pintér
      Tamás Pintér almost 3 years
      I edited the original question there you can see my Podfile.
    • Hemal Moradiya
      Hemal Moradiya almost 3 years
      Have you tried pod repo update & pod update?
  • Tamás Pintér
    Tamás Pintér almost 3 years
    I overwritten my Podfile content with this, deleted the podfile.lock file and then ran pod install. The output was the following: pastebin.com/nAXHt2Cm
  • Tamás Pintér
    Tamás Pintér almost 3 years
    I added these lines to your version since it gave me those version errors { target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0' end} and got this error in the output: { Command PhaseScriptExecution failed with a nonzero exit code}
  • Tamás Pintér
    Tamás Pintér almost 3 years
    This finally solved the problem. I changed my Podfile to the edited one that I am going to put in the original post, and then ran pod repo update and pod update which I am not sure helped me or not. Then it worked after waiting 10 minutes of compiling. Thank you!
  • Ara Hussein
    Ara Hussein over 2 years
    Thanks a lot. I spent about more 2 days to solve that issue and your PodFile solve it.
  • Vishak A Kamath
    Vishak A Kamath about 2 years
    I'm using the Mac M1 and this solution worked for me.