繁体   English   中英

将 Firebase 添加到 flutter 应用程序后,iOS 构建失败

[英]iOS build failed after adding Firebase to flutter app

我昨天添加了 Firebase,在 Android 上它没有问题。 当我尝试运行 iOS 应用程序时,出现以下错误消息:

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

我的播客文件如下所示:

# 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

我的 pubspec.yaml 具有以下依赖项:

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

我的 AppDelegate.swift 看起来像这样

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)
  }
}

我已经尝试了 5 个小时不同的解决方案。 我已经尝试过的:

  • 确保通过 Xcode 添加了 GoogleService-Info.plist 文件

  • 删除 Podfile & Podfile.lock

  • 取消注释platform:ios, '9.0' ,也尝试使用版本 10.0 和 12.0

  • 手动将 pod 添加到 Podfile:

    pod 'Firebase/分析'

    pod 'Firebase/Core'

    pod 'Firebase/Auth'

    pod 'Firebase/Firestore'

它实际上在某个时候成功构建,但随后应用程序在启动时立即崩溃,所以我用 flutter create 完全重建了 ios 文件夹,但不知道该怎么做了。

更新

现在将 podfile 更改为:

 # 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

解决了构建错误,但当我想启动它时应用程序仍然立即崩溃

我昨天添加了Firebase,在Android上可以正常使用。 当我尝试运行iOS-app时,出现以下错误消息:

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

我的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 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

我的pubspec.yaml具有以下依赖关系:

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

我的AppDelegate.swift看起来像这样

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)
  }
}

我已经尝试了5个小时的其他解决方案。 我已经尝试过的:

  • 确保通过Xcode添加了GoogleService-Info.plist文件

  • 删除Podfile和Podfile.lock

  • 取消注释的platform :ios, '9.0' Podfile中的platform :ios, '9.0' ,也尝试在版本10.0和12.0中使用

  • 将Pod手动添加到Podfile:

    pod“ Firebase / Analytics”

    pod“ Firebase / Core”

    pod“ Firebase / Auth”

    pod“ Firebase / Firestore”

它实际上在某个时候成功构建,但是随后应用程序在启动时立即崩溃,因此我用flutter create完全重建了ios文件夹,不知道该怎么办了。

更新

现在将podfile更改为:

 # 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

解决了构建错误,但是当我要启动该应用程序时,该应用程序仍然立即崩溃

我有相同的代码(完全相同),但这个错误继续在我身边。

打开ios/Runner/AppDelegate.swift

您需要放置此代码

FirebaseApp.configure()

在这个之前

GeneratedPluginRegistrant.register(with: self)

您将在AddDelegate.swift中看到这样的内容。

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)
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM