美文网首页fultter学习
ios mac配置flutter环境并成功运行demo

ios mac配置flutter环境并成功运行demo

作者: 小学生课代表 | 来源:发表于2020-04-07 17:11 被阅读0次

    1.安装xcode

    2.终端输入open ~/.bash_profile编辑内容

    export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn 
    export PATH=‘clone的flutter目录’/flutter/bin:$PATH
    

    终端执行保存操作:

    source ~/.bash_profile 
    

    3.创建‘clone的flutter目录’文件夹,然后在终端cd到此文件夹并执行命令:

    git clone -b stable https://github.com/flutter/flutter.git
    

    注:第一次我直接点击下载的,运行flutter doctor时报错:

      Error: The Flutter directory is not a clone of the GitHub project.
       The flutter tool requires Git in order to operate properly;
       to set up Flutter, run the following command:
       git clone -b stable https://github.com/flutter/flutter.git
    

    如果情况一样就需要使用git clone来获取sdk

    漫长的等待。。。

    4.执行 flutter doctor

    ziyuanxiazai:~ fonchy$ flutter doctor
    
    Downloading Dart SDK from Flutter engine af51afceb8886cc11e25047523c4e0c7e1f5d408...
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  200M  100  200M    0     0  10.0M      0  0:00:19  0:00:19 --:--:-- 10.9M
    Building flutter tool...
    
      ╔════════════════════════════════════════════════════════════════════════════╗
      ║                 Welcome to Flutter! - https://flutter.dev                  ║
      ║                                                                            ║
      ║ 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.                                                   ║
      ║                                                                            ║
      ║ Flutter tool analytics are not sent on the very first run. To disable      ║
      ║ reporting, type 'flutter config --no-analytics'. To display the current    ║
      ║ setting, type 'flutter config'. If you opt out of analytics, an opt-out    ║
      ║ event will be sent, and then no further information will be sent by the    ║
      ║ Flutter tool.                                                              ║
      ║                                                                            ║
      ║ By downloading the Flutter SDK, you agree to the Google Terms of Service.  ║
      ║ Note: The Google Privacy Policy describes how data is handled in this      ║
      ║ service.                                                                   ║
      ║                                                                            ║
      ║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and  ║
      ║ crash reports to Google.                                                   ║
      ║                                                                            ║
      ║ Read about data we send with crash reports:                                ║
      ║ https://github.com/flutter/flutter/wiki/Flutter-CLI-crash-reporting        ║
      ║                                                                            ║
      ║ See Google's privacy policy:                                               ║
      ║ https://www.google.com/intl/en/policies/privacy/                           ║
      ╚════════════════════════════════════════════════════════════════════════════╝
    
    
    Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure
    you trust this source!
    Downloading Material fonts...                                       0.4s
    Downloading Gradle Wrapper...                                       0.2s
    Downloading android-arm-profile/darwin-x64 tools...                 0.3s
    Downloading android-arm-release/darwin-x64 tools...                 0.3s
    Downloading android-arm64-profile/darwin-x64 tools...               0.3s
    Downloading android-arm64-release/darwin-x64 tools...               0.3s
    Downloading android-x64-profile/darwin-x64 tools...                 0.3s
    Downloading android-x64-release/darwin-x64 tools...                 0.3s
    Downloading package sky_engine...                                   0.2s
    Downloading common tools...                                         1.0s
    Downloading common tools...                                         1.0s
    Downloading darwin-x64 tools...                                     3.4s
    Downloading libimobiledevice...                                     0.2s
    Downloading usbmuxd...                                              0.1s
    Downloading libplist...                                             0.1s
    Downloading openssl...                                              0.6s
    Downloading ideviceinstaller...                                     0.2s
    Downloading ios-deploy...                                           0.1s
    Downloading libzip...                                               0.1s
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.3 19D76,
        locale zh-Hans-US)
    [✗] Android toolchain - develop for Android devices
        ✗ Unable to locate Android SDK.
          Install Android Studio from:
          https://developer.android.com/studio/index.html
          On first launch it will assist you in installing the Android SDK
          components.
          (or visit https://flutter.dev/setup/#android-setup for detailed
          instructions).
          If the Android SDK has been installed to a custom location, set
          ANDROID_HOME to that location.
          You may also want to add it to your PATH environment variable.
    
    [!] Xcode - develop for iOS and macOS (Xcode 11.3.1)
        ! CocoaPods 1.5.3 out of date (1.6.0 is recommended).
            CocoaPods is used to retrieve the iOS and macOS platform side's plugin
            code that responds to your plugin usage on the Dart side.
            Without CocoaPods, plugins will not work on iOS or macOS.
            For more info, see https://flutter.dev/platform-plugins
          To upgrade:
            sudo gem install cocoapods
    [!] Android Studio (not installed)
    [✓] VS Code (version 1.43.2)
    [✓] Connected device (3 available)
    
    ! Doctor found issues in 3 categories.
    

    发现其中有“Android toolchain - develop for Android devices”前面有个红色 [x],其实只要保证Xcode 和 Android toolchain 有一个成功就行,当然也可以再下载补全

    注:flutter doctor -v 查看配置并有提示安装的命令,直接复制粘贴运行即可

    5.下载VS Code

    6.安装Flutter插件

    (1)启动 VS Code
    (2)调用 View>Command Palette…
    (3)输入 ‘install’, 然后选择 Extensions: Install Extension action
    (4)在搜索框输入 flutter , 在搜索结果列表中选择 ‘Flutter’, 然后点击 Install
    (5)选择 ‘OK’ 重新启动 VS Code

    7.创建新的应用

    (1)启动 VS Code
    (2)调用 View>Command Palette…
    (3)输入 ‘flutter’, 然后选择 ‘Flutter: New Project’ action
    (4)输入 Project 名称 (如myapp), 然后按回车键
    (5)指定放置项目的位置,然后按蓝色的确定按钮
    (6)等待项目创建继续,并显示main.dart文件

    • 确保在VS Code的右下角选择了目标设备
    • 调用Debug>Start Debugging
    • 等待应用程序启动
    • 如果一切正常,在应用程序建成功后,您应该在您的设备或模拟器上看到应用程序:


      image.png
    • 配置Xcode参考链接:https://www.jianshu.com/p/f9abb844e9b1

    相关文章

      网友评论

        本文标题:ios mac配置flutter环境并成功运行demo

        本文链接:https://www.haomeiwen.com/subject/zbmnphtx.html