LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Saturday, May 11, 2019

Flutterを macOS Mojave にインストールしてみる


Google Apps Script関連ではありませんが Flutterをインストールした時の備忘録です。


公式ページに書かれているこれをやりました。
Docs > Get started > Install > MacOS
https://flutter.dev/docs/get-started/install/macos

いろいろ壁があるだろうと思い、やりながら手順を書き残していきます。


(途中でmacOSのアップデートやXcodeのアップデートなどにも時間がかかり、2日がかりでインストールしました。 僕の環境でのログなので、環境によっては別の壁があると思います。同じ壁にぶつかったときの参考になればと思います)



1. ボタンをクリックしてzipファイルをダウンロードします
Download the following installation bundle to get the latest stable release of the Flutter SDK:



2. 指定した場所に展開します
Extract the file in the desired location, for example:

ここでは例に習ってdevelopmentに展開してみますが、
developmentディレクトリ(フォルダ)がないので作るところから書きます。

ターミナル
$ cd ~
$ mkdir development
$ cd ~/development
$ unzip ~/Downloads/flutter_macos_v1.5.4-hotfix.2-stable.zip
意訳
ホームに行って
developmentフォルダを作って
developmentフォルダに行って
Downloadsの中のflutterのzipを解凍する


3. flutter/binまでの道をPATHに追加しておきます
export PATH="$PATH:[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin"
これはよく「PATHを通す」と表現されます。

以下意訳です

PATHって何?
  • コンピュータの中に「PATH」という名前の変数がある
通すってどういうこと?
  • その「PATH」という変数に目的の場所までの道を登録する
なんで?
  • 毎回手動で道を書くのが大変だから、コンピュータに道をおぼえておいてもらう

もっというと
「"コンピュータのホームの中のユーザーの中のdevelopの中のflutterの中のbin" のような深い階層に目的のフォルダがある時、毎回その階層までの道を書くのは大変なので、コンピュータが持っている PATH という名前の変数に登録しておこう」
という感じで、今回の場合、目的のフォルダはflutterの中のbinです。

ターミナル
$ export PATH="$PATH:/Users/NAME/development/flutter/bin"
$ vim ~/.bash_profile

#Flutter
export PATH="$PATH:/Users/NAME/development/flutter/bin"

$ source ~/.bash_profile
$ echo $PATH
意訳
flutter/binまでの道をPATHに登録する
vimで.bash_profileを開いて

コメントと
PATHを追加して(そのあと:wqで保存してvimを閉じる)

変更内容を反映させる
登録されたか確認する


これによって
$ PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin/コマンド
のようにflutter/bin/までのPATHを書かなくても

$ コマンド
でコマンドが実行できるようになります。

4. 必要に応じて実行します
Optionally, pre-download development binaries:
$  flutter precache


5. 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

  ╔════════════════════════════════════════════════════════════════════════════╗
  ║                 Welcome to Flutter! - https://flutter.dev                  ║
  ║                                                                            ║
  ║ The Flutter tool anonymously reports feature usage statistics and crash    ║
  ║ reports to Google in order to help Google contribute improvements to       ║
  ║ Flutter over time.                                                         ║
  ║                                                                            ║
  ║ 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/                           ║
  ║                                                                            ║
  ║ Use "flutter config --no-analytics" to disable analytics and crash         ║
  ║ reporting.                                                                 ║
  ╚════════════════════════════════════════════════════════════════════════════╝


Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.13.5 17F77, locale
    ja-JP)

[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    ✗ Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses
[✗] iOS toolchain - develop for iOS devices
    ✗ 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
    ✗ 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
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS platform side's plugin code that
        responds to your plugin usage on the Dart side.
        Without resolving iOS dependencies with CocoaPods, plugins will not work
        on iOS.
        For more info, see https://flutter.dev/platform-plugins
      To install:
        brew install cocoapods
        pod setup
[!] Android Studio (version 3.3)
    ✗ 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 4 categories.


出力される内容は各自の環境によって異なると思いますが、×を解消していきます。


解消していったログ

Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
これを解消します
$ flutter doctor --android-licenses
を実行すると
(y/N)? の入力を求められるので次々と y を入力して行きます
最後まで行くと
All SDK package licenses accepted
と表示されて×が解消されます。


次に、Xcode installation is incomplete; a full installation is necessary for iOS development.
Xcodeのインストールが完了していないようなので
Mac App Storeにアクセスして「View in Mac App Store 」をクリックします

補足
ちなみに https://developer.apple.com/xcode/download/ にアクセスして
「Download」をクリックして進んで行くと結局 Mac App Store にたどり着きました

Xcodeのアップデートには時間がかかりました。

補足
MacOSを最新にしてflutter doctorを実行すると以下のようなエラーがでましたが $ xcode-select --install で解消できました。

ターミナル
$ flutter doctor
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Building flutter tool...
^C
mac_NAME:flutter NAME$ xcode-select --install

参考
https://stackoverflow.com/questions/52522565/git-is-not-working-after-macos-mojave-update-xcrun-error-invalid-active-devel

その後、指示通り

ターミナル
$ sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
Password:
$ brew update
$ brew install --HEAD usbmuxd
$ brew link usbmuxd
$ brew install --HEAD libimobiledevice
$ brew install ideviceinstaller

$ brew install ios-deploy
$ brew install cocoapods
$ pod setup



次に
Flutter plugin not installed; this adds Flutter specific functionality.
Dart plugin not installed; this adds Dart specific functionality.
を解消していきます。

Android Studioはインストールされている前提で進めます。
https://developer.android.com/studio/install?hl=ja


Android Studioを開いて「Preferences...」を選択します

「Plugins」でflutterを検索します
Search in repositoriesのリンクをクリックします

「Flutter」を選択して「Install」ボタンをクリックします

「Accept」をクリックします


Dartも一緒にinstallしてくれるようなので「Yes」をクリックします

Android StudioをRestart後、再度Pluginsを見ると
「Dart」と「Flutter」が表示されます


ここまででAndroid Studioまで解消できました

ターミナル
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.4 18E226, locale ja-JP)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
[✓] Android Studio (version 3.3)
[!] Connected device
    ! No devices available

! Doctor found issues in 1 category.


最後にConnected deviceを解消していきます

Android setup
https://flutter.dev/docs/get-started/install/macos#android-setup
に書かれているとおりにスマホ側で「開発者向けオプション」「USBデバッグ」を有効にしてコンピュータと接続し flutter devices

ターミナル
$ flutter devices
1 connected device:

SO 01J • CB512DBRVL • android-arm64 • Android 8.0.0 (API 26)



これですべて解消しました

ターミナル
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.4 18E226, locale ja-JP)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
[✓] Android Studio (version 3.3)
[✓] Connected device (1 available)

• No issues found!


参考

Docs > Get started > Install > MacOS
https://flutter.dev/docs/get-started/install/macos

Android setup
https://flutter.dev/docs/get-started/install/macos#android-setup

Android Studio
https://developer.android.com/studio/install?hl=ja

Xcode
Mac App Store

xcrun: error〜の解消
https://stackoverflow.com/questions/52522565/git-is-not-working-after-macos-mojave-update-xcrun-error-invalid-active-devel

Latest post

スプレッドシートA列にある複数のテキストをスライドに追加したい(Google Apps Script)

今回Google Apps Scriptでやりたいこと GoogleスプレッドシートA列にある複数の値を取得して Googleスライドに渡して 図形オブジェクトのテキストとして追加したい ① スプレッドシートのA列に値を入れておく ② Code.gsのinsertNewShape...