Flutter
FlutterはGoogleが提供するものでクロスプラットフォーム開発が可能です。Android以外にもiOSアプリやWebアプリ開発もできます。
Google Trendでのクロスプラットフォームの動向は、
Flutterに注目が集まっていて日本も2019年から関心が高いようです。
ここではFlutterのAndroid開発環境をWindowsで作ってみたいと思います。iOSアプリではMacが必要になります。
1. Flutter SDK
1.1 ダウンロード
1.2 環境変数PATHの設定: Flutter SDK
2. Android Studio
2.1 Android Studio インストール
2.2 環境変数PATHの設定: Android Studio
3. Flutter doctor
Flutter SDK
Flutter SDKを以下よりOSに合わせてダウンロードします。(ここではWindows OSとして進めていきます)
Install Flutter
Windowsのケース:開発環境に必要とされる条件
- OS: Windows 7 SP1 or later (64-bit)
- Disk Space: 1.32 GB (does not include disk space for IDE/tools)
- これはflutterでのことですが、Android Studioでエミュレータを使う場合は数十GBの空きが必要です
- Tools: Flutter depends on these tools being available in your environment.
- Windows 10であれば比較的楽ですが、とりあえずはケースバイケースで揃えます
- Windows PowerShell 5.0 or newer (this is pre-installed with Windows 10)
- Git for Windows 2.x, with the Use Git from the Windows Command Prompt option.If Git for Windows is already installed, make sure you can run
git
commands from the command prompt or PowerShell.
ダウンロード
以下は公式の Windows install に沿って進めていきます。
flutter_windows_xxx.zip のzipファイルをダウンロード
過去の古いSDKはこちら Flutter SDK releases にあります。
flutter_windows_xxx.zip のzipファイルを解凍し、例えばC:\src\flutter 以下にフォルダをコピペします。
C:\Program Files\ 以下に通常のソフトのようにインストールすると管理者権限がうるさいので推奨していないようです。
環境変数PATHの設定: Flutter SDK
このflutter sdkにPATHを通してどこからでも実行させられるように環境変数のPATHに追加します。
Windowsの「スタート」から「Windows システムツール」にある「コントロールパネル」を開きます。
「システムとセキュリティ」「システム」「システムの詳細設定」から
「システムのプロパティ」の「詳細設定」タグの下に「環境変数(N)…」があります。
環境変数には、ユーザー環境変数と、システム環境変数がありユーザー側を選びます。
Pathの変数には値としてローカルパスが割り当てられています。なければ新規で作成
編集から、fluetter SDKのbinを設定します。
例えば c\_Flutter\src\flutter\bin のパスを新規で追加
Android Studio
Android Studioを設定します。これを使うとAndroidのエミュレータが使用できます。またDartのエディタとしても使えます。
インストール
Android Studio をWindowsにインストールするには以下を参考にしてください。
注意点として、flutterとは違ってインストール場所の変更はお勧めできないのでそのまま設定していきます。結果として
C:\Program Files\Android
C:\Users\「ユーザー名」\AppData\Local\Android
以下にファイルが格納されます。(これ以外にもありますが)、また「ユーザー名」を日本語にすると問題が起きますのでアルファベットのユーザー名を作って再インストールしないと後々面倒な事になります。
エミュレータ:
Android Studioがインストールできたなら、以下を参考にエミュレータを設定します。
USBドライバー:
またUSBドライバーを設定して実機上でテストできるようにもできます。
環境変数PATHの設定: Android Studio
flutterと同じようにAndroid StudioのPATHを設定します。
PATHは先ほどのAndroidフォルダ以下にあるSdkです。
C:\Users\「ユーザー名」\AppData\Local\Android\Sdk
環境変数のPathに設定します。
Flutter doctor
flutter doctorを使って環境がセットアップされているか確認します。
コマンドプロンプトを起動して以下コマンドを入力します。
1 |
C:\Users\hoge>flutter doctor |
コマンドプロンプトは前出のコントロールパネルの近くにあります。
診断結果が表示されるのでそれぞれ対処していきます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
C:\Users\hoge>flutter doctor 指定されたファイルが見つかりません。 Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 1.20.3, on Microsoft Windows [Version 10.0.18363.1016], locale ja-JP) [!] Android toolchain - develop for Android devices (Android SDK version 30.0.0) ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses [!] Android Studio (version 4.0) X Flutter plugin not installed; this adds Flutter specific functionality. X Dart plugin not installed; this adds Dart specific functionality. [!] VS Code (version 1.48.2) X Flutter extension not installed; install from https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [!] Connected device ! No devices available ! Doctor found issues in 4 categories. C:\Users\hoge> |
Flutterは問題ないようです。VS Codeはたまたま使っていたのでFlutter extensionが入っていないということですが、これは必須ではありません。
- Android licenses not accepted
- Flutter plugin not installed
- Dart plugin not installed
1. Android Licensesが許可されていないようですが対処方法が書いてあります。
To resolve this, run: flutter doctor –android-licenses
以下コマンドを入力して規約に了承する意味のyを入力
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
C:\Users\hoge>flutter doctor --android-licenses Warning: File C:\Users\hoge\.android\repositories.cfg could not be loaded. 5 of 7 SDK package licenses not accepted. 100% Computing updates... Review licenses that have not been accepted (y/N)? y 1/5: License android-googletv-license: --------------------------------------- Terms and Conditions ... August 15, 2011 --------------------------------------- Accept? (y/N): y 2/5: License android-sdk-preview-license: --------------------------------------- To get started with the Android SDK Preview, ... June 2014. --------------------------------------- Accept? (y/N): y 3/5: License google-gdk-license: --------------------------------------- This is a Developer Preview of the GDK that is subject to change. ... November 19, 2013 --------------------------------------- Accept? (y/N): y 4/5: License intel-android-extra-license: --------------------------------------- Intel (R) Hardware Accelerated Execution Manager End-User License Agreement ... --------------------------------------- Accept? (y/N): y All SDK package licenses accepted C:\Users\hoge>flutter doctor -android-licenses |
2. FutterとDartのプラグインがインストールされていない件はFlutterのプラグインを入れるとDartも一緒に入ります。
Android Studio のTop画面の下から「Configure」「SDK Manager」を起動します
「Plugins」タグから、「flutter」を検索してインストールします。
インストールが終わると「Restart IDE」と表示されるのでクリックしてAndroid Studioを再起動させます。
再度doctorを走らせてみると
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
C:\Users\hoge>flutter doctor Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 1.20.3, on Microsoft Windows [Version 10.0.18363.1016], locale ja-JP) [√] Android toolchain - develop for Android devices (Android SDK version 30.0.0) [√] Android Studio (version 4.0) [!] VS Code (version 1.48.2) X Flutter extension not installed; install from https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [!] Connected device ! No devices available ! Doctor found issues in 2 categories. C:\Users\hoge> |
これで環境設定がある程度できました。次は実際のアプリを作っていきましょう
References:
Flutter
Flutter architectural overview
Flutter Install
Set up an editor – Flutter