2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

M1 MacでAndroidエミュレーターを起動する

Last updated at Posted at 2021-11-07

はじめに

Flutterのアプリ開発をしようとしてめちゃくちゃハマりました。

Flutterのチュートリアル

iOSはこれ見ながらやれば大丈夫です。

問題はAndroid

何が問題か

手順の途中で flutter doctor でそれぞれのプラットフォームが起動準備できているか確認します。

iOS であれば XCode, Android であれば Android Studioを事前にインストールしておきましょう。

しかし、AndroidについてSDKがないと怒られました。

解決策

SDKを手動で入れます。

まず、JDKを入れましょう。とりあえず brew で最新stableをインストールしましょう。

$ arch -arm64 brew install openjdk

次に sdkmanager と呼ばれる Android SDK用のCLIをインストールします。

# 解凍したものを、~/Library/Android/sdk/cmdline-tools/latest に配置します
# ~/Library/Android/sdk/cmdline-tools/latest/bin へのパス通しも忘れずに
$ sdkmanager --list

# 上記の結果からインストールしたいものを選択してインストール
$ sdkmanager "*****"

ここでSDKのインストールまでは良かったのですが、Flutterではbuild-toolsが必要なのです。
これがインストールできない。

$ sdkmanager "build-tools:*.*.*"

Warning: Dependant package with key emulator not found!                         
Warning: Unable to compute a complete list of dependencies.

CLIだと原因が出ませんが、同様のコマンドをAndroid Studioで実行するとどうやらエミュレーターが事前に必要とのこと。

なので以下を実行してインストールします。

$ sdkmanager --channel=3 emulator

もう一度実行

$ sdkmanager "build-tools;*.*.*"
[=======================================] 100% Unzipping... android-Sv2/zipalign

これでいけるはず

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-arm, locale ja-JP)
[!] Android toolchain - develop for Android devices (Android SDK version 32.0.0-rc1)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.61.2)
[✓] Connected device (1 available)

ライセンスに同意して

$ flutter doctor --android-licenses

これで、、、

$ flutter doctor                   
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-arm, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0-rc1)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.61.2)
[✓] Connected device (1 available)

• No issues found!

あとは公式ドキュメントの手順でエミュレーターを起動してプロジェクト作成すれば完了です。

長かった。。。3時間は溶けた。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?