我昨天添加了 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
我的 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 个小时不同的解决方案。 我已经尝试过的:
确保 GoogleService-Info.plist 文件是通过 Xcode 添加的
删除Podfile和Podfile.lock
platform :ios, '9.0'
,也尝试使用版本 10.0 & 12.0
pod“Firebase/分析”
pod“Firebase/Core”
pod“Firebase/Auth”
pod“Firebase/Firestore”
更新
# 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
解决了构建错误,但当我想启动它时应用程序仍然立即崩溃
我终于找到了问题,我只需要将 FirebaseApp.configure()
移到
GeneratedPluginRegistrant.register(with: self)
上方,这样就不是 AppDelegate.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)
}
}