Skip to content

"flutter run" fails with "Target aot_assembly_release failed: Exception: release/profile builds are only supported for physical devices. attempted to build for simulator." #85643

Description

@jmagman

I've been having the same issue on an existing app and then just tried a completely fresh app and getting the same issue. The issue started happening after upgrading to 2.2.2 but downgrading has not helped. Also, Android is fine.

Logs below. Project attached here.
misoapp.zip

flutter doctor -v Adeels-MacBook-Pro-2:misoapp adeel$ flutter doctor -v [✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-x64, locale en-US) • Flutter version 2.2.2 at /Users/adeel/flutter • Framework revision d79295a (3 weeks ago), 2021-06-11 08:56:01 -0700 • Engine revision 91c9fc8fe0 • Dart version 2.13.3

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/adeel/Library/Android/sdk
• Platform android-30, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.5, Build version 12E262
• CocoaPods version 1.10.1

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 49.0.2
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.57.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.23.0

[✓] Connected device (3 available)
• iPhone 12 Pro Max (mobile) • 520CFDE9-DF8D-44DD-A634-3AC152A4117D • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS 11.4 20F71 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.114

• No issues found!

Results of flutter run -v:
flutter-run.txt
(Log was too long to paste)

Originally posted by @realadeel in #85197 (comment)

Activity

  1. jmagman commented on Jun 30, 2021

    @jmagman
    MemberAuthor

    User is running straight flutter run -v which is choosing an iOS simulator. However, even though the Configuration is Debug (export CONFIGURATION\=Debug) it's passing -dBuildMode=release to assemble:

    /Users/adeel/flutter/bin/flutter --verbose assemble --no-version-check --output=/Users/adeel/projects/misoapp/build/ios/Debug-iphonesimulator/ -dTargetPlatform=ios
                   -dTargetFile=/Users/adeel/projects/misoapp/lib/main.dart -dBuildMode=release -dIosArchs=x86_64
                   -dSdkRoot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk -dSplitDebugInfo= -dTreeShakeIcons=false
    -dTrackWidgetCreation=true
                   -dDartObfuscation=false -dEnableBitcode= -dCodesignIdentity=- --ExtraGenSnapshotOptions= --DartDefines=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ== --ExtraFrontEndOptions=
                   release_ios_bundle_flutter_assets
    

    Failure is:

    [   +7 ms] Target aot_assembly_release failed: Exception: release/profile builds are only supported for physical devices. attempted to build for simulator.
    
  2. jmagman commented on Jun 30, 2021

    @jmagman
    MemberAuthor

    Odd, I really wouldn't have expected this problem unless FLUTTER_BUILD_MODE is set, which it's not.

    local build_mode="$(ParseFlutterBuildMode)"
    local artifact_variant="unknown"
    case "$build_mode" in
    release ) artifact_variant="ios-release";;
    profile ) artifact_variant="ios-profile";;
    debug ) artifact_variant="ios";;
    esac

    ParseFlutterBuildMode() {
    # Use FLUTTER_BUILD_MODE if it's set, otherwise use the Xcode build configuration name
    # This means that if someone wants to use an Xcode build config other than Debug/Profile/Release,
    # they _must_ set FLUTTER_BUILD_MODE so we know what type of artifact to build.
    local build_mode="$(echo "${FLUTTER_BUILD_MODE:-${CONFIGURATION}}" | tr "[:upper:]" "[:lower:]")"
    case "$build_mode" in
    *release*) build_mode="release";;
    *profile*) build_mode="profile";;
    *debug*) build_mode="debug";;

    -dBuildMode=${build_mode} \

    @realadeel What's the output of:

    $ cd /Users/adeel/flutter
    $ git status
    

    Can you also attach /Users/adeel/flutter/packages/flutter_tools/bin/xcode_backend.sh?

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 30, 2021
  4. realadeel commented on Jun 30, 2021

    @realadeel

    @jmagman
    Adeels-MacBook-Pro-2:flutter adeel$ git status
    On branch stable
    Your branch is up to date with 'origin/stable'.

    nothing to commit, working tree clean


    #!/usr/bin/env bash
    # Copyright 2014 The Flutter Authors. All rights reserved.
    # Use of this source code is governed by a BSD-style license that can be
    # found in the LICENSE file.
    
    # Exit on error
    set -e
    
    RunCommand() {
      if [[ -n "$VERBOSE_SCRIPT_LOGGING" ]]; then
        echo "♦ $*"
      fi
      "$@"
      return $?
    }
    
    # When provided with a pipe by the host Flutter build process, output to the
    # pipe goes to stdout of the Flutter build process directly.
    StreamOutput() {
      if [[ -n "$SCRIPT_OUTPUT_STREAM_FILE" ]]; then
        echo "$1" > $SCRIPT_OUTPUT_STREAM_FILE
      fi
    }
    
    EchoError() {
      echo "$@" 1>&2
    }
    
    AssertExists() {
      if [[ ! -e "$1" ]]; then
        if [[ -h "$1" ]]; then
          EchoError "The path $1 is a symlink to a path that does not exist"
        else
          EchoError "The path $1 does not exist"
        fi
        exit -1
      fi
      return 0
    }
    
    ParseFlutterBuildMode() {
      # Use FLUTTER_BUILD_MODE if it's set, otherwise use the Xcode build configuration name
      # This means that if someone wants to use an Xcode build config other than Debug/Profile/Release,
      # they _must_ set FLUTTER_BUILD_MODE so we know what type of artifact to build.
      local build_mode="$(echo "${FLUTTER_BUILD_MODE:-${CONFIGURATION}}" | tr "[:upper:]" "[:lower:]")"
    
      case "$build_mode" in
        *release*) build_mode="release";;
        *profile*) build_mode="profile";;
        *debug*) build_mode="debug";;
        *)
          EchoError "========================================================================"
          EchoError "ERROR: Unknown FLUTTER_BUILD_MODE: ${build_mode}."
          EchoError "Valid values are 'Debug', 'Profile', or 'Release' (case insensitive)."
          EchoError "This is controlled by the FLUTTER_BUILD_MODE environment variable."
          EchoError "If that is not set, the CONFIGURATION environment variable is used."
          EchoError ""
          EchoError "You can fix this by either adding an appropriately named build"
          EchoError "configuration, or adding an appropriate value for FLUTTER_BUILD_MODE to the"
          EchoError ".xcconfig file for the current build configuration (${CONFIGURATION})."
          EchoError "========================================================================"
          exit -1;;
      esac
      echo "${build_mode}"
    }
    
    BuildApp() {
      local project_path="${SOURCE_ROOT}/.."
      if [[ -n "$FLUTTER_APPLICATION_PATH" ]]; then
        project_path="${FLUTTER_APPLICATION_PATH}"
      fi
    
      local target_path="lib/main.dart"
      if [[ -n "$FLUTTER_TARGET" ]]; then
        target_path="${FLUTTER_TARGET}"
      fi
    
      local derived_dir="${SOURCE_ROOT}/Flutter"
      if [[ -e "${project_path}/.ios" ]]; then
        derived_dir="${project_path}/.ios/Flutter"
      fi
    
      local bundle_sksl_path=""
      if [[ -n "$BUNDLE_SKSL_PATH" ]]; then
        bundle_sksl_path="-iBundleSkSLPath=${BUNDLE_SKSL_PATH}"
      fi
    
      # Default value of assets_path is flutter_assets
      local assets_path="flutter_assets"
      # The value of assets_path can set by add FLTAssetsPath to
      # AppFrameworkInfo.plist.
      if FLTAssetsPath=$(/usr/libexec/PlistBuddy -c "Print :FLTAssetsPath" "${derived_dir}/AppFrameworkInfo.plist" 2>/dev/null); then
        if [[ -n "$FLTAssetsPath" ]]; then
          assets_path="${FLTAssetsPath}"
        fi
      fi
    
      # Use FLUTTER_BUILD_MODE if it's set, otherwise use the Xcode build configuration name
      # This means that if someone wants to use an Xcode build config other than Debug/Profile/Release,
      # they _must_ set FLUTTER_BUILD_MODE so we know what type of artifact to build.
      local build_mode="$(ParseFlutterBuildMode)"
      local artifact_variant="unknown"
      case "$build_mode" in
        release ) artifact_variant="ios-release";;
        profile ) artifact_variant="ios-profile";;
        debug ) artifact_variant="ios";;
      esac
    
      # Warn the user if not archiving (ACTION=install) in release mode.
      if [[ "$ACTION" == "install" && "$build_mode" != "release" ]]; then
        echo "warning: Flutter archive not built in Release mode. Ensure FLUTTER_BUILD_MODE \
    is set to release or run \"flutter build ios --release\", then re-run Archive from Xcode."
      fi
    
      local framework_path="${FLUTTER_ROOT}/bin/cache/artifacts/engine/${artifact_variant}"
      local flutter_engine_flag=""
      local local_engine_flag=""
      local flutter_framework="${framework_path}/Flutter.xcframework"
    
      if [[ -n "$FLUTTER_ENGINE" ]]; then
        flutter_engine_flag="--local-engine-src-path=${FLUTTER_ENGINE}"
      fi
    
      if [[ -n "$LOCAL_ENGINE" ]]; then
        if [[ $(echo "$LOCAL_ENGINE" | tr "[:upper:]" "[:lower:]") != *"$build_mode"* ]]; then
          EchoError "========================================================================"
          EchoError "ERROR: Requested build with Flutter local engine at '${LOCAL_ENGINE}'"
          EchoError "This engine is not compatible with FLUTTER_BUILD_MODE: '${build_mode}'."
          EchoError "You can fix this by updating the LOCAL_ENGINE environment variable, or"
          EchoError "by running:"
          EchoError "  flutter build ios --local-engine=ios_${build_mode}"
          EchoError "or"
          EchoError "  flutter build ios --local-engine=ios_${build_mode}_unopt"
          EchoError "========================================================================"
          exit -1
        fi
        local_engine_flag="--local-engine=${LOCAL_ENGINE}"
        flutter_framework="${FLUTTER_ENGINE}/out/${LOCAL_ENGINE}/Flutter.xcframework"
      fi
      local bitcode_flag=""
      if [[ "$ENABLE_BITCODE" == "YES" && "$ACTION" == "install" ]]; then
        bitcode_flag="true"
      fi
    
      # TODO(jmagman): use assemble copied engine in add-to-app.
      if [[ -e "${project_path}/.ios" ]]; then
        RunCommand rm -rf -- "${derived_dir}/engine/Flutter.framework"
        RunCommand cp -r -- "${flutter_framework}" "${derived_dir}/engine"
      fi
    
      RunCommand pushd "${project_path}" > /dev/null
    
      local verbose_flag=""
      if [[ -n "$VERBOSE_SCRIPT_LOGGING" ]]; then
        verbose_flag="--verbose"
      fi
    
      local performance_measurement_option=""
      if [[ -n "$PERFORMANCE_MEASUREMENT_FILE" ]]; then
        performance_measurement_option="--performance-measurement-file=${PERFORMANCE_MEASUREMENT_FILE}"
      fi
    
      local code_size_directory=""
      if [[ -n "$CODE_SIZE_DIRECTORY" ]]; then
        code_size_directory="-dCodeSizeDirectory=${CODE_SIZE_DIRECTORY}"
      fi
    
      local codesign_identity_flag=""
      if [[ -n "${EXPANDED_CODE_SIGN_IDENTITY:-}" && "${CODE_SIGNING_REQUIRED:-}" != "NO" ]]; then
        codesign_identity_flag="-dCodesignIdentity=${EXPANDED_CODE_SIGN_IDENTITY}"
      fi
    
      RunCommand "${FLUTTER_ROOT}/bin/flutter"                                \
        ${verbose_flag}                                                       \
        ${flutter_engine_flag}                                                \
        ${local_engine_flag}                                                  \
        assemble                                                              \
        --no-version-check                                                    \
        --output="${BUILT_PRODUCTS_DIR}/"                                     \
        ${performance_measurement_option}                                     \
        -dTargetPlatform=ios                                                  \
        -dTargetFile="${target_path}"                                         \
        -dBuildMode=${build_mode}                                             \
        -dIosArchs="${ARCHS}"                                                 \
        -dSdkRoot="${SDKROOT}"                                                \
        -dSplitDebugInfo="${SPLIT_DEBUG_INFO}"                                \
        -dTreeShakeIcons="${TREE_SHAKE_ICONS}"                                \
        -dTrackWidgetCreation="${TRACK_WIDGET_CREATION}"                      \
        -dDartObfuscation="${DART_OBFUSCATION}"                               \
        -dEnableBitcode="${bitcode_flag}"                                     \
        "${codesign_identity_flag}"                                           \
        ${bundle_sksl_path}                                                   \
        ${code_size_directory}                                                \
        --ExtraGenSnapshotOptions="${EXTRA_GEN_SNAPSHOT_OPTIONS}"             \
        --DartDefines="${DART_DEFINES}"                                       \
        --ExtraFrontEndOptions="${EXTRA_FRONT_END_OPTIONS}"                   \
        "${build_mode}_ios_bundle_flutter_assets"
    
      if [[ $? -ne 0 ]]; then
        EchoError "Failed to package ${project_path}."
        exit -1
      fi
      StreamOutput "done"
      StreamOutput " └─Compiling, linking and signing..."
    
      RunCommand popd > /dev/null
    
      echo "Project ${project_path} built and packaged successfully."
      return 0
    }
    
    # Adds the App.framework as an embedded binary and the flutter_assets as
    # resources.
    EmbedFlutterFrameworks() {
      # Embed App.framework from Flutter into the app (after creating the Frameworks directory
      # if it doesn't already exist).
      local xcode_frameworks_dir="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
      RunCommand mkdir -p -- "${xcode_frameworks_dir}"
      RunCommand rsync -av --delete --filter "- .DS_Store" "${BUILT_PRODUCTS_DIR}/App.framework" "${xcode_frameworks_dir}"
    
      # Embed the actual Flutter.framework that the Flutter app expects to run against,
      # which could be a local build or an arch/type specific build.
      RunCommand rsync -av --delete --filter "- .DS_Store" "${BUILT_PRODUCTS_DIR}/Flutter.framework" "${xcode_frameworks_dir}/"
    
      AddObservatoryBonjourService
    }
    
    # Add the observatory publisher Bonjour service to the produced app bundle Info.plist.
    AddObservatoryBonjourService() {
      local build_mode="$(ParseFlutterBuildMode)"
      # Debug and profile only.
      if [[ "${build_mode}" == "release" ]]; then
        return
      fi
      local built_products_plist="${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"
    
      if [[ ! -f "${built_products_plist}" ]]; then
        # Very occasionally Xcode hasn't created an Info.plist when this runs.
        # The file will be present on re-run.
        echo "${INFOPLIST_PATH} does not exist. Skipping _dartobservatory._tcp NSBonjourServices insertion. Try re-building to enable \"flutter attach\"."
        return
      fi
      # If there are already NSBonjourServices specified by the app (uncommon), insert the observatory service name to the existing list.
      if plutil -extract NSBonjourServices xml1 -o - "${built_products_plist}"; then
        RunCommand plutil -insert NSBonjourServices.0 -string "_dartobservatory._tcp" "${built_products_plist}"
      else
        # Otherwise, add the NSBonjourServices key and observatory service name.
        RunCommand plutil -insert NSBonjourServices -json "[\"_dartobservatory._tcp\"]" "${built_products_plist}"
      fi
    
      # Don't override the local network description the Flutter app developer specified (uncommon).
      # This text will appear below the "Your app would like to find and connect to devices on your local network" permissions popup.
      if ! plutil -extract NSLocalNetworkUsageDescription xml1 -o - "${built_products_plist}"; then
        RunCommand plutil -insert NSLocalNetworkUsageDescription -string "Allow Flutter tools on your computer to connect and debug your application. This prompt will not appear on release builds." "${built_products_plist}"
      fi
    }
    
    # Main entry point.
    if [[ $# == 0 ]]; then
      # Named entry points were introduced in Flutter v0.0.7.
      EchoError "error: Your Xcode project is incompatible with this version of Flutter. Run \"rm -rf ios/Runner.xcodeproj\" and \"flutter create .\" to regenerate."
      exit -1
    else
      case $1 in
        "build")
          BuildApp ;;
        "thin")
          # No-op, thinning is handled during the bundle asset assemble build target.
          ;;
        "embed")
          EmbedFlutterFrameworks ;;
        "embed_and_thin")
          # Thinning is handled during the bundle asset assemble build target, so just embed.
          EmbedFlutterFrameworks ;;
        "test_observatory_bonjour_service")
          # Exposed for integration testing only.
          AddObservatoryBonjourService ;;
      esac
    fi
    
  5. jmagman commented on Jul 1, 2021

    @jmagman
    MemberAuthor

    Huh, yeah that looks clean to me. Can't spot how CONFIGURATION=Debug is resulting in -dBuildMode=release...

  6. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 1, 2021
  7. added
    t: xcode"xcodebuild" on iOS and general Xcode project management
    toolAffects the "flutter" command-line tool. See also t: labels.
    P2Important issues not at the top of the work list
    on Jul 1, 2021
  8. bartekpacia commented on Dec 18, 2022

    @bartekpacia
  9. charliewwdev commented on Feb 17, 2023

    @charliewwdev

    Huh, yeah that looks clean to me. Can't spot how CONFIGURATION=Debug is resulting in -dBuildMode=release...

    How do you fix it ? i have this issue two and do not know how to fix it... it's stuck me for a long time

  10. 4x0v7 commented on Mar 17, 2023

    @4x0v7

    Fix for me was removing export FLUTTER_BUILD_MODE=Release from the ~/.zshrc
    This ENV was overriding the command-line flags so builds would always be release builds

  11. juliandevelops commented on Apr 22, 2023

    @juliandevelops

    Not sure if it's relevant, but I came across the same issue and tried archiving the app via Xcode. The console logs the following error:

    This binary was built with the incorrect architecture to run on this machine.
    Flutter requires the Rosetta translation environment. If you are on an ARM Mac, try running:
    sudo softwareupdate --install-rosetta --agree-to-license
    

    And then I found this issue which mentions native build engine support for ARM Macs. But at the moment this issue is still open and the implementation not done. So I guess, maybe we just have to wait

  12. haitrieu223 commented on Apr 24, 2023

    @haitrieu223
  13. yacineblr commented on Sep 14, 2023

    @yacineblr
  14. zakblacki commented on Dec 4, 2023

    @zakblacki
  15. dvkstalin commented on May 16, 2024

    @dvkstalin

    sudo softwareupdate --install-rosetta --agree-to-license Run this command. It works me.

  16. quetool commented on Jul 18, 2024

    @quetool
  17. aneeshjoshi commented on Dec 4, 2024

    @aneeshjoshi

    Apologies for the long post, but hope this helps people avoid the hours of struggle (some of it self-inflicted).

    I encountered this same error while attempting to get flavors running on an iOS Simulator (iphone 16, iOS 18.1) while following the
    Flutter Flavors Guide

    Some additional context is that I was also setting this up in conjunction with setting up Firebase for multiple environments (Note: This guide is linked on the official Flutter Flavors Guide)

    I finally have a setup that works across flavors. I've called out any particular changes I may have initially overlooked or any deviations from the two docs I used.

    1. I created the schemes by duplicating the existing scheme from the Manage Schemes window
    Screenshot 2024-12-04 at 9 22 28 AM
    1. This I believe is mentioned in the guide but it's important to ensure that your xcode scheme matches the flavor name (ensure case sensitive matching).

    For example, your xcode scheme should be called "dev" if your flavor is "dev" (case sensitive). I had made the mistake of naming my scheme "Dev" instead of matching it to flavor "dev".

    I believe this was my major blunder, but the associated errors did not immediately lead me to finding out that this was the issue.

    I will outline additional things I checked/modified, but those might not have as much bearing.

    1. This is mentioned in the guide but ensure that the flavor build configs are using the default schemes
    Screenshot 2024-12-04 at 9 47 03 AM
    1. When setting Product Name in those instructions in Step 2, ensure you are doing so on the Project and not the Target. The Target has to remain as Runner.
    setting product name for flavors
    1. The instructions in Step 5 display an image for your scheme configurations that seems to set every setting to "Debug-{flavor}" (in the case of the instructions, it's "Debug-free".
    scheme configurations

    However, I mirrored the scheme settings that were already present for the default scheme and set the corresponding build configuration for my flavor
    my scheme settings

    1. I did run (on my M1 MBP)

    sudo softwareupdate --install-rosetta --agree-to-license`

    and received an error

    2024-12-04 09:06:02.684 softwareupdate[76958:3274780] Package Authoring Error: 062-58681: Package reference com.apple.pkg.RosettaUpdateAuto is missing installKBytes attribute

    which I believe you can ignore

    1. I updated my Podfile as follows
    Screenshot 2024-12-04 at 9 25 20 AM Screenshot 2024-12-04 at 9 27 11 AM
  18. github-actions commented on Feb 7, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  19. locked as resolved and limited conversation to collaborators on Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listt: xcode"xcodebuild" on iOS and general Xcode project managementteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions