flutter-environment-setup-macos

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

flutter-macos-setup

flutter-macos-setup

Goal

目标

Configures a macOS development environment for building, running, and deploying Flutter applications. Validates tooling dependencies including Xcode and CocoaPods, and ensures the environment passes Flutter's diagnostic checks for macOS desktop development. Assumes the host operating system is macOS and the user has administrative privileges.
配置用于构建、运行和部署Flutter应用的macOS开发环境。校验包括Xcode和CocoaPods在内的工具依赖,确保环境能够通过Flutter针对macOS桌面开发的诊断检查。假设主机操作系统为macOS,且用户拥有管理员权限。

Instructions

操作指南

  1. Verify Flutter Installation Check if Flutter is installed and accessible in the current environment.
    bash
    flutter --version
    Decision Logic:
    • If the command fails, STOP AND ASK THE USER: "Flutter is not installed or not in your PATH. Please install Flutter and add it to your PATH before continuing."
    • If the command succeeds, proceed to step 2.
  2. Verify Xcode Installation Ensure Xcode is installed on the macOS system.
    bash
    xcodebuild -version
    Decision Logic:
    • If Xcode is not installed, STOP AND ASK THE USER: "Xcode is required for macOS Flutter development. Please install the latest version of Xcode from the Mac App Store and notify me when complete."
    • If Xcode is installed, proceed to step 3.
  3. Configure Xcode Command-Line Tools Link the Xcode command-line tools to the installed version of Xcode and run the first-launch setup. STOP AND ASK THE USER: "I need to configure Xcode command-line tools. This requires administrative privileges. Please run the following command in your terminal and confirm when done:"
    bash
    sudo sh -c 'xcode-select -s /Applications/Xcode.app/Contents/Developer && xcodebuild -runFirstLaunch'
    (Note: If the user installed Xcode in a non-standard directory, instruct them to replace
    /Applications/Xcode.app
    with their custom path).
  4. Accept Xcode Licenses The Xcode license agreements must be accepted before compilation can occur. STOP AND ASK THE USER: "Please run the following command to review and accept the Xcode license agreements:"
    bash
    sudo xcodebuild -license
  5. Install CocoaPods CocoaPods is required for Flutter plugins that utilize native macOS code. Check if CocoaPods is installed:
    bash
    pod --version
    Decision Logic:
    • If installed, proceed to step 6.
    • If not installed, instruct the user to install it (e.g., via Homebrew or RubyGems) and verify the installation.
    bash
    sudo gem install cocoapods
  6. Validate Setup (Validate-and-Fix Loop) Run the Flutter diagnostic tool to check for any remaining macOS toolchain issues.
    bash
    flutter doctor -v
    Decision Logic:
    • Analyze the output under the Xcode section.
    • If there are errors or missing components, identify the specific missing dependency, provide the user with the exact command to fix it, and re-run
      flutter doctor -v
      .
    • Repeat this loop until the Xcode section reports no issues.
  7. Verify Device Availability Ensure Flutter can detect the macOS desktop as a valid deployment target.
    bash
    flutter devices
    Verify that at least one entry in the output has "macos" listed as the platform. If it is missing, instruct the user to enable macOS desktop support:
    bash
    flutter config --enable-macos-desktop
  1. 校验Flutter安装状态 检查当前环境中是否已安装Flutter且可正常访问。
    bash
    flutter --version
    判断逻辑:
    • 如果命令执行失败,停止并询问用户: "Flutter未安装或未添加到PATH中,请先安装Flutter并将其添加到PATH后再继续。"
    • 如果命令执行成功,继续执行步骤2。
  2. 校验Xcode安装状态 确保macOS系统上已安装Xcode。
    bash
    xcodebuild -version
    判断逻辑:
    • 如果未安装Xcode,停止并询问用户: "Xcode是macOS端Flutter开发的必需依赖,请从Mac App Store安装最新版本的Xcode,完成后告知我。"
    • 如果已安装Xcode,继续执行步骤3。
  3. 配置Xcode命令行工具 将Xcode命令行工具关联到已安装的Xcode版本,并运行首次启动设置。 停止并询问用户: "我需要配置Xcode命令行工具,此操作需要管理员权限,请在终端中运行以下命令,完成后确认:"
    bash
    sudo sh -c 'xcode-select -s /Applications/Xcode.app/Contents/Developer && xcodebuild -runFirstLaunch'
    (注意:如果用户将Xcode安装到了非标准目录,请告知其将
    /Applications/Xcode.app
    替换为自定义的安装路径)。
  4. 同意Xcode许可协议 编译前必须同意Xcode许可协议。 停止并询问用户: "请运行以下命令查看并同意Xcode许可协议:"
    bash
    sudo xcodebuild -license
  5. 安装CocoaPods 对于使用原生macOS代码的Flutter插件,CocoaPods是必需的依赖。 检查是否已安装CocoaPods:
    bash
    pod --version
    判断逻辑:
    • 如果已安装,继续执行步骤6。
    • 如果未安装,指导用户进行安装(例如通过Homebrew或RubyGems安装)并校验安装结果。
    bash
    sudo gem install cocoapods
  6. 校验配置(校验-修复循环) 运行Flutter诊断工具,检查macOS工具链是否还存在其他问题。
    bash
    flutter doctor -v
    判断逻辑:
    • 分析输出中Xcode部分的内容。
    • 如果存在错误或缺失组件,明确指出具体缺失的依赖,为用户提供修复所需的准确命令,然后重新运行
      flutter doctor -v
    • 重复此循环直到Xcode部分无任何问题提示。
  7. 校验设备可用性 确保Flutter可以将macOS桌面识别为合法的部署目标。
    bash
    flutter devices
    确认输出中至少有一条条目的平台列为"macos"。如果缺失,指导用户开启macOS桌面支持:
    bash
    flutter config --enable-macos-desktop

Constraints

约束条件

  • Do NOT include any external URLs or links in the output or prompts.
  • Do NOT attempt to run
    sudo
    commands automatically; always pause and provide the exact command for the user to execute.
  • Do NOT explain basic terminal usage or general macOS concepts.
  • MUST ensure the
    flutter doctor
    Xcode section is completely clear of errors before considering the skill complete.
  • MUST assume the user is operating on a macOS environment; do not provide Windows or Linux alternatives.
  • 输出或提示中不得包含任何外部URL或链接。
  • 不得自动运行
    sudo
    命令;始终暂停操作,向用户提供准确的命令由用户自行执行。
  • 不得解释基础的终端使用方法或通用macOS概念。
  • 必须确保
    flutter doctor
    的Xcode部分完全无错误,才能认为本操作完成。
  • 必须假设用户正在macOS环境下操作;不得提供Windows或Linux的替代方案。