GUIから作業するのはあまり好きじゃないのでCLIから起動する方法を調べてみた。
Android
エミュレーターのリストを確認する。
$ emulator -list-avds Pixel_4a_API_30
エミュレーターを起動する。
私の場合、emulatorの設定は以下のようにしている。
export ANDROID_SDK_HOME="~/Library/Android/Sdk" alias emulator="$ANDROID_SDK_HOME/emulator/emulator"
$ emulator -avd Pixel_4a_API_30 -no-cache INFO | Android emulator version 31.1.4.0 (build_id 7920983) (CL:N/A) WARNING | unexpected system image feature string, emulator might not function correctly, please try updating the emulator. INFO | configAndStartRenderer: setting vsync to 60 hz WARNING | cannot add library /Users/t-sugiyama/Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libvulkan.dylib: failed INFO | added library /Users/t-sugiyama/Library/Android/sdk/emulator/lib64/vulkan/libvulkan.dylib WARNING | cannot add library /Users/t-sugiyama/Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libMoltenVK.dylib: failed INFO | added library /Users/t-sugiyama/Library/Android/sdk/emulator/lib64/vulkan/libMoltenVK.dylib INFO | Started GRPC server at 127.0.0.1:8554, security: Local INFO | Advertising in: /Users/t-sugiyama/Library/Caches/TemporaryItems/avd/running/pid_19045.ini
エミュレーターを指定してFlutterアプリを起動する。
$ flutter devices 2 connected devices: Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator) Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.110 $ flutter run -d emulator-5554 Using hardware rendering with device Android SDK built for x86. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering". Launching lib/main.dart on Android SDK built for x86 in debug mode... Running Gradle task 'assembleDebug'... 5.8s ✓ Built build/app/outputs/flutter-apk/app-debug.apk. Syncing files to device Android SDK built for x86... 123ms Flutter run key commands. r Hot reload. 🔥🔥🔥 R Hot restart. h List all available interactive commands. d Detach (terminate "flutter run" but leave application running). c Clear the screen q Quit (terminate the application on the device). 💪 Running with sound null safety 💪 An Observatory debugger and profiler on Android SDK built for x86 is available at: http://127.0.0.1:54770/zJMJwpmh0G8=/ The Flutter DevTools debugger and profiler on Android SDK built for x86 is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:54770/zJMJwpmh0G8=/
iOS
シュミレーターを起動する。
$ open -a Simulator.app
あとはAndroidと同様にdevice_idを指定して起動する。