flutter: fatal error: module 'firebase_analytics' not found

Viewed 3761

After adding firebase dependency on iOS, when I want to run then I get this error

Xcode's output:
↳
    ../ios/Runner/GeneratedPluginRegistrant.m:10:9: fatal error: module
    'firebase_analytics' not found
    @import firebase_analytics;
     ~~~~~~~^~~~~~~~~~~~~~~~~~
    1 error generated.
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Constructing build description

Could not build the precompiled application for the device.

Error launching application on Abir's iPhone.

I already tried many way. like delete pod file, pod update, pod install etc.

5 Answers

Its problem with openning Runner. Open Runner.xcworkspace not Runner.xcodeproj.enter image description here

I had this same error and here is how to solve it.

  1. Delete the DerivedData from Xcode folder. Open Runner.xcworkspace inside the ios folder of your flutter project then click File -> Workspace Settings -> Click the grey arrow beside DerivedData path and delete the DerivedData inside the Xcode folder. enter image description here

enter image description here

  1. Delete both Podfile and Podfile.lock files inside ios folder of your flutter project.
  2. Change the Deployment Target to 12.0. You will find the Deployment Target under General -> Deployment Info.

enter image description here

  1. Clean your ios build folder.

enter image description here

  1. Run your app (it will generate a new podfile, do not edit this podfile) It should work.

pod repo update or with pod install --repo-update

Matching the Deployment Target under General -> Deployment Info with the platform :ios, '11.0' version in Podfile solved the issue for me.

I was using a very old Mac mini with Catalina. I had to switch to Mac Mini M1 with latest XCode. Plus had make my Podfile looks like this.

# Uncomment this line to define a global platform for your project
platform :ios, '12.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
Related