Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 214
Tanmay Avatar asked Apr 28 '20 09:04

Tanmay


People also ask

What version of Android SDK do I need for Cordova?

Android SDK build-tools version 29.0.2 or higher In Android Studio 3.6 or later, you need to manually add the old version of the Android SDK Tools. To do this: See Android's documentation on Installing SDK Packages for more details. Cordova's CLI tools require some environment variables to be set in order to function correctly.

How to manage Android SDK with Android Studio?

For future reference, the Android SDK can be managed with Android Studio in the Configure » SDK Manager menu of the Android Studio welcome screen or Tools » SDK Manager inside Android projects. The Android SDK ships with useful command-line tools.

Can I use Ionic apps with Android Studio?

Ionic apps can also be launched to a device. We don't recommend using Android Studio for developing Ionic apps. Instead, it should only really be used to build and run your apps for the native Android platform and to manage the Android SDK and virtual devices.

How to get Android SDK from the command line?

Android SDK is required to build Android apps. The recommended way to download it is through Android Studioelse you need to download sdk manually Next, you need to add the Android sdk path in your Environment variable to access the command-line utility. Follow the screenshots provided in this answer for the same.


2 Answers

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.

like image 127
Dinesh Bala Avatar answered Sep 28 '22 00:09

Dinesh Bala


I had the same error. I solved it by using Gradle 5.6.3 instead of the newer versions.

like image 42
Chenru Yan Avatar answered Sep 27 '22 23:09

Chenru Yan