You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加Flavor/Xcode Scheme后无法通过命令行构建Flutter项目

Flutter多环境Flavor配置:Xcode可运行但终端/Android Studio构建失败

按照教程为Flutter项目配置了Flavor,Xcode中可以正常运行应用,但使用Android Studio或执行终端命令flutter run --flavor doctor -t lib/main_doctor.dart时,Xcode构建阶段失败,报错信息如下:

Error output from Xcode build:
↳
** BUILD FAILED **


Xcode's output:
↳
Writing result bundle at path:
/var/folders/8k/shgdr8gj3gn9lzsh9rlpsxn00000gn/T/flutter_tools.AJouME/flutter_ios_build_temp_dircFYIpM/temporary_xcresult_bundle

/Users/macbook/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.4/ios/Classes/Extensions/CLPlacemarkExtensions.m:22:18: warning: 'addressDictionary' is deprecated: first deprecated in iOS 11.0 - Use @properties [-Wdeprecated-declarations]
if (self.addressDictionary != nil) {
^
In module 'CoreLocation' imported from /Users/macbook/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.4/ios/Classes/Extensions/CLPlacemarkExtensions.h:10:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/System/Library/Frameworks/CoreLocation.framework/Headers/CLPlacemark.h:76:63: note: 'addressDictionary' has been explicitly marked deprecated here
@property (nonatomic, readonly, copy, nullable) NSDictionary *addressDictionary API_DEPRECATED("Use @properties", macos(10.8, 10.13), ios(5.0, 11.0), watchos(1.0, 4.0));
^
/Users/macbook/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.4/ios/Classes/Extensions/CLPlacemarkExtensions.m:23:29: warning: 'addressDictionary' is deprecated: first deprecated in iOS 11.0 - Use @properties [-Wdeprecated-declarations]
street = [[self addressDictionary] objectForKey:(NSString *)kABPersonAddressStreetKey];
^
In module 'CoreLocation' imported from /Users/macbook/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.4/ios/Classes/Extensions/CLPlacemarkExtensions.h:10:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/System/Library/Frameworks/CoreLocation.framework/Headers/CLPlacemark.h:76:63: note: property 'addressDictionary' is declared deprecated here
@property (nonatomic, readonly, copy, nullable) NSDictionary *addressDictionary API_DEPRECATED("Use @properties", macos(10.8, 10.13), ios(5.0, 11.0), watchos(1.0, 4.0));
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/System/Library/Frameworks/CoreLocation.framework/Headers/CLPlacemark.h:76:63: note: 'addressDictionary' has been explicitly marked deprecated here
/Users/macbook/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.4/ios/Classes/Extensions/CLPlacemarkExtensions.m:23:73: warning: 'kABPersonAddressStreetKey' is deprecated: first deprecated in iOS 9.0 - use CNPostalAddress.street [-Wdeprecated-declarations]
street = [[self addressDictionary] objectForKey:(NSString *)kABPersonAddressStreetKey];
^
In module 'AddressBook' imported from /Users/macbook/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.4/ios/Classes/Extensions/CLPlacemarkExtensions.m:8:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/System/Library/Frameworks/AddressBook.framework/Headers/ABPerson.h:113:29: note: 'kABPersonAddressStreetKey' has been explicitly marked deprecated here
AB_EXTERN const CFStringRef kABPersonAddressStreetKey AB_DEPRECATED("use CNPostalAddress.street");
^
3 warnings generated.
/Users/macbook/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.4/ios/Classes/Extensions/CLPlacemarkExtensions.m:22:18: warning: 'addressDictionary' is deprecated: first deprecated in iOS 11.0 - Use @properties [-Wdeprecated-declarations]
if (self.addressDictionary != nil) {
^
In module 'CoreLocation' imported from /Users/macbook/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.4/ios/Classes/Extensions/CLPlacemarkExtensions.h:10:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/System/Library/Frameworks/CoreLocation.framework/Headers/CLPlacemark.h:76:63: note: 'addressDictionary' has been explicitly marked deprecated here
@property (nonatomic, readonly, copy, nullable) NSDictionary *addressDictionary API_DEPRECATED("Use @properties", macos(10.8, 10.13), ios(5.0, 11.0), watchos(1.0, 4.0));
^
/Users/macbook/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.4/ios/Classes/Extensions/CLPlacemarkExtensions.m:23:29: warning: 'addressDictionary' is deprecated: first deprecated in iOS 11.0 - Use @properties [-Wdeprecated-declarations]
street = [[self addressDictionary] objectForKey:(NSString *)kABPersonAddressStreetKey];
^
In module 'CoreLocation' imported from /Users/macbook/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.4/ios/Classes/Extensions/CLPlacemarkExtensions.h:10:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/System/Library/Frameworks/CoreLocation.framework/Headers/CLPlacemark.h:76:63: note: property 'addressDictionary' is declared deprecated here
@property (nonatomic, readonly, copy, nullable) NSDictionary *addressDictionary API_DEPRECATED("Use @properties", macos(10.8, 10.13), ios(5.0, 11.0), watchos(1.0, 4.0));
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/System/Library/Frameworks/CoreLocation.framework/Headers/CLPlacemark.h:76:63: note: 'addressDictionary' has been explicitly marked deprecated here
/Users/macbook/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.4/ios/Classes/Extensions/CLPlacemarkExtensions.m:23:73: warning: 'kABPersonAddressStreetKey' is deprecated: first deprecated in iOS 9.0 - use CNPostalAddress.street [-Wdeprecated-declarations]
street = [[self addressDictionary] objectForKey:(NSString *)kABPersonAddressStreetKey];
^
In module 'AddressBook' imported from /Users/macbook/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.4/ios/Classes/Extensions/CLPlacemarkExtensions.m:8:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/System/Library/Frameworks/AddressBook.framework/Headers/ABPerson.h:113:29: note: 'kABPersonAddressStreetKey' has been explicitly marked deprecated here
AB_EXTERN const CFStringRef kABPersonAddressStreetKey AB_DEPRECATED("use CNPostalAddress.street");
^
3 warnings generated.
/Users/macbook/.pub-cache/hosted/pub.dartlang.org/location-4.4.0/ios/Classes/LocationPlugin.m:176:13: warning: 'UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead [-Wdeprecated-declarations]
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location is Disabled"
^
In module 'UIKit' imported from /Users/macbook/Code/bookmd_flutter/ios/Pods/Target Support Files/location/location-prefix.pch:2:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAlertView.h:27:12: note: 'UIAlertView' has been explicitly marked deprecated here
@interface UIAlertView : UIView
^
/Users/macbook/.pub-cache/hosted/pub.dartlang.org/location-4.4.0/ios/Classes/LocationPlugin.m:176:48: warning: 'UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead [-Wdeprecated-declarations]
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location is Disabled"
^
In module 'UIKit' imported from /Users/macbook/Code/bookmd_flutter/ios/Pods/Target Support Files/location/location-prefix.pch:2:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAlertView.h:27:12: note: 'UIAlertView' has been explicitly marked deprecated here
@interface UIAlertView : UIView
^
2 warnings generated.
/Users/macbook/.pub-cache/hosted/pub.dartlang.org/location-4.4.0/ios/Classes/LocationPlugin.m:176:13: warning: 'UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead [-Wdeprecated-declarations]
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location is Disabled"
^
In module 'UIKit' imported from /Users/macbook/Code/bookmd_flutter/ios/Pods/Target Support Files/location/location-prefix.pch:2:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAlertView.h:27:12: note: 'UIAlertView' has been explicitly marked deprecated here
@interface UIAlertView : UIView
^
/Users/macbook/.pub-cache/hosted/pub.dartlang.org/location-4.4.0/ios/Classes/LocationPlugin.m:176:48: warning: 'UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead [-Wdeprecated-declarations]
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location is Disabled"
^
In module 'UIKit' imported from /Users/macbook/Code/bookmd_flutter/ios/Pods/Target Support Files/location/location-prefix.pch:2:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAlertView.h:27:12: note: 'UIAlertView' has been explicitly marked deprecated here
@interface UIAlertView : UIView
^
2 warnings generated.

Failed to package /Users/macbook/Code/bookmd_flutter.
Command PhaseScriptExecution failed with a nonzero exit code
note: Building targets in dependency order
warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Runner' from project 'Runner')
warning: Run script build phase 'Thin Binary' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Runner' from project 'Runner')
/Users/macbook/Code/bookmd_flutter/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 9.0, but the range of supported deployment target versions is 11.0 to 16.1.99. (in target 'PhoneNumberKit' from project 'Pods')
/Users/macbook/Code/bookmd_flutter/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 9.0, but the range of supported deployment target versions is 11.0 to 16.1.99. (in target 'GoogleMaps' from project 'Pods')

Result bundle written to path:
/var/folders/8k/shgdr8gj3gn9lzsh9rlpsxn00000gn/T/flutter_tools.AJouME/flutter_ios_build_temp_dircFYIpM/temporary_xcresult_bundle


Could not build the application for the simulator.
Error launching application on iPhone 14 Pro Max.

已尝试的修复方法

  • 执行flutter clean命令
  • 执行flutter upgrade命令
  • 删除pod文件夹、解除pod集成并重新安装
  • 删除./pub-cache/文件夹
  • 删除Derived Data和Cocoa Pods缓存
  • 执行flutter pub cache repair命令

解决方案

1. 统一iOS部署目标版本

打开iOS项目根目录下的Podfile,添加以下配置,强制所有Pods的部署目标与项目保持一致(建议设置为11.0及以上):

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
    end
  end
end

修改后执行cd ios && pod install重新安装依赖。

2. 校验Flavor配置一致性

  • 确认Xcode中存在名为doctor的Scheme,且该Scheme对应的Build Configuration(Debug/Release)配置正确
  • 检查每个Flavor对应的Info.plist文件,确保CFBundleIdentifier等关键配置与Flutter命令中指定的Flavor匹配

3. 更新过时依赖

报错中显示geocoding和location依赖使用了iOS已废弃的API,建议更新到最新稳定版本:
修改pubspec.yaml中的依赖版本:

geocoding: ^2.1.0
location: ^5.0.0

执行flutter pub get更新依赖,再重新执行pod install。

4. 调整Xcode构建脚本配置

打开Xcode的Runner目标,进入Build Phases:

  • 找到"Run Script"阶段,确认脚本内容为标准的Flutter构建脚本:
    "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build
    
  • 取消勾选"Based on dependency analysis"选项,避免脚本执行异常

内容的提问来源于stack exchange,提问作者Michael Jajou

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 08:32:17