5

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.

2

4 Answers 4

7

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.

3

If you have an android studio installed, you need not to worry about this error on terminal, as until this error cordova will update your android package in platforms directory.

  1. Open your Android Studio.
  2. Select open existing project and browse to select your /platforms/android folder in project directory.
  3. It will open in android and will be build success
1
  • 2
    This answer is semi-usefull. Yes, it works. But it does not solve the problem to run from cli.
    – Gollm
    Aug 13, 2020 at 8:21
3

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

1

For anyone as dumb as I was that also thought you could setup and run a cordova project on android without having java, gradle or android studio installed: Once you installed all those things, delete your cordova project's node_modules, platforms, plugins and www folders and set them up again (i.e. rerun npm i, cordova platform add android, npm run build, etc) before trying to run the cordova project again. In my case I'm trying to run cordova run android which caused the same error that OP's getting.

NOTE: I have zero experience with cordova. I have to get a very specific cordova/webpack template up and running locally, and the advice I'm giving in this answer is what worked for me. YMMV.

2
  • 2
    Thanks, it actually worked, I had wasted complete 3 days trying to fix this build.
    – Pravin
    Dec 12, 2021 at 12:30
  • 1
    Along with it, I also had to copy project to different directory, something was chached in commandline as well. It did not work in same folder in vs commandline.
    – Pravin
    Dec 12, 2021 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.