failed to install the following android sdk packages as some licences have not been accepted.
Android Studioでエミュレータを起動しようとした際に、下記のようなエラーが発生した。
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
build-tools;29.0.2 Android SDK Build-Tools 29.0.2
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html
Using Android SDK: /Users/username/Library/Android/sdk
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 5m 25s
Checking the license for package Android SDK Build-Tools 29.0.2 in /Users/username/Library/Android/sdk/licenses
Warning: License for package Android SDK Build-Tools 29.0.2 not accepted.
Exception: Gradle task assembleDebug failed with exit code 1
原因
エラー文を読むと、Android SDK (build-tools 29.0.2) のライセンスに同意していないとのこと。
あれ?もしかして…。と思い、ターミナルで下記コマンドを実行し、flutterの環境を調べてみると、以下の結果が返ってきました。
$ flutter doctor
--- 一部抜粋 ---
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
やっぱりって感じでしたw
解決方法
$ flutter doctor
を実行した際に、返ってきた以下の文を参考にすれば解決できました。
Run flutter doctor --android-licenses to accept the SDK licenses.
ということでターミナルを開き、以下のコマンドを実行。
$ flutter doctor --android-licenses
上記で解決できない場合
上記方法で解決できなかった場合、ターミナルでAndroidのSDKのあるディレクトリに移動して、ライセンスをAccept。
$ cd ~/Library/Android/sdk/tools/bin
$ ./sdkmanager --licenses
上記コマンドを実行後、下記の文が表示されるので、y
を入力してEnter。
Review licenses that have not been accepted (y/N)?
上記より、Acceptされていないライセンスが順に表示されるので、
全て下記のところで y
を入力してEnter。
Accept? (y/N)
最終的に下記の文が表示されれば完了です。
All SDK package licenses accepted