【Android开发学Flutter】Flutter build

作者: JairusTse | 来源:发表于2019-08-05 10:47 被阅读21次

    一直在做Android开发,没有接触过iOS开发,build iOS App的时候还是遇到不少坑的。

    搭建Flutter开发环境【Android开发学Flutter】搭建Flutter开发环境 有写,这里就不再赘述,还有个小插曲,Xcode需要升级,但是在App Store上升级一直提示磁盘空间不足,但是空间是够的,最后还是手动下载了Xcode的安装包,在本地安装。算是个小坑吧。

    开发环境:
    Mac 10.14.4
    Android Studio 3.4.2
    Xcode 10.3

    网上找了个开源项目来练手,开源中国客户端:flutter-osc,目前有22k star,还是不错的。

    在 Xcode 上打开工程下的 ios 目录:
    image.png
    build 的时候遇到这个问题:

    Command /bin/sh failed with exit code 255

    网上找的解决办法,在 terminal 执行:
    flutter clean
    flutter build ios
    
    build ios的时候遇到:
    Cannot find "xcodebuild". Xcode 9.0 or greater is required to develop for iOS.
    Encountered error while building for device.
    
    执行:
    flutter doctor
    
    提示开发环境还没有搭建好:
    xieyuedeMacBook-Pro:flutter-osc-master xieyue$ flutter doctor
    Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure
    you trust this source!
    Downloading android-arm-profile/darwin-x64 tools...                 1.0s
    Downloading android-arm-release/darwin-x64 tools...                 0.5s
    Downloading android-arm64-profile/darwin-x64 tools...               1.3s
    Downloading android-arm64-release/darwin-x64 tools...               0.4s
    Downloading android-x86 tools...                                    2.0s
    Downloading android-x64 tools...                                    2.2s
    Downloading android-arm tools...                                    1.2s
    Downloading android-arm-profile tools...                            0.6s
    Downloading android-arm-release tools...                            0.5s
    Downloading android-arm64 tools...                                  1.3s
    Downloading android-arm64-profile tools...                          0.7s
    Downloading android-arm64-release tools...                          0.6s
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel beta, v1.7.8+hotfix.4, on Mac OS X 10.14.4 18E226, locale
        zh-Hans-CN)
     
    [!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
        ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
          --android-licenses
    [✗] Xcode - develop for iOS and macOS
        ✗ Xcode installation is incomplete; a full installation is necessary for iOS
          development.
          Download at: https://developer.apple.com/xcode/download/
          Or install Xcode via the App Store.
          Once installed, run:
            sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        ✗ CocoaPods not installed.
            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 install:
            brew install cocoapods
            pod setup
        ! Brew can be used to install CocoaPods.
          Download brew at https://brew.sh/.
    [✗] iOS tools - develop for iOS devices
        ✗ libimobiledevice and ideviceinstaller are not installed. To install with
          Brew, run:
            brew update
            brew install --HEAD usbmuxd
            brew link usbmuxd
            brew install --HEAD libimobiledevice
            brew install ideviceinstaller
        ✗ ios-deploy not installed. To install:
            brew install ios-deploy
        ! Brew can be used to install tools for iOS device development.
          Download brew at https://brew.sh/.
    [✓] Android Studio (version 3.4)
    [!] IntelliJ IDEA Community Edition (version 2017.3.4)
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
        ✗ Dart plugin not installed; this adds Dart specific functionality.
    [!] Connected device
        ! No devices available
    
    ! Doctor found issues in 5 categories.
    
    
    
    其实Xcode已经安装了的,但是还需要执行下面的指令:
    sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
    
    根据提示往下执行:
     brew install cocoapods
    
    提示:-bash: brew: command not found
    先安装Homebrew:

    打开 Terminal 输入以下命令行:

     /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    

    输入命令 brew help 检查是否正确安装;
    如果提示:brew:command not found,就需要进行环境配置;
    终端输入:

    sudo vim .bash_profile
    

    在 .bash_profile 文件的末尾添加如下代码:

    export PATH=/usr/local/bin:$PATH
    

    在 vim 模式下,按下 i键 进入编辑模式;编辑完成后,按 Esc键 退出编辑模式;输入 :wq 保存退出;
    刷新环境变量,输入命令:

    source .bash_profile
    
    安装Homebrew成功后继续安装cocoapods:
    brew install cocoapods
    
    然后:
    pod setup
    
    最后还剩这个警告:[!] IntelliJ IDEA Community Edition (version 2017.3.4),这个是IntelliJ IDEA编译器,我们只要Android Studio可用就好,大家忽视就好。
    build工程后出现:
    diff: /Users/xieyue/Downloads/flutter-osc-master/ios/Pods/Manifest.lock: No such file or directory
    error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
    
    
    关闭Xcode,cd到项目ios目录下:
    pod install
    
    再打开 Xcode 重新 build,可以成功运行在模拟器上。
    运行到真机出现:
    image.png
    “设置”>“通用”>“描述文件”或“描述文件与设备管理”,设置信任后终于可以运行到真机。
    build 第三方项目是成功了,但是build自己项目时遇到两个新问题,也记录在这里:
    Command PhaseScriptExecution failed with a nonzero exit code
    
    image.png
    需要安装插件:
    image.png

    然后可以build成功,但是模拟器上一片空白,因为打开的是一个web页面,用的是HTTP协议,搜索了一下,苹果出于安全考虑,提交到App Store的App都要用HTTPS,调试的时候还是可以用HTTP的,不过需要设置一下,方法可以参考:
    ATS(App Transport Security)对HTTP协议屏蔽引起的问题

    设置之后就可以正常在模拟器上运行了。但是真机上还是有问题:

    
    Showing All Messages
    :-1: Signing for "Runner" requires a development team. Select a development team in the project editor. (in target 'Runner')
    
    image.png

    选择开发团队后就可以在真机上运行了。

    相关文章

      网友评论

        本文标题:【Android开发学Flutter】Flutter build

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