skip to Main Content

I’m a newborn in flutter environment.

I was trying to setup a Cloud Firestore connection to my app. I did most of the coding process on VSCode, but after implementing firestore, I tried building in Xcode since I got some error on VSCode.

Upon building my app in Xcode 12.5.1 (which I opened using Rosetta), I got this error
Error when building app – Module ‘cloud_firestore’ not found

I’ve make sure to add the dependencies either in Podfile or in my Pubspec.yaml file.

Here is My podfile and here is my pubspec.yaml dependencies pubspec.yaml dependencies

I’ve tried several things such as:

  1. Deintegrate pod and installing pod again(including deleting the podfile.lock and pods directory and reinstalling the pod again)

  2. I’ve tried flutter clean -> flutter pub get -> flutter build ios, but still resulting in the same error.

  3. I have imported my GoogleService-Info.plist to my Runner via Xcode and double checking the name.

What intrigue me is, I also add Firebase_auth package and it works just fine. See the error only showing at the import Cloud Firestore line

Does anyone know how to resolve this error? Any help would be very much appreciated. Thank you so much 🙏

3

Answers


  1. Chosen as BEST ANSWER

    Finally after days of trying and error, I found a way to work it out..

    So, I noticed several things that might cause an error when building for iOS.

    1. Never run the command pod install manually.

    2. Do not add the line pod install Firebase to your podfile. Instead, just override all of the firebase dependencies using $FirebaseSDKVersion = '8.0.0'

    3. Don't forget to specify your iOS Deployment target on your podfile and match it with the deployment target on your Runner.xcworkspace file (Both in the runner and in the target)

    So, if you already have a project, here are the steps I recommend, as this works perfectly for me:

    1. Delete the Pods directory, the /ios/podfile.lock, and the ios/Flutter/Flutter.podspec

    2. Run pod deintegrate

    3. Delete all of the contents inside your DerivedData folder.. you can run rm -rf ~/Library/Developer/Xcode/DerivedData/*

    4. Run flutter clean

    5. Run flutter pub get

    6. Run flutter build ios. Note thas this will also run the pod install command.

    7. Close your editor, and open your Runner.xcworkspace on XCode and run your XCode. Clean your build folder. If there's an option to update your project settings, accept it.

    You might get several warnings about deprecated functions, but in my case, my app run just fine..

    I don't know about the details on why it happened, but from what I noticed, Cocoapods have a different version of some of the firebase packages for ios.. I hope someone can explain it..

    --

    Things to note :

    • If build your app on XCode, and then use flutter run either on terminal or VSCode, you would get some warnings like Class AMSupportURLConnectionDelegate is implemented in both. So, from my personal experience, I always run my app from XCode.

    • If you use Google Sign In, follow the steps here you don't need to add anything in your podfile.

    For reference, here is my podfile content.

    # Uncomment the next line to define a global platform for your project
     # platform :ios, '12.0'
    
    ENV['COCOAPODS_DISABLE_STATS'] = 'true'
    
    $FirebaseSDKVersion = '8.0.0'
    
    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)
        target.build_configurations.each do |config|
         config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
         config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
        end
      end
    end
    

    I hope it works for you! Goodluck!


  2. Can you see that the cloud_firestore module has been successfully imported under your iOS project?

    Login or Signup to reply.
  3. Non of the previous solutions worked for me. After two days of searching I downgraded cocoapods to an older version that I knew had worked in the past:

    -COCOAPODS: 1.11.2
    +COCOAPODS: 1.10.1
    
    

    Uninstalled with gem uninstall cocoapods and installed the old version.
    After that I applied @reneconrad’s answer.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search