iosswiftfirebaseflutterbuild-error

iOS build failed after adding Firebase to flutter app


I added Firebase yesterday, on Android it works without problems. When I try to run the iOS-app the following error message appears:

Downloading ios tools...
Downloading ios-profile tools...
Downloading ios-release tools...
Running "flutter pub get" in ripped...
Launching lib/main.dart on iPhone 11 Pro in debug mode...
Running Xcode build...
Xcode build done.                                           21.9s
Could not build the application for the simulator.
Error launching application on iPhone 11 Pro.
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **


Xcode's output:
↳
    /Users/michi/Coding/flutter/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.16.2/darwin/Classes/AudioplayersPlugin.m:89:37: warning: incompatible pointer types sending 'FlutterEngine *' to parameter of type 'NSObject<FlutterBinaryMessenger> * _Nonnull' [-Wincompatible-pointer-types]
                        binaryMessenger:_headlessEngine];
                                        ^~~~~~~~~~~~~~~
    In module 'Flutter' imported from /Users/michi/Coding/flutter/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.16.2/darwin/Classes/AudioplayersPlugin.h:2:
    /Users/michi/AndroidStudioProjects/ripped/ios/Flutter/Flutter.framework/Headers/FlutterChannels.h:178:74: note: passing argument to parameter 'messenger' here
                          binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger;
                                                                             ^
    /Users/michi/Coding/flutter/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.16.2/darwin/Classes/AudioplayersPlugin.m:482:74: warning: 'initWithImage:' is deprecated: first deprecated in iOS 10.0 - Use -initWithBoundsSize:requestHandler: [-Wdeprecated-declarations]
                  MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage: artworkImage];
                                                                             ^
    In module 'MediaPlayer' imported from /Users/michi/Coding/flutter/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.16.2/darwin/Classes/AudioplayersPlugin.m:7:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaItem.h:240:1: note: 'initWithImage:' has been explicitly marked deprecated here
    - (instancetype)initWithImage:(UIImage *)image MP_DEPRECATED("Use -initWithBoundsSize:requestHandler:", ios(5.0, 10.0));
    ^
    2 warnings generated.
    /Users/michi/Coding/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_analytics-6.2.0/ios/Classes/FLTFirebaseAnalyticsPlugin.m:49:19: warning: 'setScreenName:screenClass:' is deprecated: Use +[FIRAnalytics logEventWithName:kFIREventScreenView parameters:] instead. [-Wdeprecated-declarations]
        [FIRAnalytics setScreenName:screenName screenClass:screenClassOverride];
                      ^
    In module 'FirebaseAnalytics' imported from /Users/michi/AndroidStudioProjects/ripped/ios/Pods/Headers/Public/Firebase/Firebase.h:22:
    /Users/michi/AndroidStudioProjects/ripped/ios/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers/FIRAnalytics.h:115:5: note: 'setScreenName:screenClass:' has been explicitly marked deprecated here
        DEPRECATED_MSG_ATTRIBUTE(
        ^
    In module 'UIKit' imported from /Users/michi/AndroidStudioProjects/ripped/ios/Pods/Target Support Files/firebase_analytics/firebase_analytics-prefix.pch:2:
    In module 'Foundation' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:8:
    In module 'CoreFoundation' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6:
    In module 'Darwin' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:16:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.0.sdk/usr/include/AvailabilityMacros.h:181:64: note: expanded from macro 'DEPRECATED_MSG_ATTRIBUTE'
                #define DEPRECATED_MSG_ATTRIBUTE(s) __attribute__((deprecated(s)))
                                                                   ^
    1 warning generated.
    /Users/michi/Library/Developer/Xcode/DerivedData/Runner-ctrarkqgeeshcpdfedxiktkemfwl/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.build/Script-7CA6D22A4148A35EEC636DD2.sh: line 2: /Users/michi/AndroidStudioProjects/ripped/ios/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh: Permission denied
    Command PhaseScriptExecution failed with a nonzero exit code
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Constructing build description

My podfile looks like this:

# 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 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

My pubspec.yaml has the following dependencies:

dependencies:
  firebase_core: ^0.5.2
  firebase_analytics: ^6.2.0
  cloud_firestore: ^0.14.3
  firebase_auth: ^0.18.3
  percent_indicator: ^2.1.8
  numberpicker: ^1.2.1
  email_validator: ^1.0.6
  simple_animations: ^2.2.3
  audioplayers: ^0.16.1
  expandable: ^4.1.4
  smooth_page_indicator: ^0.2.0
  auto_size_text: ^2.1.0
  tab_indicator_styler: ^1.0.0
  flutter_gradient_colors: ^1.0.0
  font_awesome_flutter: ^8.8.1
  flutter_svg:
  flutter:
    sdk: flutter

My AppDelegate.swift looks like this

import UIKit
import Flutter
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    FirebaseApp.configure()
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

I have been trying different solutions for 5 hours. What I have already tried:

It actually built succesfully at some point but then the app crashed instantly when starting so I completely rebuilt the ios folder with flutter create and don't know what to do anymore.

UPDATE

now changing the podfile to:

 # 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
    
    # add pods for any other desired Firebase products
    # https://firebase.google.com/docs/ios/setup#available-pods
      pod 'Firebase/Analytics'
      pod 'Firebase/Core'
      pod 'Firebase/Auth'
      pod 'Firebase/Firestore'
    
      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

resolved the build error but the app still crashes immediately when I want to start it


Solution

  • thanks to How to fix iOS crash during the start Firebase configure in Flutter? I finally found the issue, I just had to move FirebaseApp.configure() one line up so that it is above GeneratedPluginRegistrant.register(with: self), so not the AppDelegate.swift file looks like this:

    import UIKit
    import Flutter
    import Firebase
    
    @UIApplicationMain
    @objc class AppDelegate: FlutterAppDelegate {
      override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
      ) -> Bool {
        FirebaseApp.configure()
        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
      }
    }