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.
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.
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.
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.
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.
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.
I had the same error. I solved it by using Gradle 5.6.3 instead of the newer versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With