我是颤振环境中的新生儿。
我尝试设置与我的应用程序的 Cloud Firestore 连接。我在 VSCode 上完成了大部分编码过程,但在实现 firestore 后,我尝试在 Xcode 中构建,因为我在 VSCode 上遇到了一些错误。
在 Xcode 12.5.1 中构建我的应用程序(我使用 Rosetta 打开)时,出现此错误
我已确保在 Podfile 或我的 Pubspec.yaml 文件中添加依赖项。
我尝试过几种方法,例如:
解体pod并重新安装pod(包括删除podfile.lock和pods目录并重新安装pod)
我已经尝试过
flutter clean
-> flutter pub get
-> flutter build ios
,但仍然导致相同的错误。
我已通过 Xcode 将 GoogleService-Info.plist 导入到我的 Runner 中,并仔细检查名称。
令我感兴趣的是,我还添加了 Firebase_auth 包,它工作得很好。查看仅显示在
的错误有谁知道如何解决这个错误?任何帮助将非常感激。非常感谢🙏
经过几天的尝试和错误,我终于找到了解决办法..
所以,我注意到在为 iOS 构建时可能会导致错误的几件事。
切勿手动运行命令
pod install
。
不要将行
pod install Firebase
添加到您的podfile中。相反,只需使用 $FirebaseSDKVersion = '8.0.0'
覆盖所有 Firebase 依赖项
不要忘记在 podfile 上指定您的 iOS 部署目标,并将其与 Runner.xcworkspace 文件上的部署目标相匹配(在运行程序和目标中)
因此,如果您已经有一个项目,那么这是我推荐的步骤,因为这对我来说非常有效:
删除 Pods 目录、/ios/podfile.lock 和 ios/Flutter/Flutter.podspec
运行
pod deintegrate
删除 DerivedData 文件夹中的所有内容..您可以运行
rm -rf ~/Library/Developer/Xcode/DerivedData/*
运行
flutter clean
运行
flutter pub get
运行
flutter build ios
。请注意,这还将运行 pod install
命令。
关闭编辑器,然后在 XCode 上打开 Runner.xcworkspace 并运行 XCode。清理你的构建文件夹。如果有更新项目设置的选项,请接受它。
您可能会收到一些有关已弃用功能的警告,但就我而言,我的应用程序运行得很好..
我不知道为什么会发生这种情况,但据我观察,Cocoapods 对于 ios 的一些 firebase 软件包有不同的版本..我希望有人能解释一下..
--
注意事项:
如果在 XCode 上构建您的应用程序,然后在终端或 VSCode 上使用
flutter run
,您会收到一些警告,例如 Class AMSupportURLConnectionDelegate is Implemented in Both。因此,根据我的个人经验,我总是从 XCode 运行我的应用程序。
如果您使用 Google 登录,请按照此处的步骤操作,您无需在 podfile 中添加任何内容。
作为参考,这是我的 podfile 内容。
# Uncomment the next line to define a global platform for your project
# platform :ios, '12.0'
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
$FirebaseSDKVersion = '8.0.0'
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)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
end
我希望它对你有用!祝你好运!
可以看到
cloud_firestore
模块已经成功导入到你的iOS项目下了吗
以前的解决方案都不适合我。经过两天的搜索,我将 cocoapods 降级到我知道过去可以使用的旧版本:
-COCOAPODS: 1.11.2
+COCOAPODS: 1.10.1
使用
gem uninstall cocoapods
卸载并安装旧版本。
之后我应用了@reneconrad的答案。
当您打开 .xcodeproj 而不是打开时,可能会出现此错误消息 .xcworkspace 文件。
.xcworkspace 不仅包含应用程序项目本身,还包含 由 cocoapods 生成的项目来管理所有依赖项。