やっつけ不定記

好きなときに好きなことをちゃっちゃと書いてます

UbuntuでFlutterを動かしてみた

ちょっと前からGoogleさんがAndroidiOS両方のアプリを作ることができる
仕組みに取り組んでいるそうで、そのベータ版が公開されたとのこと。
http://www.itmedia.co.jp/news/articles/1802/28/news076.html
面白そうだったので、とりあえず試してみたのですが、
公式サイト
https://flutter.io/setup-linux/
だけでは微妙にうまくいかなかったので、メモしてみます。
環境はUbuntu16.04でやっています。


(1)追加パッケージの導入
Synapticパッケージマネージャからlib32stdc++6入れる。
これをやらないと、後のflutter doctor時に
https://github.com/flutter/flutter/issues/6207#issuecomment-310912958
にぶち当たるようで、

                                                                                                                          • -

Downloaded executables cannot execute on host
(see https://github.com/flutter/flutter/issues/6207 for more information)

                                                                                                                          • -

を吐く。
lib32stdc++6を入れると、依存パッケージとして lib32gcc1,libc6-i386 も入った。




(2)Android Studioの導入
インストールディレクトリを変えた場合は、
インストール後に環境変数 $ANDROID_HOME を設定する。
$ export ANDROID_HOME=(Android SDKディレクトリ)




(3)デバイスの接続
端末をUSBでつなぐ。本件ではNexus7(2013)を利用する。




(4)Flutterの導入
$ cd (ホームディレクトリ)/apps
$ git clone -b beta https://github.com/flutter/flutter.git
$ export PATH=`pwd`/flutter/bin:$PATH




(5)環境の確認
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (on Linux, locale ja_JP.UTF-8, channel beta)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] Android Studio (version 3.0)
[✓] Connected devices


• No issues found!




(6)サンプルアプリの動作確認
とりあえず、Hello Worldを動かしてみる。
$ ls (Flutterのディレクトリ)/examples
README.md flutter_gallery hello_world platform_channel platform_view
catalog flutter_view layers platform_channel_swift stocks
$ cd (Flutterのディレクトリ)/examples/hello_world
$ flutter run
Android SDKが足りていないようで、下記エラーを吐いた。

                                                                                                                          • -

Running "flutter packages get" in hello_world... 14.7s
Launching lib/main.dart on Nexus 7 in debug mode...
Initializing gradle... 21.2s
Resolving dependencies... -

* Error running Gradle:
Unable to download needed Android SDK components, as the following licenses have not been accepted:
Android SDK Build-Tools 26.0.2

To resolve this, please run the following command in a Terminal:
flutter doctor --android-licenses

                                                                                                                          • -



SDK ManagerからAndroid 8.0 SDK(26.2)を入れて
改めてサンプルアプリを実行する。


$ flutter run
下記メッセージが出力された後、Nexus7に「Hello World」が表示された。

                                                                                                                          • -

Launching lib/main.dart on Nexus 7 in debug mode...
Initializing gradle... 4.8s
Resolving dependencies... 17.7s
Running 'gradlew assembleDebug'... 38.9s
Built build/app/outputs/apk/debug/app-debug.apk (24.0MB).
Installing build/app/outputs/apk/app.apk... 17.5s
I/FlutterActivityDelegate( 8913): onResume setting current activity to this
I/FlutterActivityDelegate( 8913): onResume setting current activity to this
Syncing files to device Nexus 7... 4.9s

🔥 To hot reload your app on the fly, press "r". To restart the app entirely, press "R".
An Observatory debugger and profiler on Nexus 7 is available at: http://127.0.0.1:8100/
For a more detailed help message, press "h". To quit, press "q".

                                                                                                                          • -

→ターミナル上でqを押したら、アプリが終了した。


スマホアプリ開発周りって、最近はほとんど追えてないのですが、
GoogleさんKotlinにも力入れてたり、今後どうなっていくんでしょうね。