我正在使用 Flutter 和 AWS Auth Cognito,当我尝试在 ios 模拟器上运行 flutter run 时,我收到以下错误消息:
leon@MBP app % flutter run --flavor dev
Launching lib/main.dart on iPhone 15 Pro in debug mode...
Running Xcode build...
└─Compiling, linking and signing... 1,531ms
Xcode build done. 11.0s
Failed to build iOS app
Parse Issue (Xcode): Module 'amplify_auth_cognito' not found
/Users/leon/work/app/ios/Runner/GeneratedPluginRegistrant.m:11:8
Could not build the application for the simulator.
Error launching application on iPhone 15 Pro.
但是,如果我通过以下方式启动它。 XCode 我可以在模拟器上构建应用程序,没有任何问题。在 Android 模拟器上,它也可以通过我的 launch.json 中提供的运行命令或 vs-code 运行选项运行。
扑医生:
✓] Flutter (Channel stable, 3.13.8, on macOS 14.3.1 23D60 darwin-arm64, locale en-DE)
• Flutter version 3.13.8 on channel stable at /opt/homebrew/Caskroom/flutter/3.3.2/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 6c4930c4ac (4 months ago), 2023-10-18 10:57:55 -0500
• Engine revision 767d8c75e8
• Dart version 3.1.4
• DevTools version 2.25.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/me/Library/Android/sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15C500b
• CocoaPods version 1.13.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.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.13+0-b1751.21-8125866)
[✓] VS Code (version 1.86.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.82.0
[✓] Connected device (3 available)
• iPhone 15 Pro (mobile) • 8D18B1DA-DB2D-47CA-9D0D-2EBCDC7784E3 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 14.3.1 23D60 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 121.0.6167.184
[✓] Network resources
• All expected network resources are available.
• No issues found!
Podfile:
# Uncomment this line to define a global platform for your project
platform :ios, '15.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)
target.build_configurations.each do |config|
config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
end
end
end
source 'https://cdn.cocoapods.org/'
Pubspec.yaml:
name: app
description: A new Flutter project.
publish_to: "none" # Remove this line if you wish to publish to pub.dev
https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.18.0 <4.0.0"
flutter: ">=3.3.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.5
smooth_page_indicator: ^1.0.0+2
# i18n section
flutter_localizations:
sdk: flutter
intl: ^0.18.0 # flutter_localizations
flutter_riverpod: ^2.3.6
hooks_riverpod: ^2.3.6
flutter_hooks: ^0.18.6
path: ^1.8.1
shared_preferences: ^2.0.15
# Charts
# TODO: Replace with fl_charts. High priority, since syncfusion_flutter_gauges
# has the problem with memory leaks
# Reference: https://github.com/syncfusion/flutter-examples/issues/67
syncfusion_flutter_gauges: ^21.2.4
phosphor_flutter: ^2.0.0
flutter_svg: ^2.0.7
amplify_flutter: ^1.0.0
amplify_auth_cognito: ^1.6.2
amplify_authenticator: ^1.0.0
freezed_annotation: ^2.0.3
json_annotation: ^4.8.1
jiffy: ^5.0.0
dotted_line: ^3.1.0
go_router: ^7.0.1
package_info_plus: ^4.0.2
http: ^0.13.5
dio: ^5.3.0
month_picker_dialog: ^2.0.0
auto_size_text: ^3.0.0
url_launcher: ^6.2.2
graphql: ^5.1.2
graphql_flutter: ^5.1.1
upgrader: ^6.5.0
# Sentry
sentry_flutter: ^7.13.1
sentry_logging: ^7.13.1
sentry_dio: ^7.13.1
logging: ^1.2.0
flutter_secure_storage: ^9.0.0
local_auth: ^2.1.7
local_auth_ios: ^1.1.4
local_auth_android: ^1.0.35
flutter_flavorizr: ^2.2.1
dev_dependencies:
flutter_test:
sdk: flutter
faker: ^2.0.0
flutter_lints: ^2.0.1
mocktail: ^0.3.0
collection: ^1.16.0
build_runner: ^2.4.4
freezed: ^2.0.4
json_serializable: ^6.7.0
integration_test:
sdk: flutter
flutter_driver:
sdk: flutter
test: ^1.24.3
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# Related to i18n section in dependencies
generate: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/Graphics/
- assets/Graphics/onboarding/
- assets/Graphics/logo/
- assets/Graphics/Cards/
- assets/Graphics/tva/
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
fonts:
- family: Inter
fonts:
- asset: assets/google-fonts/Inter/static/Inter-Bold.ttf
weight: 700
- asset: assets/google-fonts/Inter/static/Inter-SemiBold.ttf
weight: 600
- asset: assets/google-fonts/Inter/static/Inter-Regular.ttf
weight: 400
# - family: <Name>
# fonts:
# - asset: <path>.ttf
# style: normal
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
我已经更新了 auth_cogntio 插件,更新了 pod 存储库,解体了 pod,再次安装了 pod 等等。我认为这是一个配置问题,但我不知道还能在哪里查看,因为它通过 XCode 运行运行,但在其他地方都失败了。
我希望它通过 vsCode 运行或终端运行,并通过 ./ios/Runner.xcworkspace UI 构建它
也许其他人也面临同样的问题?
我已经确定了问题的根本原因,这与构建设置有关。具体来说,就是优化级别配置。将优化级别设置为“无”(对于常规构建设置和 Swift 编译器)解决了该问题。
以下是我遵循的步骤:
在构建设置中将优化级别设置为“无”。 在 Swift 编译器设置中设置“无优化”。 进行了颤振清洁。 删除了 Pod 和 Podfile.lock。 重新启动该进程并重新安装 Pod。 此外,我检查了依赖项版本并确保它们更新如下:
amplify_flutter:^2.2.0 至 2.5.0 amplify_auth_cognito:^2.2.0 到 2.5.0 放大核心:^2.2.0 至 2.5.0 最后,我删除并重新添加了 Link Binary with Libraries 中所需的库,这有助于解决链接问题。