Flutter iOS项目无法运行:Bundle Identifier无法确定问题求助
问题描述
我有一个Flutter项目,使用Visual Studio Code开发,Android端可正常运行,但iOS端无法启动。调试控制台报错提示无法确定应用的Bundle Identifier,需确保Info.plist包含CFBundleIdentifier值,已调试3天仍未解决,恳请帮助。
报错信息
无法安装 /Users/a/Desktop/xeta-flutter-main/build/ios/iphonesimulator/Runner.app 到设备A2DF75F6-E581-47AE-89FB-2875BBFFB2A8。这有时是plist文件格式错误导致的:
ProcessException: 进程异常退出:
处理命令时遇到错误(domain=NSPOSIXErrorDomain, code=22):
无法安装请求的应用
无法确定应用的Bundle Identifier。
请确保应用的Info.plist包含CFBundleIdentifier的值。
命令:xcrun simctl install A2DF75F6-E581-47AE-89FB-2875BBFFB2A8 /Users/a/Desktop/xeta-flutter-main/build/ios/iphonesimulator/Runner.app
在iPhone 11上启动应用失败。
提供的Info.plist文件内容
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>$(DEVELOPMENT_LANGUAGE)</string> <key>CFBundleDisplayName</key> <string>Xeta App</string> <key>CFBundleExecutable</key> <string>$(EXECUTABLE_NAME)</string> <key>CFBundleIdentifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleName</key> <string>xetaapp</string> <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleShortVersionString</key> <string>$(FLUTTER_BUILD_NAME)</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <string>com.googleusercontent.apps.802724704125-tr7nj48c74uifdrk0ar9pp22gh6vvt3n</string> </array> </dict> <dict> <key>CFBundleTypeRole</key> <string>None</string> </dict> </array> <key>CFBundleVersion</key> <string>$(FLUTTER_BUILD_NUMBER)</string> <key>LSApplicationQueriesSchemes</key> <array> <string>https</string>`enter code here` <string>http</string> </array> <key>LSRequiresIPhoneOS</key> <true/> <key>NSAllowsArbitraryLoads</key> <true/> <key>NSAllowsArbitraryLoadsInWebContent</key> <true/> <key>UILaunchStoryboardName</key> <string>LaunchScreen</string> <key>UIMainStoryboardFile</key> <string>Main</string> <key>UISupportedInterfaceOrientations</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array> <key>UISupportedInterfaceOrientations~ipad</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array> <key>UIViewControllerBasedStatusBarAppearance</key> <false/> <key>UIStatusBarHidden</key> <true/> <key>CADisableMinimumFrameDurationOnPhone</key> <true/> </dict> </plist>
解决方案
修复Info.plist语法错误
你的plist文件存在两处格式问题,这是导致识别失败的核心原因:- 删除
LSApplicationQueriesSchemes数组中<string>https</string>后面的enter code here垃圾字符; - 将
CADisableMinimumFrameDurationOnPhone对应的<true/>调整为和其他键值对一致的缩进格式。
- 删除
验证PRODUCT_BUNDLE_IDENTIFIER配置
打开iOS目录下的Runner.xcworkspace,在Xcode中选中Runner目标,进入「Build Settings」标签,搜索PRODUCT_BUNDLE_IDENTIFIER,确认其值为合法的Bundle ID格式(例如com.yourcompany.xetaapp),不能留空或格式错误。清理缓存并重建项目
执行以下命令彻底清理后重新构建:flutter clean flutter pub get cd ios pod deintegrate pod install cd .. flutter run重置模拟器状态
重启iOS模拟器,或切换至其他模拟器设备尝试启动,避免模拟器缓存引发的异常。
内容的提问来源于stack exchange,提问作者Tiberius John

