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

Tanmay picture Tanmay · Apr 28, 2020 · Viewed 24.1k times · Source

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

ionic cordova build android --prod --release

But getting error

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 setup environment variable ANDROID_SDK_ROOT with 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 not sure where.

Your help will be highly appreciated. Thanks.

Answer

Dinesh Bala picture Dinesh Bala · Oct 14, 2020

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.