【Using English】47 - MacOS install of Flutter

original

System requirements 系统要求

To install and run Flutter, your development environment must meet these minimum requirements:
为了安装和运行Flutter,您的开发环境必须满足这些最低要求:

  • Operating Systems: macOS (64-bit) 操作系统:macOS(64位)
  • Disk Space: 700 MB (does not include disk space for IDE/tools). 硬盘空间:700MB(不包括集成开发环境或工具的硬盘空间)
  • Tools: Flutter depends on these command-line tools being available in your environment. 工具: Flutter依赖于以下命令行工具在环境中可以运行。
    • bash
    • curl
    • git 2.x
    • mkdir
    • rm
    • unzip
    • which

Get the Flutter SDK

  1. Download the following installation bundle to get the latest stable release of the Flutter SDK:
    下载以下安装包来获取最新的稳定版Flutter SDK
    flutter_macos_v1.7.8+hotfix.4-stable.zip

    For other release channels, and older builds, see the SDK archive page.
    对于其他的发布渠道,或者之前的构建版本,请查看SDK 归档页面

  2. Extract the file in the desired location, for example:
    在合适的位置提取文件,例如

 cd ~/development
 unzip ~/Downloads/flutter_macos_v1.7.8+hotfix.4-stable.zip
  1. Add the flutter tool to your path:
    在路径中添加flutter
 export PATH="$PATH:`pwd`/flutter/bin"

This command sets your PATH variable for the current terminal window only. To permanently add Flutter to your path, see Update your path.

这个命令仅仅在当前的终端窗口设置了您的Path变量。如果要永久添加Flutter到您的路径中,请查看升级路径

  1. Optionally, pre-download development binaries:
    可选地,提前下载开发二进制文件。
    The flutter tool downloads platform-specific development binaries as needed. For scenarios where pre-downloading these artifacts is preferable (for example, in hermetic build environments, or with intermittent network availability), iOS and Android binaries can be downloaded ahead of time by running:
    flutter工具会下载特定于平台的开发二进制文件。在一些场景中,提前下载这些文件会更好,例如密闭的构建环境,或者网络间歇性可用的环境。iOS和Android二进制文件可以通过运行下面的命令提前下载。
 flutter precache

For additional download options, see flutter help precache.
想了解更多下载选项,请查看flutter 帮助预缓存

You are now ready to run Flutter commands!
现在,你可以运行Flutter命令了。

Note: To update an existing version of Flutter, see Upgrading Flutter.

注意:想要升级已经存在的Flutter版本,请看升级Flutter

Run flutter doctor

Run the following command to see if there are any dependencies you need to install to complete the setup (for verbose output, add the -v flag):
为了完成设置,运行下面的命令来查看是否需要安装依赖

 flutter doctor

This command checks your environment and displays a report to the terminal window. The Dart SDK is bundled with Flutter; it is not necessary to install Dart separately. Check the output carefully for other software you might need to install or further tasks to perform (shown in bold text).

这个命令检查您的环境,并且在终端窗口显示一个报告。Dart SDK已经与Flutter一起打包了,无需单独安装。仔细检查输出信息,因为您可以需要安装其他软件或执行进一步的任务。

For example:

[-] Android toolchain - develop for Android devices
    • Android SDK at /Users/obiwan/Library/Android/sdk
    ✗ Android SDK is missing command line tools; download from https://goo.gl/XxQghQ
    • Try re-installing or updating your Android SDK,
      visit https://flutter.dev/setup/#android-setup for detailed instructions.

The following sections describe how to perform these tasks and finish the setup process.

下面的部分描述了如何执行这些任务并完成设置过程。

Once you have installed any missing dependencies, run the flutter doctor command again to verify that you’ve set everything up correctly.

每次你安装了缺少的依赖后,再次运行flutter doctor命令来验证是否已经设置正确了。

Warning: The flutter tool uses Google Analytics to anonymously report feature usage statistics and basic crash reports. This data is used to help improve Flutter tools over time. Analytics is not sent on the very first run or for any runs involving flutter config, so you can opt out of analytics before any data is sent. To disable reporting, type flutter config --no-analytics and to display the current setting, type flutter config. See Google’s Privacy Policy.

提示:flutter工具使用了Google分析来匿名报告特性使用情况的统计和基础的奔溃报告。随着时间的推移,该数据用来帮助提高Flutter工具。第一次运行或涉及到flutter配置的运行,分析数据不会被发送;所以您可以在分析被发送之前选择退出。想要关闭报告,可以输入flutter config --no-analytics;想要并显示当前的设置,输入flutter config.查看Google的隐私政策

Update your path

You can update your PATH variable for the current session only at the command line, as shown in Get the Flutter SDK. You’ll probably want to update this variable permanently, so you can run flutter commands in any terminal session.

正如在获取Flutter SDK中提到的一样,您可以仅在当前命令行更新PATH变量。您可能还想要永久地更新这个变量,这样您可以运行flutter命令在任何的终端。

The steps for modifying this variable permanently for all terminal sessions are machine-specific. Typically you add a line to a file that is executed whenever you open a new window. For example:

想要永久地修改这个变量,让它在任意终端都可用,操作步骤会因机器而异。典型的操作是在每次打开窗口都会运行的文件中添加一行,例如:

  1. Determine the directory where you placed the Flutter SDK. You will need this in Step 3.
    第一步:确定存放Flutter SDK的目录。第三步需要这个信息。
  2. Open (or create) $HOME/.bash_profile. The file path and filename might be different on your machine.
    打开(或者创建)$HOME/.bash_profile文件,这个文件的路径和名称可能与你机器的不同。
  3. Add the following line and change [PATH_TO_FLUTTER_GIT_DIRECTORY] to be the path where you cloned Flutter’s git repo:
    添加下面一行,把[PATH_TO_FLUTTER_GIT_DIRECTORY]改成第一步中的目录,用来设置Flutter的目录。
 export PATH="$PATH:[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin"
  1. Run source $HOME/.bash_profile to refresh the current window.
    运行source $HOME/.bash_profile 来刷新当前的窗口
  2. Verify that the flutter/bin directory is now in your PATH by running:
    运行下面的命令,验证flutter/bin目的现在在你的PATH中
 echo $PATH

For more details, see this StackExchange question.
更多的细节,查看StackExchange问题.

Platform setup

MacOS supports developing Flutter apps for both iOS and Android. Complete at least one of the two platform setup steps now, to be able to build and run your first Flutter app.

MacOS同时支持开发iOS和Android的Flutter应用。现在,至少完成两个平台中的一个的设置步骤,来构建和运行您的第一个Flutter应用。

iOS setup

Install Xcode

To develop Flutter apps for iOS, you need a Mac with Xcode 9.0 or newer:
想要开发iOS上的Flutter应用,您需要在Mac上安装Xcode9.0 或更高版本。

  1. Install Xcode 9.0 or newer (via web download or the Mac App Store).
    安装Xcode9.0或更高版本(通过网页下载或者Mac应用商店)
  2. Configure the Xcode command-line tools to use the newly-installed version of Xcode by running the following from the command line:
    通过在命令行中运行以下命令,可以配置Xcode命令行工具,确保使用最新安装的Xcode版本。
 sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

This is the correct path for most cases, when you want to use the latest version of Xcode. If you need to use a different version, specify that path instead.
如果您想要使用最新版的Xcode,大多数情况下,这个都是正确的路径。如果您需要使用一个不同的版本,制定对应的路径即可。

  1. Make sure the Xcode license agreement is signed by either opening Xcode once and confirming or runningsudo xcodebuild -license from the command line.

为了确保Xcode的许可协议已被签署,可以打开一次Xcode或者在命令行运行sudo xcodebuild -license

With Xcode, you’ll be able to run Flutter apps on an iOS device or on the simulator.

有了Xcode,您可以在iOS设备或者模拟器上运行Flutter应用了

Set up the iOS simulator

To prepare to run and test your Flutter app on the iOS simulator, follow these steps:
为了在iOS模拟器上准备运行和测试您的Flutter应用,遵循以下步骤:

  1. On your Mac, find the Simulator via Spotlight or by using the following command:
    在Mac上,通过Spotlight或者以下命令找到模拟器。
 open -a Simulator
  1. Make sure your simulator is using a 64-bit device (iPhone 5s or later) by checking the settings in the simulator’s Hardware > Device menu.
    通过在硬件 > 设备菜单里检查模拟器的设置,确保您的模拟器使用了64位的设备(iPhone 5s或者更新的设备)。
  2. Depending on your development machine’s screen size, simulated high-screen-density iOS devices might overflow your screen. Set the device scale under the Window > Scale menu in the simulator.
    依赖于开发设备的屏幕尺寸,模拟高清分辨率的iOS设备也许会超出您的屏幕。在窗口 > 缩放菜单中设置设备缩放度来调整模拟器。

Create and run a simple Flutter app

To create your first Flutter app and test your setup, follow these steps:
想要创建您的第一个Flutter应用并且测试设置的正确性,遵循以下步骤:

  1. Create a new Flutter app by running the following from the command line:
    运行以下命令 创建一个新的Flutter应用。
 flutter create my_app
  1. A my_app directory is created, containing Flutter’s starter app. Enter this directory:
    my_app目的创建后,包含了Flutter的启动应用,进入该目录
 cd my_app
  1. To launch the app in the Simulator, ensure that the Simulator is running and enter:
    想要在模拟器中启动应用,确保模拟器正在运行并输入flutter run
 flutter run

Deploy to iOS devices

部署到iOS设备
To deploy your Flutter app to a physical iOS device, you’ll need some additional tools and an Apple account. You’ll also need to set up physical device deployment in Xcode.
想要部署Flutter应用到一个现实中的iOS设备,您需要一些额外的工具和一个苹果账号。您也需要在Xcode中设置真实设备的部署。

  1. Install homebrew.
  2. Ensure that homebrew is up to date:
 brew update
  1. Install the tools for deploying Flutter apps to iOS devices by running the following commands:
    运行以下命令,安装用于部署Flutter应用到iOS设备的工具。
 brew install --HEAD usbmuxd
 brew link usbmuxd
 brew install --HEAD libimobiledevice
 brew install ideviceinstaller ios-deploy cocoapods
 pod setup

Note: The first two commands above are necessary as a temporary workaround until the next release of libusbmuxd, as explained in libusbmuxd issue #46 and Flutter issue #22595.

提示:作为一个临时解决方案,以上命令中的前两个是必要的。正如两个issue中解释过的原因,这个问题直到libusbmuxd下一次发布才能解决。

If any of these commands fail, run brew doctor and follow the instructions to resolve any issues.

如果这些命令汇总的任何一个运行失败了,运行brew doctor并且遵循说明来解决对应的问题。

  1. Follow the Xcode signing flow to provision your project:
    遵循Xcode签名步骤来提供你的项目

    1. Open the default Xcode workspace in your project by running open ios/Runner.xcworkspace in a terminal window from your Flutter project directory.
      在工程中,通过在终端窗口中运行open ios/Runner.xcworkspace打开Xcode默认的工作空间

    2. In Xcode, select the Runner project in the left navigation panel.
      在Xcode中,在左侧导航栏中选择Runner工程。

    3. In the Runner target settings page, make sure your Development Team is selected under General > Signing > Team. When you select a team, Xcode creates and downloads a Development Certificate, registers your device with your account, and creates and downloads a provisioning profile (if needed).
      Runner目标设置页面,确保您已经在通用 > 签名 > 团队中选择了您的开发团队。当您选择了团队,Xcode会创建并且下载一个开发证书,用您的账号注册您的设备,如果需要的话,也会创建并下载一个提供好的档案。

      • To start your first iOS development project, you might need to sign into Xcode with your Apple ID.
        想要开启您的第一个iOS开发工程,您或许需要用您的苹果ID登陆Xcode。


        Xcode account add

      Development and testing is supported for any Apple ID. Enrolling in the Apple Developer Program is required to distribute your app to the App Store. For details about membership types, see Choosing a Membership.
      任何AppleID都支持开发和测试。想要发布您的应用到App Store,您需要注册苹果开发者。关于会员类型的更多细节,请查看选择一种会员

      • The first time you use an attached physical device for iOS development, you will need to trust both your Mac and the Development Certificate on that device. Select Trust in the dialog prompt when first connecting the iOS device to your Mac.
        第一次在iOS开发中使用一个绑定的真实设备,您需要在设备中信任您的Mac和开发证书。第一次连接iOS设备到电脑时,在弹窗提示中选择Trust

        Trust Mac

        Then, go to the Settings app on the iOS device, select General > Device Management and trust your Certificate.
        然后,在iOS设备的设置应用中,选择通用 > 设备管理并信任您的证书。

      • If automatic signing fails in Xcode, verify that the project’s General > Identity > Bundle Identifiervalue is unique.
        如果Xcode中的自动签名失败了,验证工程的通用 > 身份 > 包标识符的值是否唯一

        Check the app's Bundle ID

  2. Start your app by running flutter run.
    运行应用通过运行flutter run

Android setup

Note: Flutter relies on a full installation of Android Studio to supply its Android platform dependencies. However, you can write your Flutter apps in a number of editors; a later step will discuss that.

提示: Flutter依赖一个Android Studio的全量安装,来支持Flutter Android平台的依赖。但是,你可以在很多编辑器中写Flutter应用(安装了但可以不用。。。),之后的步骤中将会讨论。

Install Android Studio

  1. Download and install Android Studio.
    下载并安装Android Studio
  2. Start Android Studio, and go through the ‘Android Studio Setup Wizard’. This installs the latest Android SDK, Android SDK Platform-Tools, and Android SDK Build-Tools, which are required by Flutter when developing for Android.
    开启Android Studio,并完成安装向导。这样,已经安装了最新的Android SDK,Android SDK 平台工具,和 Android SDK打包工具,这些都是使用Flutter开发Android时需要的。

Set up your Android device

To prepare to run and test your Flutter app on an Android device, you’ll need an Android device running Android 4.1 (API level 16) or higher.
想要准备在一个Android设备上运行和测试您的Flutter应用,您需要一个运行着Android4.1(API 等级16)及以上的Android设备。

  1. Enable Developer options and USB debugging on your device. Detailed instructions are available in theAndroid documentation.
    在设备上开启开发者选项USB调试功能。更多的说明可以在Android文档中查看。
  2. Windows-only: Install the Google USB Driver.
    只针对Windows设备,安装Google USB 驱动
  3. Using a USB cable, plug your phone into your computer. If prompted on your device, authorize your computer to access your device.
    使用USB数据线,连接您的手机到电脑。如果在设备上有提示,授权您的电脑对于设备的访问权。
  4. In the terminal, run the flutter devices command to verify that Flutter recognizes your connected Android device. By default, Flutter uses the version of the Android SDK where your adb tool is based. If you want Flutter to use a different installation of the Android SDK, you must set the ANDROID_HOME environment variable to that installation directory.
    在终端里,运行命令flutter devices来检验Flutter已经检测到您连接好的设备。默认地,Flutter使用adb工具依赖的Android SDK版本。如果您想要Flutter使用一个不同的AndroidSDK安装,您必须设置ANDROID_HOME环境变量在那个对应的安装目录。

Set up the Android emulator

To prepare to run and test your Flutter app on the Android emulator, follow these steps:
想要准备在Android模拟器上运行和测试您的Flutter应用,遵循以下步骤:

  1. Enable VM acceleration on your machine.
    打开您的机器中的[虚拟机加速]
  2. Launch Android Studio > Tools > Android > AVD Manager and select Create Virtual Device. (The Androidsubmenu is only present when inside an Android project.)
    打开Android Studio > 工具 > Android > AVD 管理器并选择创建虚拟设备(Android子目录只有在Android工程中才会看到)
  3. Choose a device definition and select Next.
    选择一个设备定义,然后选择下一步
  4. Select one or more system images for the Android versions you want to emulate, and select Next. An x86or x86_64 image is recommended.
    为您想要模拟的Android版本选择一个或多个系统镜像,并且选择下一步。推荐x86或者x86_64镜像。
  5. Under Emulated Performance, select Hardware - GLES 2.0 to enable hardware acceleration.
    关于模拟器性能,选择硬件-GLES2.0来开启硬件加速
  6. Verify the AVD configuration is correct, and select Finish.
    验证AVD配置是正确的并选择“完成”。
    For details on the above steps, see Managing AVDs.
    前面步骤的更多详细信息,请查看管理AVDs
  7. In Android Virtual Device Manager, click Run in the toolbar. The emulator starts up and displays the default canvas for your selected OS version and device.
    在Android虚拟设备管理器中,在工具栏中点击运行。模拟器启动后会显示选择您已选操作系统版本和设备的默认UI视图。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,324评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,303评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,192评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,555评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,569评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,566评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,927评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,583评论 0 257
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,827评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,590评论 2 320
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,669评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,365评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,941评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,928评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,159评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,880评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,399评论 2 342

推荐阅读更多精彩内容