「Installing the latest version of flutter and dart to a raspberry pi 4 and creating an application」
https://www.youtube.com/watch?v=SHc3NB1LdlI&feature=youtu.be
という 2019/11/08 投稿の動画があります。
しかしながら老害の僕は動画だと何をやっているのかいまいちわからない。
なので実際に試した記録。
環境
- RaspberryPi 4 8GB
- Raspberry Pi OS (32-bit) Lite 2020-08-20
- ssh で操作 (ログイン済)
あらかじめ、ssh の有効か、apt update や vim のインストールなどは終わっています。
flutter のインストール
https://flutter.dev/docs/get-started/install/linux
から、
をダウンロードする必要がある。今回は RaspberryPi から直接 wget でダウンロードするので URL をコピーしておく。
youtube 動画では ~/Documnets/sdk を作業場所にしているが、Raspberry Pi OS Lite 版なので ~/Documents フォルダーは存在しない。なので ~/sdk を作ってそこにダウンロードすることにした。
$ mkdir sdk
$ cd sdk
$ wget https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_1.22.2-stable.tar.xz
$ tar xf flutter_linux_1.22.2-stable.tar.xz
~/.bashrc を編集して、最後の行に以下を追加
export PATH=$PATH:/home/pi/sdk/fultter/bin
以下のようにして設定を反映
$ source ~/.bashrc
$ flutter
とすると
Error: Unable to find git in your PATH.
と出たので
$ sudo apt install git
としてもう一度
$ flutter
/home/pi/sdk/flutter/bin/internal/shared.sh: line 214: /home/pi/sdk/flutter/bin/cache/dart-sdk/bin/dart: cannot execute binary file: Exec format error
と出る。flutter に同梱されている dart に問題があるみたいです。
dart のインストール
の
に行って、
2.10.2 (ref 1d923a3) Linux ARMv7 Dart SDK (SHA-256)
の URL をコピーしダウンロード、解凍します。
$ wget https://storage.googleapis.com/dart-archive/channels/stable/release/2.10.2/sdk/dartsdk-linux-arm-release.zip
$ unzip dartsdk-linux-arm-release.zip
flutterパッケージに含まれる dart を削除し、ダウンロードしたものに置き換えます。
$ ls -l flutter/bin/cache
$ rm -rf flutter/bin/cache/dart-sdk
$ mv dart-sdk/ flutter/bin/cache/
再度 ~/.bashrc の末尾に以下を追加
export PATH=$PATH:/home/pi/sdk/flutter/bin/cache/dart-sdk/bin
設定を反映
$ source ~/.bashrc
実行してみる
$ flutter
とすると、
Manage your Flutter app development.
Common commands:
flutter create <output directory>
Create a new Flutter project in the specified directory.
flutter run [options]
Run your Flutter application on an attached device or in an emulator.
Usage: flutter <command> [arguments]
Global options:
-h, --help Print this usage information.
-v, --verbose Noisy logging, including all shell commands
executed.
If used with --help, shows hidden options.
-d, --device-id Target device id or name (prefixes allowed).
--version Reports the version of this tool.
--suppress-analytics Suppress analytics reporting when this command runs.
--packages Path to your ".packages" file.
(required, since the current directory does not
contain a ".packages" file)
Available commands:
analyze Analyze the project's Dart code.
assemble Assemble and build flutter resources.
attach Attach to a running application.
bash-completion Output command line shell completion setup scripts.
build Flutter build commands.
channel List or switch flutter channels.
clean Delete the build/ and .dart_tool/ directories.
config Configure Flutter settings.
create Create a new Flutter project.
devices List all connected devices.
doctor Show information about the installed tooling.
downgrade Downgrade Flutter to the last active version for the current
channel.
drive Runs Flutter Driver tests for the current project.
emulators List, launch and create emulators.
format Format one or more dart files.
gen-l10n Generate localizations for the Flutter project.
install Install a Flutter app on an attached device.
logs Show log output for running Flutter apps.
precache Populates the Flutter tool's cache of binary artifacts.
pub Commands for managing Flutter packages.
run Run your Flutter app on an attached device.
screenshot Take a screenshot from a connected device.
symbolize Symbolize a stack trace from an AOT compiled flutter
application.
test Run Flutter unit tests for the current project.
upgrade Upgrade your copy of Flutter.
Run "flutter help <command>" for more information about a command.
Run "flutter help -v" for verbose help output, including less commonly used
options.
╔════════════════════════════════════════════════════════════════════════════╗
║ Welcome to Flutter! - https://flutter.dev ║
║ ║
║ The Flutter tool uses Google Analytics to anonymously report feature usage ║
║ statistics and basic crash reports. This data is used to help improve ║
║ Flutter tools over time. ║
║ ║
║ Flutter tool analytics are not sent on the very first run. To disable ║
║ reporting, type 'flutter config --no-analytics'. To display the current ║
║ setting, type 'flutter config'. If you opt out of analytics, an opt-out ║
║ event will be sent, and then no further information will be sent by the ║
║ Flutter tool. ║
║ ║
║ By downloading the Flutter SDK, you agree to the Google Terms of Service. ║
║ Note: The Google Privacy Policy describes how data is handled in this ║
║ service. ║
║ ║
║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and ║
║ crash reports to Google. ║
║ ║
║ Read about data we send with crash reports: ║
║ https://flutter.dev/docs/reference/crash-reporting ║
║ ║
║ See Google's privacy policy: ║
║ https://policies.google.com/privacy ║
╚════════════════════════════════════════════════════════════════════════════╝
と出る。
無事実行されてたみたいです。
アプリを作ってみる
sdk ディレクトリから外に出ます。
$ cd ..
test_app という名前でアプリを作ります。
$ flutter create test_app
以下のように
Creating project test_app...
test_app/pubspec.yaml (created)
test_app/README.md (created)
test_app/ios/Runner/AppDelegate.swift (created)
test_app/ios/Runner/Runner-Bridging-Header.h (created)
test_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme (created)
test_app/ios/Runner.xcodeproj/project.pbxproj (created)
test_app/.metadata (created)
test_app/lib/main.dart (created)
test_app/ios/.gitignore (created)
・
・
・
・
test_app/android/build.gradle (created)
test_app/android/app/build.gradle (created)
test_app/android/app/src/main/kotlin/com/example/test_app/MainActivity.kt
(created)
test_app/test/widget_test.dart (created)
test_app/test_app.iml (created)
Running "flutter pub get" in test_app... ⣾p
12.8s
Wrote 71 files.
All done!
You'll need to install additional components before you can run your Flutter
app:
[!] Flutter (Channel stable, 1.22.2, on Linux, locale en_GB.UTF-8)
• Flutter version 1.22.2 at /home/pi/sdk/flutter
• Framework revision 84f3d28555 (6 days ago), 2020-10-15 16:26:19 -0700
• Engine revision b8752bbfff
• Dart version 2.10.2
✗ 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
✗ Unable to locate Android SDK.
Install Android Studio from:
https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK
components.
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup
for detailed instructions).
If the Android SDK has been installed to a custom location, set
ANDROID_SDK_ROOT to that location.
You may also want to add it to your PATH environment variable.
[!] Android Studio (not installed)
• Android Studio not found; download from
https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup
for detailed instructions).
[!] Connected device
! No devices available
! Doctor found issues in 4 categories.
After installing components, run 'flutter doctor' in order to re-validate your
setup.
When complete, type 'flutter run' from the 'test_app' directory in order to
launch your app.
Your application code is in test_app/lib/main.dart
いくつかエラーらしきものが出てますね。しかしながらアプリケーションはできているっぽいので、アプリケーションディレクトリに移って実行してみます。
$ cd test_app
$ flutter run
以下のようにエラーが出ました。
Unable to locate a development device; please run 'flutter doctor' for
information about installing additional components.
flutter doctor を実行しろとあるので、試してみます。
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel stable, 1.22.2, on Linux, locale en_GB.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
✗ Unable to locate Android SDK.
Install Android Studio from:
https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK
components.
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup
for detailed instructions).
If the Android SDK has been installed to a custom location, set
ANDROID_SDK_ROOT to that location.
You may also want to add it to your PATH environment variable.
[!] Android Studio (not installed)
[!] Connected device
! No devices available
! Doctor found issues in 4 categories.
ビルド時のエラーと同じようなものが報告されました。これを解消するには Android SDK をインストールすればいいのかな?
とりあえず、動画で紹介されていたものと同じところまでは確認できました。