android-studiocordovaionic-frameworkionic5android-studio-3.6.1

ANDROID_SDK_ROOT=undefined (recommended setting) while building ionic app using Cordova for Android device


I am trying to build an ionic app for Android device with Cordova using the below command from VSCode.

ionic cordova build android --prod --release

But I'm getting this error:

cordova.cmd build android --release
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\tanmay\AppData\Local\Android\sdk (DEPRECATED)
Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
[ERROR] An error occurred while running subprocess cordova.

        cordova.cmd build android --release exited with exit code 1.

I have already installed JDK, Android Studio. I also have setup the environment variable ANDROID_SDK_ROOT with the correct SDK path. But still no luck.

I am using Android Studio 3.6.1, Gradle 6.3, Cordova 8.1, on Windows 10.

I guess I am somewhere missing the setting the ANDROID_SDK_ROOT but I'm not sure where.


Solution

  • You can check if Java JDK, Android SDK, Gradle are properly installed before building an app. To do so, you can run the following command :

    cordova requirements android --verbose

    It will show, what is missing and after that, you may install it if you haven't installed it or you may check for the correct path in the Environment Variables.