Flutterfire: [Cloud Firestore] fatal error: module 'cloud_firestore' not found

Created on 11 Feb 2020  Â·  25Comments  Â·  Source: FirebaseExtended/flutterfire

Describe the bug

I can't build my iOS application.

To Reproduce
Steps to reproduce the behavior:

flutter build ios

See error or incorrect behavior

 /$MY_FLUTTER_PJT/ios/Runner/GeneratedPluginRegistrant.m:10:9: fatal error: module
    'cloud_firestore' not found
    @import cloud_firestore;
     ~~~~~~~^~~~~~~~~~~~~~~
    1 error generated.

I also tried to build it via XCode, but I ran into the same error.

I tried the following commands:

flutter clean
rm ios/Pod*
flutter build ios

But it failed too.

customer-response crowd bug

Most helpful comment

I think I managed to workaround the issue.

I got this error as well after integrating cocoapods myself with pod init (by following this guide). The created Podfile is a bare one.

I removed cocoapods entirely, deleting the Podfile/Podfile.lock and everything associated to cocoapods, restored the project.pbxproj file to the version before cocapods integration.

Then I ran flutter run. This command seems to create a Podfile if there is no exisiting one, and this Podfile contains much more stuff than the bare one creating with pod init.

Then I was able to add my Firestore pod, then run pod install, then build again without errors.

Hope this help.

My final Podfile:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.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 parse_KV_file(file, separator='=')
  file_abs_path = File.expand_path(file)
  if !File.exists? file_abs_path
    return [];
  end
  generated_key_values = {}
  skip_line_start_symbols = ["#", "/"]
  File.foreach(file_abs_path) do |line|
    next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
    plugin = line.split(pattern=separator)
    if plugin.length == 2
      podname = plugin[0].strip()
      path = plugin[1].strip()
      podpath = File.expand_path("#{path}", file_abs_path)
      generated_key_values[podname] = podpath
    else
      puts "Invalid plugin specification: #{line}"
    end
  end
  generated_key_values
end

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  # Flutter Pod
  pod 'Firebase/Firestore'

  copied_flutter_dir = File.join(__dir__, 'Flutter')
  copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
  copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
  unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
    # Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
    # That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
    # CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.

    generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
    unless File.exist?(generated_xcode_build_settings_path)
      raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
    end
    generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
    cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];

    unless File.exist?(copied_framework_path)
      FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
    end
    unless File.exist?(copied_podspec_path)
      FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
    end
  end

  # Keep pod path relative so it can be checked into Podfile.lock.
  pod 'Flutter', :path => 'Flutter'

  # Plugin Pods

  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
  # referring to absolute paths on developers' machines.
  system('rm -rf .symlinks')
  system('mkdir -p .symlinks/plugins')
  plugin_pods = parse_KV_file('../.flutter-plugins')
  plugin_pods.each do |name, path|
    symlink = File.join('.symlinks', 'plugins', name)
    File.symlink(path, symlink)
    pod name, :path => File.join(symlink, 'ios')
  end
end

# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
install! 'cocoapods', :disable_input_output_paths => true

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end

All 25 comments

I have the same error for firebase_admob on iOS.
After following the steps presented in the firebase_admob flutter plugin and running

flutter build iOS

I receive:

ios/Runner/GeneratedPluginRegistrant.m:10:9: fatal
    error: module 'firebase_admob' not found
    @import firebase_admob;
     ~~~~~~~^~~~~~~~~~~~~~
    1 error generated.

It works fine on android.

Yeah. I have the same issue.

I solved this issue executing the following steps.

  • Designate the latest version of the library in pubspec.yaml ( cloud_firestore: "^0.13.2+1" )
flutter clean
cd ios
rm Pods
pod install
cd ..
flutter run

I solved this issue executing the following steps.

  • Designate the latest version of the library in pubspec.yaml ( cloud_firestore: "^0.13.2+1" )
flutter clean
cd ios
rm Pods
pod install
cd ..
flutter run

It's not working for me. I'm still get the same error just like this.

Launching lib/main.dart on iPhone X in debug mode...

Running pod install...                                              1.7s
Running Xcode build...                                                  

 ├─Assembling Flutter resources...                          18.3s
 └─Compiling, linking and signing...                         4.6s
Xcode build done.                                           28.8s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **


Xcode's output:
↳
    /Users/yudisetiawan/IdeaProjects/flutter_firestore_todo/ios/Runner/GeneratedPluginRegistrant.m:10:9: fatal error: module
    'cloud_firestore' not found
    @import cloud_firestore;
     ~~~~~~~^~~~~~~~~~~~~~~
    1 error generated.
    note: Using new build system
    note: Planning build
    note: Constructing build description

Could not build the application for the simulator.
Error launching application on iPhone X.

@CoderJava
Are you using the latest version of coocoapods?

@CoderJava
Are you using the latest version of coocoapods?

I'm used 1.8.4

@CoderJava

My environment is the following.

Flutter 1.15.3-pre.58 • channel master • github:flutter/flutter.git
Framework • revision f769bcc5c4 (30 hours ago) • 2020-02-10 20:55:48 -0500
Engine • revision e4f46f32f1
Tools • Dart 2.8.0 (build 2.8.0-dev.8.0 fd992e423e)

@CoderJava

My environment is the following.

Flutter 1.15.3-pre.58 • channel master • github:flutter/flutter.git
Framework • revision f769bcc5c4 (30 hours ago) • 2020-02-10 20:55:48 -0500
Engine • revision e4f46f32f1
Tools • Dart 2.8.0 (build 2.8.0-dev.8.0 fd992e423e)

Okay, I will test to switch my Flutter channel to master.

@CoderJava

My environment is the following.

Flutter 1.15.3-pre.58 • channel master • github:flutter/flutter.git
Framework • revision f769bcc5c4 (30 hours ago) • 2020-02-10 20:55:48 -0500
Engine • revision e4f46f32f1
Tools • Dart 2.8.0 (build 2.8.0-dev.8.0 fd992e423e)

Hhhmmm.... I don't know why it's not working for me. I have already switch my Flutter channel to master but, I'm still get the same error. 😞
Screen Shot 2020-02-12 at 4 56 36 PM

I solved this issue executing the following steps.

  • Designate the latest version of the library in pubspec.yaml ( cloud_firestore: "^0.13.2+1" )
flutter clean
cd ios
rm Pods
pod install
cd ..
flutter run

I also tried that with firebase_admob: "^0.9.0+10" also not working for me. I have tried linking a new app to firebase, similar error 'firebase_core' not found. I am also using cocoapods version 1.8.4. I downgraded to 1.8.0, same issue.

I think I managed to workaround the issue.

I got this error as well after integrating cocoapods myself with pod init (by following this guide). The created Podfile is a bare one.

I removed cocoapods entirely, deleting the Podfile/Podfile.lock and everything associated to cocoapods, restored the project.pbxproj file to the version before cocapods integration.

Then I ran flutter run. This command seems to create a Podfile if there is no exisiting one, and this Podfile contains much more stuff than the bare one creating with pod init.

Then I was able to add my Firestore pod, then run pod install, then build again without errors.

Hope this help.

My final Podfile:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.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 parse_KV_file(file, separator='=')
  file_abs_path = File.expand_path(file)
  if !File.exists? file_abs_path
    return [];
  end
  generated_key_values = {}
  skip_line_start_symbols = ["#", "/"]
  File.foreach(file_abs_path) do |line|
    next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
    plugin = line.split(pattern=separator)
    if plugin.length == 2
      podname = plugin[0].strip()
      path = plugin[1].strip()
      podpath = File.expand_path("#{path}", file_abs_path)
      generated_key_values[podname] = podpath
    else
      puts "Invalid plugin specification: #{line}"
    end
  end
  generated_key_values
end

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  # Flutter Pod
  pod 'Firebase/Firestore'

  copied_flutter_dir = File.join(__dir__, 'Flutter')
  copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
  copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
  unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
    # Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
    # That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
    # CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.

    generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
    unless File.exist?(generated_xcode_build_settings_path)
      raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
    end
    generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
    cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];

    unless File.exist?(copied_framework_path)
      FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
    end
    unless File.exist?(copied_podspec_path)
      FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
    end
  end

  # Keep pod path relative so it can be checked into Podfile.lock.
  pod 'Flutter', :path => 'Flutter'

  # Plugin Pods

  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
  # referring to absolute paths on developers' machines.
  system('rm -rf .symlinks')
  system('mkdir -p .symlinks/plugins')
  plugin_pods = parse_KV_file('../.flutter-plugins')
  plugin_pods.each do |name, path|
    symlink = File.join('.symlinks', 'plugins', name)
    File.symlink(path, symlink)
    pod name, :path => File.join(symlink, 'ios')
  end
end

# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
install! 'cocoapods', :disable_input_output_paths => true

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end

@ncuillery thanks a lot, indeed that was my issue, I also used pod init and my Podfile was almost empty, therefore pod install wasn't installing anything.

Hi @hrsma2i
does these answers [1, 2] fix the issue?
thank you

@iapicca
Yes, the 2nd answer does.
I have yet to try the first answer.

Hi @hrsma2i
I'm glad that you solved the issue
thank you for letting me know

help guys i need help!!!

Xcode's output:
↳
/Users/builder/clone/ios/Runner/GeneratedPluginRegistrant.m:10:9: fatal error: module 'cloud_firestore' not found
@import cloud_firestore;
~^~~~~
1 error generated.
/Users/builder/clone/ios/Runner/GeneratedPluginRegistrant.m:10:9: fatal error: module 'cloud_firestore' not found
@import cloud_firestore;
~^~~~~
1 error generated.
note: Using new build system
note: Planning build
note: Constructing build description

Encountered error while building for device.

seems pod install in windows do not import dependeces

how to solve????

Could everyone who still has this problem please file a new issue with the exact descriptions what happens, logs and the output of 'flutter doctor -v' please.
All system setups can be slightly different so it's always better to open new issues and reference related issues.

I have the exact same issue and none of the workarounds described here and in related issues work (flutter clean, remove and reinstall pods etc.). Any updates on this?

First of all open iOS project with xcode and fix platform from runner and version etc from target ...

Ok i do that function for me ...erase pod folder ...and pod file under iOS flutter project ..
Install covoapods with MacOS terminal
Install Android studio on MacOS

Under Android studio ...
Run flutter clean
Run flutter pub get
Run flutter pug upgrade
Run flutter build iOS

Android studio create correct POD file

And flutter build iOS

After that open project with xcode
And product > Archive

if my target in xcode is 12.1 build successful
if I change it to 10.3 this error comes!

I tried all of the above. Nothing does the trick.

if my target in xcode is 12.1 build successful
if I change it to 10.3 this error comes!

I works for me :D

The official document in pub.dev tells everything.

iOS

Using the Firebase Console, add an iOS app to your project.
Follow the assistant, download the generated GoogleService-Info.plist file. Do NOT follow the steps named "Add Firebase SDK" and "Add initialization code" in the Firebase assistant.
Open ios/Runner.xcworkspace with Xcode, and within Xcode place the GoogleService-Info.plist file inside ios/Runner.

Solution
I tried creating new flutter project with lib/, pubspec.yaml copied, and it worked.

adding lines onto xcode project workspace following "Add Firebase SDK" may prevent flutter from processing installation. so try my solution or try removing cocoapods library dependencies instead of deleting all the project.

Was this page helpful?
0 / 5 - 0 ratings