yasutomogのブログ

Software Engineerの雑記

CordovaのAndroidビルドエラーと環境構築

前提の環境

ビルドエラーについて

cordovaで開発するときに、Android用のビルドで以下のようなエラーが発生。

Starting 'cordova-with-build'...
(省略)
Error: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.
'cordova-with-build' errored after 5.55 s

これだけ見ると「ANDROID_HOME」を設定すればいいように見えるが環境変数として、「ANDROID_HOME」に「~/Library/Android/sdk」を設定しても同様のエラーとなり解決せず。

確認

cordova requirementsコマンドでみると、以下のようにAndroid targetがnot installedになっている。

本来であれば、ここはAndroid StudioのSDKManagerでインストールした環境が表示されるはず。

$ cordova requirements android

Requirements check results for android:
Java JDK: installed .
Android SDK: installed
Android target: not installed
Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.
Gradle: not installed
Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.

対応方法

・cordova platform rm android
・cordova platform add android

上記を試してた後に、改めてcordova requirementsコマンドを実行し、targetに正しく値が表示されていることを確認してOK

$ cordova requirements android

Requirements check results for android:
Java JDK: installed .
Android SDK: installed
Android target: installed android-21,android-22,android-23,android-24,android-25,android-26,android-27
Gradle: installed