firebase / flutterfire

πŸ”₯ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.73k stars 3.98k forks source link

πŸ› [firebase_core] [iOS] could not build module 'firebase_core' #7184

Closed DarkKnight1005 closed 2 years ago

DarkKnight1005 commented 3 years ago

Error after first firebase integration:

Xcode's output:
↳
    While building module 'firebase_core' imported from /Users/ayazpanahov/Documents/cap_mobile-master/ios/Runner/GeneratedPluginRegistrant.m:22:
    In file included from <module-includes>:1:
    In file included from /Users/ayazpanahov/Documents/cap_mobile-master/build/ios/Debug-iphoneos/firebase_core/firebase_core.framework/Headers/firebase_core-umbrella.h:13:
    In file included from /Users/ayazpanahov/Documents/cap_mobile-master/build/ios/Debug-iphoneos/firebase_core/firebase_core.framework/Headers/FLTFirebaseCorePlugin.h:11:
    /Users/ayazpanahov/Documents/cap_mobile-master/build/ios/Debug-iphoneos/firebase_core/firebase_core.framework/Headers/FLTFirebasePlugin.h:9:9: error: include of non-modular header inside framework module
    'firebase_core.FLTFirebasePlugin': '/Users/ayazpanahov/Documents/cap_mobile-master/build/ios/Debug-iphoneos/FirebaseCore/FirebaseCore.framework/Headers/FirebaseCore.h'
    [-Werror,-Wnon-modular-include-in-framework-module]
    #import "FirebaseCore.h"
            ^
    1 error generated.
    /Users/ayazpanahov/Documents/cap_mobile-master/ios/Runner/GeneratedPluginRegistrant.m:22:9: fatal error: could not build module 'firebase_core'
    #import <firebase_core/FLTFirebaseCorePlugin.h>
     ~~~~~~~^
    2 errors generated.
    note: Using new build system
    note: Planning
    note: Build preparation complete
    note: Building targets in parallel
    note: Removed stale file
    '/Users/ayazpanahov/Library/Developer/Xcode/DerivedData/Runner-fsbkgrvkbqooehagsdflyjgomodn/Build/Intermediates.noindex/Runner.build/Debug-iphoneos/Runner.build/Script-E8A0874E9F12B2C01AF6E81F.sh'

The issue can be resolved if in GeneratedPluginRegistrant.m the 3rd line of the following block:

...
#if __has_include(<firebase_core/FLTFirebaseCorePlugin.h>)
#import <firebase_core/FLTFirebaseCorePlugin.h>
#else
@import firebase_core;
#endif
...

will be changed to

#import "FLTFirebaseCorePlugin.h"

However, editing the GeneratedPluginRegistrant.m is only possible if building purely with XCode, when building with flutter by flutter run command, then the previous file being overwritten by flutter and build error occurring again.

Expected behavior: A successful build for the iOS simulator

All Flutter Packages:

dependencies:
  flutter_svg: ^0.22.0
  flutter_inappwebview: ^5.3.2
  getwidget: ^2.0.3
  otp_text_field: ^1.1.1
  pin_code_fields: ^7.3.0
  dio: ^4.0.0
  provider: ^5.0.0
  fule_scaffold: ^0.1.1
  sembast: ^3.1.0+2
  flutter_datetime_picker: ^1.5.1
  stacked: ^2.2.3
  kiwi: ^3.0.0
  shared_preferences: ^2.0.6
  openapi_generator_annotations: ^1.1.4
  get_storage: ^2.0.3
  get: ^4.3.8
  jwt_decoder: ^2.0.1
  fluttertoast: ^8.0.8
  open_file: ^3.2.1
  path_provider: ^2.0.3
  local_auth: ^1.1.7
  package_info_plus: ^1.0.6
  device_info_plus: ^3.0.1
  super_easy_permissions: ^0.1.1
  uni_links: ^0.5.1
  after_layout: ^1.1.0
  firebase_core: ^1.7.0
  socket_io_client: ^1.0.1
  firebase_analytics: ^8.3.3
  argon_buttons_flutter: ^1.1.0
  flutter_launcher_icons: "^0.9.2"

Podfile:

# Uncomment this line to define a global platform for your project
platform :ios, '12.3'

# 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
  pod 'Firebase/Analytics'

  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.3'
    end
  end
end

Flutter doctor:

[βœ“] Flutter (Channel stable, 2.5.2, on macOS 11.6 20G165 darwin-x64, locale en)
    β€’ Flutter version 2.5.2 at /Users/ayazpanahov/Files/FlutterSDK/flutter
    β€’ Upstream repository https://github.com/flutter/flutter.git
    β€’ Framework revision 3595343e20 (2 weeks ago), 2021-09-30 12:58:18 -0700
    β€’ Engine revision 6ac856380f
    β€’ Dart version 2.14.3

[βœ“] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc3)
    β€’ Android SDK at /Users/ayazpanahov/Library/Android/sdk
    β€’ Platform android-31, build-tools 31.0.0-rc3
    β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    β€’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    β€’ All Android licenses accepted.

[βœ“] Xcode - develop for iOS and macOS
    β€’ Xcode at /Applications/Xcode.app/Contents/Developer
    β€’ Xcode 13.0, Build version 13A233
    β€’ CocoaPods version 1.11.2

[βœ“] Chrome - develop for the web
    β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[βœ“] Android Studio (version 2020.3)
    β€’ Android Studio at /Applications/Android Studio.app/Contents
    β€’ Flutter plugin can be installed from:
      πŸ”¨ https://plugins.jetbrains.com/plugin/9212-flutter
    β€’ Dart plugin can be installed from:
      πŸ”¨ https://plugins.jetbrains.com/plugin/6351-dart
    β€’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[βœ“] IntelliJ IDEA Ultimate Edition (version 2020.2.4)
    β€’ IntelliJ at /Applications/IntelliJ IDEA.app
    β€’ Flutter plugin version 55.1.2
    β€’ Dart plugin version 202.8488

[βœ“] VS Code (version 1.61.0)
    β€’ VS Code at /Applications/Visual Studio Code.app/Contents
    β€’ Flutter extension version 3.27.0

[βœ“] VS Code (version 1.49.0)
    β€’ VS Code at /Users/ayazpanahov/Desktop/Visual Studio Code.app/Contents
    β€’ Flutter extension version 3.27.0

[βœ“] Connected device (4 available)
    β€’ SM G975F (mobile)           β€’ R58M352GZWD               β€’ android-arm64  β€’ Android 11 (API 30)
    β€’ iPad 11 Pro M1 AIH (mobile) β€’ 00008103-000A692236EB001E β€’ ios            β€’ iOS 15.0.2 19A404
    β€’ macOS (desktop)             β€’ macos                     β€’ darwin-x64     β€’ macOS 11.6 20G165 darwin-x64
    β€’ Chrome (web)                β€’ chrome                    β€’ web-javascript β€’ Google Chrome 92.0.4515.107

β€’ No issues found!
darshankawar commented 3 years ago

The issue can be resolved if in GeneratedPluginRegistrant.m the 3rd line of the following block:

You can't edit the file since it's autogenerated. Whatever changes you'll make, it will be reset during build run.

Can you try:

pod cache clean β€”all
flutter clean
flutter pub get
pod install
DarkKnight1005 commented 3 years ago

The issue can be resolved if in GeneratedPluginRegistrant.m the 3rd line of the following block:

You can't edit the file since it's autogenerated. Whatever changes you'll make, it will be reset during build run.

Can you try:

pod cache clean β€”all
flutter clean
flutter pub get
pod install

Did it several times, not working. Also did

pod deintegrate

not woking.

darshankawar commented 3 years ago

@DarkKnight1005 It could be a conflict with 3rd party plugins with the podfile. I tried a sample app with firebase_core on iphone simulator using latest stable and it worked properly as expected. Maybe you can try to delete podfile.lock and then podfile and regenerate it using pod install, pod repo update and then flutter run.

Thanks.

DarkKnight1005 commented 3 years ago

@DarkKnight1005 It could be a conflict with 3rd party plugins with the podfile. I tried a sample app with firebase_core on iphone simulator using latest stable and it worked properly as expected. Maybe you can try to delete podfile.lock and then podfile and regenerate it using pod install, pod repo update and then flutter run.

Thanks.

Thanks, for the reply, although I did everything you mentioned unfortunately this is not working. What exactly can cause ta problem? Which 3rd party plugins may malfunction the work of firebase?

Thanks in advance.

darshankawar commented 3 years ago

@DarkKnight1005 I tried sample code using the plugins you are using and ran it properly. Can you try to create a new project, copy over all the plugins and podfile and run it to if that also gives you same error or not ?

DarkKnight1005 commented 3 years ago

@DarkKnight1005 I tried sample code using the plugins you are using and ran it properly. Can you try to create a new project, copy over all the plugins and podfile and run it to if that also gives you same error or not ?

I Created a new project, copied and pasted all the stuff in info.plist,podfile and pubspec.yaml. And again I have the same issue.

Here is output:

Xcode's output:
↳
    FirebaseAnalytics-djjomtodwlzjdhekzzoluegsmtfp
    While building module 'firebase_core' imported from /Users/ayazpanahov/Desktop/FlutterProjects/AIH/cap_mobile_flutter/ios/Runner/GeneratedPluginRegistrant.m:22:
    In file included from <module-includes>:1:
    In file included from /Users/ayazpanahov/Desktop/FlutterProjects/AIH/cap_mobile_flutter/build/ios/Debug-iphoneos/firebase_core/firebase_core.framework/Headers/firebase_core-umbrella.h:13:
    In file included from /Users/ayazpanahov/Desktop/FlutterProjects/AIH/cap_mobile_flutter/build/ios/Debug-iphoneos/firebase_core/firebase_core.framework/Headers/FLTFirebaseCorePlugin.h:11:
    /Users/ayazpanahov/Desktop/FlutterProjects/AIH/cap_mobile_flutter/build/ios/Debug-iphoneos/firebase_core/firebase_core.framework/Headers/FLTFirebasePlugin.h:9:9: error: include of non-modular header inside framework module 'firebase_core.FLTFirebasePlugin': '/Users/ayazpanahov/Desktop/FlutterProjects/AIH/cap_mobile_flutter/build/ios/Debug-iphoneos/FirebaseCore/FirebaseCore.framework/Headers/FirebaseCore.h' [-Werror,-Wnon-modular-include-in-framework-module]
    #import "FirebaseCore.h"
            ^
    1 error generated.
    /Users/ayazpanahov/Desktop/FlutterProjects/AIH/cap_mobile_flutter/ios/Runner/GeneratedPluginRegistrant.m:22:9: fatal error: could not build module 'firebase_core'
    #import <firebase_core/FLTFirebaseCorePlugin.h>
     ~~~~~~~^
    2 errors generated.
    FirebaseAnalytics-djjomtodwlzjdhekzzoluegsmtfp
    note: Using new build system
    note: Planning
    note: Build preparation complete
    note: Building targets in parallel
    /Users/ayazpanahov/Desktop/FlutterProjects/AIH/cap_mobile_flutter/ios/Pods/Pods.xcodeproj: warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.0.99. (in target 'OrderedSet' from project 'Pods')
    /Users/ayazpanahov/Desktop/FlutterProjects/AIH/cap_mobile_flutter/ios/Pods/Pods.xcodeproj: warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.0.99. (in target 'Toast' from project 'Pods')
Could not build the precompiled application for the device.

Error launching application on iPad 11 Pro M1 AIH.
Exited (sigterm)
darshankawar commented 3 years ago

Keeping it open for further insights from the team on this, as there have been similar reported issues in the past:

https://github.com/FirebaseExtended/flutterfire/issues/5284 https://github.com/FirebaseExtended/flutterfire/issues/7175

DarkKnight1005 commented 3 years ago

There are some problems with Flutter 2.5.x. Downgrading to v2.2.0 fixed the problem.

Solution: downgrade to v2.2.0

Dear FlutterFire team, please fix the problem with Flutter + Firebase on version 2.5.x.

danielroek commented 3 years ago

Experiencing the same issue. Downgrading to Flutter v2.2.0 did not solve the problem. Xcode output:

Xcode's output:
↳
    remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
    Command CompileSwiftSources failed with a nonzero exit code
    While building module 'firebase_core' imported from /Users/daniel/.pub-cache/hosted/pub.dartlang.org/firebase_crashlytics-2.3.0/ios/Classes/FLTFirebaseCrashlyticsPlugin.h:12:
    In file included from <module-includes>:1:
    In file included from /Users/daniel/projects/baseflow/hypex_molamola_app/ios/Pods/Target Support Files/firebase_core/firebase_core-umbrella.h:13:
    In file included from /Users/daniel/.pub-cache/hosted/pub.dartlang.org/firebase_core-1.10.0/ios/Classes/FLTFirebaseCorePlugin.h:12:
    /Users/daniel/.pub-cache/hosted/pub.dartlang.org/firebase_core-1.10.0/ios/Classes/FLTFirebasePlugin.h:9:9: error: include of non-modular header inside framework module 'firebase_core.FLTFirebasePlugin':
    '/Users/daniel/projects/baseflow/hypex_molamola_app/ios/Pods/Headers/Public/FirebaseCore/FirebaseCore.h' [-Werror,-Wnon-modular-include-in-framework-module]
    #import <FirebaseCore/FirebaseCore.h>
            ^
    1 error generated.
    In file included from /Users/daniel/.pub-cache/hosted/pub.dartlang.org/firebase_crashlytics-2.3.0/ios/Classes/FLTFirebaseCrashlyticsPlugin.m:5:
    /Users/daniel/.pub-cache/hosted/pub.dartlang.org/firebase_crashlytics-2.3.0/ios/Classes/FLTFirebaseCrashlyticsPlugin.h:12:9: fatal error: could not build module 'firebase_core'
    #import <firebase_core/FLTFirebasePlugin.h>
     ~~~~~~~^
    2 errors generated.
    note: Using new build system
    note: Planning
    note: Build preparation complete
    note: Building targets in parallel

Encountered error while building for device.

Flutter doctor output (not using this machine for Android):

[βœ“] Flutter (Channel stable, 2.5.3, on macOS 11.6 20G165 darwin-x64, locale nl-NL)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    βœ— cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    βœ— Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[βœ“] Xcode - develop for iOS and macOS
[βœ“] Chrome - develop for the web
[βœ“] Android Studio (version 4.1)
[βœ“] IntelliJ IDEA Ultimate Edition (version 2020.2.2)
[βœ“] Connected device (1 available)

! Doctor found issues in 1 category.

pubspec.yml:

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter_svg: ^0.23.0+1
  equatable: ^2.0.3
  flutter_reactive_ble: ^4.0.0
  fluro: ^2.0.3
  pull_to_refresh_notification: ^2.2.0
  dotted_border: ^2.0.0+1
  permission_handler: ^8.0.0
  firebase_core: ^1.10.0
  firebase_crashlytics: ^2.3.0
  flutter_bloc: ^7.3.1
  fluttertoast: ^8.0.8
  shared_preferences: ^2.0.0
  rxdart: ^0.27.2
  tuple: ^2.0.0
  package_info: ^2.0.2
  path_provider: ^2.0.0
  connectivity: ^3.0.6
  quiver: ^3.0.1+1
  dio: ^4.0.1
  ini: ^2.1.0
  url_launcher: ^6.0.0
  wakelock: ^0.5.6
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.3
  flutter_cached_pdfview: ^0.4.0-nullsafety
  flutter_pdfview: ^1.2.1

dev_dependencies:
  flutter_test:
    sdk: flutter

  # Plugin which helps generating launch icons
  flutter_launcher_icons: ^0.9.2

When creating a new project, with the same dependencies, I'm getting te following output:

Xcode's output:
↳
    /Users/daniel/projects/test/firebase_core_issue_test/ios/Runner/GeneratedPluginRegistrant.m:12:9: fatal error: module 'firebase_core' not found
    @import firebase_core;
     ~~~~~~~^~~~~~~~~~~~~
    1 error generated.
    note: Using new build system
    note: Planning
    note: Build preparation complete
    note: Building targets in parallel
MilanMeurrens commented 3 years ago

What worked for me is using the precompiled version for the Firestore iOS SDK as something went wrong during compilation. See 'Improve iOS Build Times' section at https://firebase.flutter.dev/docs/overview/#initializing-flutterfire

See this answer on StackOverflow: https://stackoverflow.com/questions/69813789/flutter-ios-how-to-fix-could-not-build-module-firebase-core/69943297#69943297

emmanuel-montoya commented 2 years ago

Having same issue and trying all steps and comments... not working..

geoffn commented 2 years ago

I am experience the same issue ever since I upgraded to the new flutter version and the new firebase_core process. Project that was working fine ceased to be able to build. I have tried a clean project and then downloading my code, same issue. I am running on the M1 processor and have tried multiple fixes including arch -x86_64 pod install and the suggested items from Milan above. None have worked.

Failed to build iOS app Error output from Xcode build: ↳ objc[2138]: Class AMSupportURLConnectionDelegate is implemented in both /usr/lib/libauthinstall.dylib (0x1f1216b90) and /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x1044682c8). One of the two will be used. Which one is undefined. objc[2138]: Class AMSupportURLSession is implemented in both /usr/lib/libauthinstall.dylib (0x1f1216be0) and /Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x104468318). One of the two will be used. Which one is undefined. BUILD FAILED

Xcode's output: ↳ /Users/geoffnelson/Documents/code/flutter/baseuserauth/ios/Runner/GeneratedPluginRegistrant.m:12:9: fatal error: module 'firebase_auth' not found @import firebase_auth;


    1 error generated.
    note: Using new build system
    note: Planning
    note: Build preparation complete
    note: Building targets in dependency order
    /Users/geoffnelson/Documents/code/flutter/baseuserauth/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported
    deployment target versions is 9.0 to 15.2.99. (in target 'AppAuth' from project 'Pods')
    /Users/geoffnelson/Documents/code/flutter/baseuserauth/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported
    deployment target versions is 9.0 to 15.2.99. (in target 'GoogleSignIn' from project 'Pods')
geoffn commented 2 years ago

I downgraded flutter to 2.5.3 and was then able to build my application. This is not resolved but at least I have a path to work on this existing project.

russellwheatley commented 2 years ago

I've just ran on Flutter stable channel latest 2.8.1 targeting iOS 10 and had no problems. Can anyone else confirm it works on latest?

geoffn commented 2 years ago

My issue looks to be resolved after upgrading. Was able to successfully run my project.

sabbir-riseuplabs commented 2 years ago

I am facing the same issue. I have done everything. pod deintegrate pod upgrate pod install flutter update flutter clean

I am using flutter 2.8.1. I have updated all the package. But I am still getting firebase_core issue.

/Users/user/Documents/Projects/LENTHO-Frontend/ios/Runner/GeneratedPluginRegistrant.m:16:9: Could not build module 'firebase_core'

Anyone has found a solution for this?

geoffn commented 2 years ago

Upgrading to 2.8.1 worked to resolve my issue. I am also running firebase_core version 1.10.6. However, I did downgrade flutter to 2.5.3 and this resolved my issue so that I could continue to work before 2.8.1. You could try that and see if resolves your problem. Pretty straight forward process documented here https://stackoverflow.com/questions/49468321/how-to-downgrade-flutter-sdk-dart-1-x. There was also an issue with xcode 13.2 and you should make sure you are on 13.2.1. Not sure if that was an issue though. Hope this helps or points you in a better direction.

sabbir-riseuplabs commented 2 years ago

@geoffn Yeah. I am using 13.2 Xcode. For me 2.8.1 is not working. I created a new project and checked. But I got the same issue. What can be the problem?

pr-Mais commented 2 years ago

@sabbir-riseuplabs can you run the following and check if the problem still persists?

flutter pub cache repair
benedict1986 commented 2 years ago

I have this issue as well today and resolved by referring to the solution mentioned in https://github.com/FirebaseExtended/flutterfire/issues/3272#issuecomment-696070834

The steps I take

  1. Remove ios/Pods folder.
  2. Copy PodFile (since I have some customised code)
  3. Remove Podfile and Podfile.lock
  4. Remove pubspec.lock

5* . Run pod cache clean β€”all in terminal 6.Run flutter clean in terminal

  1. Run flutter pub get in terminal
  2. Copy the backed up Podfile, mainly the customised code, back to newly regenerated Podfile
  3. Run pod install in terminal

Please note, step 5 is mentioned in the referred solution but I actually did not run it.

I am using

firebase_core: ^1.11.0 firebase_crashlytics: ^2.4.5

Xcode version is 13.2.1

russellwheatley commented 2 years ago

Given the lack of traffic on this issue and the fact it has been resolved, I'm going to close this issue out. If you are still experiencing this problem, it is almost certainly a caching issue. I would refer you to follow the advice set out in the above comment by @benedict1986 to help clear all build cache.