Flutter 在 iOS 模拟器上运行失败 - CFBundleVersion 无效

Tal*_*bit 1 xcode emulation ios flutter

I tried to run my flutter app on iOS but it didn't work.\nAndroid works fine.

\n

I already uninstalled CocoaPods and reinstalled it.\nAlso I done flutter clean, I cleaned the Xcode builds and the android studio caches and restarted the IDE.

\n

Here is the terminal output:

\n
Launching lib/main.dart on iPhone 13 in debug mode...\nRunning pod install...                                             11,0s\nRunning Xcode build...                                                  \n \xe2\x94\x94\xe2\x94\x80Compiling, linking and signing...                        11,8s\nXcode build done.                                           256,6s\nUnable to install .../build/ios/iphonesimulator/Runner.app on [EmulatorId]. This is sometimes caused by a malformed\nplist file:\nProcessException: Process exited abnormally:\nAn error was encountered processing the command (domain=NSPOSIXErrorDomain, code=22):\nFailed to install the requested application\nThe application's Info.plist does not contain a valid CFBundleVersion.\nEnsure your bundle contains a valid CFBundleVersion.\n  Command: /usr/bin/arch -arm64e xcrun simctl install [EmulatorId]\n.../build/ios/iphonesimulator/Runner.app\nError launching application on iPhone 13.\n
Run Code Online (Sandbox Code Playgroud)\n

Here is my flutter doctor -v:

\n
[\xe2\x9c\x93] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm, locale\n    de-DE)\n    \xe2\x80\xa2 Flutter version 2.8.1 at .../dev/flutter\n    \xe2\x80\xa2 Upstream repository https://github.com/flutter/flutter.git\n    \xe2\x80\xa2 Framework revision 77d935af4d (vor 7 Wochen), 2021-12-16 08:37:33 -0800\n    \xe2\x80\xa2 Engine revision 890a5fca2e\n    \xe2\x80\xa2 Dart version 2.15.1\n\n[\xe2\x9c\x93] Android toolchain - develop for Android devices (Android SDK version 31.0.0)\n    \xe2\x80\xa2 Android SDK at .../Library/Android/sdk\n    \xe2\x80\xa2 Platform android-31, build-tools 31.0.0\n    \xe2\x80\xa2 Java binary at: .../Library/Application\n      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.8092744\n      /Android Studio.app/Contents/jre/Contents/Home/bin/java\n    \xe2\x80\xa2 Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)\n    \xe2\x80\xa2 All Android licenses accepted.\n\n[\xe2\x9c\x93] Xcode - develop for iOS and macOS (Xcode 13.2.1)\n    \xe2\x80\xa2 Xcode at /Applications/Xcode.app/Contents/Developer\n    \xe2\x80\xa2 CocoaPods version 1.11.2\n\n[\xe2\x9c\x93] Chrome - develop for the web\n    \xe2\x80\xa2 Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome\n\n[\xe2\x9c\x93] Android Studio (version 2021.1)\n    \xe2\x80\xa2 Android Studio at .../Library/Application\n      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.8092744\n      /Android Studio.app/Contents\n    \xe2\x80\xa2 Flutter plugin can be installed from:\n       https://plugins.jetbrains.com/plugin/9212-flutter\n    \xe2\x80\xa2 Dart plugin can be installed from:\n       https://plugins.jetbrains.com/plugin/6351-dart\n    \xe2\x80\xa2 Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)\n\n[\xe2\x9c\x93] VS Code (version 1.62.3)\n    \xe2\x80\xa2 VS Code at /Applications/Visual Studio Code.app/Contents\n    \xe2\x80\xa2 Flutter extension can be installed from:\n       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter\n\n[\xe2\x9c\x93] Connected device (2 available)\n    \xe2\x80\xa2 iPhone 13 (mobile) \xe2\x80\xa2 0F835380-920C-4850-8AE2-65842F4ECCF1 \xe2\x80\xa2 ios\n      \xe2\x80\xa2 com.apple.CoreSimulator.SimRuntime.iOS-15-2 (simulator)\n    \xe2\x80\xa2 Chrome (web)       \xe2\x80\xa2 chrome                               \xe2\x80\xa2 web-javascript\n      \xe2\x80\xa2 Google Chrome 97.0.4692.99\n\n\xe2\x80\xa2 No issues found!\n
Run Code Online (Sandbox Code Playgroud)\n

Here is my info.plist:

\n
<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n    <key>CFBundleDevelopmentRegion</key>\n    <string>$(DEVELOPMENT_LANGUAGE)</string>\n    <key>CFBundleDisplayName</key>\n    <string>[AppName]</string>\n    <key>CFBundleExecutable</key>\n    <string>$(EXECUTABLE_NAME)</string>\n    <key>CFBundleGetInfoString</key>\n    <string></string>\n    <key>CFBundleIconName</key>\n    <string>AppIcon</string>\n    <key>CFBundleIdentifier</key>\n    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>\n    <key>CFBundleInfoDictionaryVersion</key>\n    <string>6.0</string>\n    <key>CFBundleName</key>\n    <string>[AppName]</string>\n    <key>CFBundlePackageType</key>\n    <string>APPL</string>\n    <key>CFBundleShortVersionString</key>\n    <string>$(FLUTTER_BUILD_NAME)</string>\n    <key>CFBundleSignature</key>\n    <string>????</string>\n    <key>CFBundleVersion</key>\n    <string>$(FLUTTER_BUILD_NUMBER)</string>\n    <key>ITSAppUsesNonExemptEncryption</key>\n    <false/>\n    <key>LSApplicationCategoryType</key>\n    <string></string>\n    <key>LSRequiresIPhoneOS</key>\n    <true/>\n    <key>MinimumOSVersion</key>\n    <string>12.0</string>\n    <key>NSCameraUsageDescription</key>\n    <string>camera</string>\n    <key>NSPhotoLibraryUsageDescription</key>\n    <string>This app needs photo library access to choose a photo for the goal page</string>\n    <key>UILaunchStoryboardName</key>\n    <string>LaunchScreen</string>\n    <key>UIMainStoryboardFile</key>\n    <string>Main</string>\n    <key>UIStatusBarHidden</key>\n    <false/>\n    <key>UISupportedInterfaceOrientations</key>\n    <array>\n        <string>UIInterfaceOrientationPortrait</string>\n    </array>\n    <key>UISupportedInterfaceOrientations~ipad</key>\n    <array>\n        <string>UIInterfaceOrientationPortrait</string>\n        <string>UIInterfaceOrientationPortraitUpsideDown</string>\n        <string>UIInterfaceOrientationLandscapeLeft</string>\n        <string>UIInterfaceOrientationLandscapeRight</string>\n    </array>\n    <key>UIViewControllerBasedStatusBarAppearance</key>\n    <false/>\n    <key>io.flutter.embedded_views_preview</key>\n    <true/>\n</dict>\n</plist>\n
Run Code Online (Sandbox Code Playgroud)\n

Please let me know if anything is missing. I will add it.\nThank you in advance!

\n

Has*_*lak 6

转到ios/Flutter/Debug.xcconfig文件并将此行添加到文件末尾:

#include "Generated.xcconfig"
Run Code Online (Sandbox Code Playgroud)

所以该文件将如下所示:

#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"

Run Code Online (Sandbox Code Playgroud)

发生这种情况是因为生成的配置不包含在调试版本中。添加上面的行确保将pubspec.yaml文件中生成的配置添加到info.plist