Flutter入門。Ubuntuの開発環境を準備した
Pixel3a XLを買いました。
新しい端末で何かしたくなったので、以前から気になっていたFlutter製アプリのセキュリティ面の検証をしてみようと思います。
まずはFlutterの開発環境を整えました。
目次
環境
- Ubuntu 18.04
インストール
公式のドキュメントに沿ってインストールを進めます。
SDKをダウンロードして展開
$ mkdir ~/development $ cd ~/development/ $ tar xf ~/Downloads/flutter_linux_v1.5.4-hotfix.2-stable.tar.xz
パスを通します。
$ export PATH="$PATH:`pwd`/flutter/bin"
必要なツール達をダウンロードします。
$ flutter precache
flutter doctorでツールの依存ライブラリなどを確認してくれます。
$ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [!] Flutter (Channel stable, v1.5.4-hotfix.2, on Linux, locale en_US.UTF-8) ✗ Downloaded executables cannot execute on host. See https://github.com/flutter/flutter/issues/6207 for more information On Debian/Ubuntu/Mint: sudo apt-get install lib32stdc++6 On Fedora: dnf install libstdc++.i686 On Arch: pacman -S lib32-gcc-libs [!] Android toolchain - develop for Android devices (Android SDK version 29.0.0) ✗ Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses [!] Android Studio (version 3.4) ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. [!] VS Code (version 1.36.0) ✗ Flutter extension not installed; install from https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter [!] Connected device ! No devices available ! Doctor found issues in 5 categories.
doctorに従って必要なライブラリのインストールやライセンスの承認をします。
$ sudo apt install lib32stdc++6 $ flutter doctor --android-licenses
Android StudioにFlutterのpluginを追加します。
Dartも一緒にインストールされました。
Android StudioをRstartします。
AndroidStudioだけ設定すれば良いような気もしますが、flutter doctorのエラーを全て消したいので、VSCodeにもFlutterの拡張を追加しておきます。
Androidをデベロッパーモードにし、USBデバッグを有効にしてパソコンと接続します。
flutter doctorで検出されて問題が解消されました。
$ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Linux, locale en_US.UTF-8) ⣽Error retrieving device properties for ro.product.cpu.abi: error: insufficient permissions for device: user in plugdev group; are your udev rules wrong? See [http://developer.android.com/tools/device.html] for more information [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.0) [✓] Android Studio (version 3.4) [✓] VS Code (version 1.36.0) [✓] Connected device (1 available) • No issues found!
Android端末との接続
端末との接続を確認すると、エラーが発生しました。
$ flutter devices 1 connected device: Error retrieving device properties for ro.product.cpu.abi: error: insufficient permissions for device: user in plugdev group; are your udev rules wrong? See [http://developer.android.com/tools/device.html] for more information 94BAX0DLNX • 94BAX0DLNX • android-arm • Android null (API null)
ADBの設定をしていなかったので、ADBの設定をします。
$ sudo apt install adb
エラーメッセージに記載されているURLを参照して、udev周りの設定をします。
$ sudo touch /etc/udev/rules.d/51-android.rules $ sudo vim /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"
の形式で設定を追記します。
idVendorは下記を参照します。
今回は、Pixel3aを使っているので、下記のようになりました。
$ cat /etc/udev/rules.d/51-android.rules SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"
$ sudo chmod a+r /etc/udev/rules.d/51-android.rules
$ adb devices List of devices attached adb server version (41) doesn't match this client (39); killing... * daemon started successfully 94BAX0DLNX no permissions (user in plugdev group; are your udev rules wrong?); see [http://developer.android.com/tools/device.html]
adb server version (41) doesn't match this client (39); killing...
を解消するために、adbを再起動します。
$ adb kill-server $ adb start-server
$ adb devices List of devices attached 94BAX0DLNX no permissions (user in plugdev group; are your udev rules wrong?); see [http://developer.android.com/tools/device.html]
no permissions (user in plugdev group; are your udev rules wrong?); see [http://developer.android.com/tools/device.html]
udevのルールは公式ドキュメントどおりだったので、こちらの記事を参考にsudo adb serverを再起動。
端末が認識されました。
$ sudo adb devices List of devices attached 94BAX0DLNX device
$ sudo ./flutter/bin/flutter devices Woah! You appear to be trying to run flutter as root. We strongly recommend running the flutter tool without superuser privileges. / 📎 1 connected device: Pixel 3a XL • 94BAX0DLNX • android-arm64 • Android 9 (API 28)
今回は一旦ここまで。
次はこちらを参考にサンプルアプリ作成を進めていきます。