0

I'm trying to build an hybrid app using the cordova cli using command

cordova build android

But it fails with error (complete log) :

Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=undefined (DEPRECATED)
Using Android SDK: /usr/lib/android-sdk
Subproject Path: CordovaLib
Subproject Path: app

FAILURE: Build failed with an exception.

* Where:
Script '/home/iam/Projects/lave/platforms/android/CordovaLib/cordova.gradle' line: 75

* What went wrong:
A problem occurred evaluating script.
> No usable Android build tools found. Highest 30.x installed version is 27.0.1; Recommended version is 30.0.3.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1s

I have followed this step thinking it would solve the issue but problem remain and I get same error even after installing the packages.

Actual image from my Android SDK Settings : enter image description here

It's worth mentioning that I have installed Android-SDK using apt and afterwards I have set up environment path with this command :

export ANDROID_HOME="/usr/lib/android-sdk/"
export PATH="${PATH}:${ANDROID_HOME}tools/:${ANDROID_HOME}platform-tools/"

After installing the packages in Android-SDK,I restarted Ubuntu thinking it would fix the problem. But still receives same error message when trying to build. Am I missing something?

Grogu
  • 2,097
  • 15
  • 36
  • which targetSDK are you building for? – Mister_CK Jan 12 '23 at 14:28
  • @Mister_CK: This is new to me. What do you mean? – Grogu Jan 12 '23 at 15:05
  • @Mister_CK: Pardon my previous ignorance. I did research here https://stackoverflow.com/questions/24510219/what-is-the-difference-between-min-sdk-version-target-sdk-version-vs-compile-sd and I now know what you mean in theory. But in practice, I believe I'm building for any Android Device version that can run the compile apk. But I cannot even build anything at the moment – Grogu Jan 12 '23 at 19:19
  • In your config.xml you specify a target-SDK (if not, than you use the on set by cordova android, see the docs for that cordova-android version. But I would recommend always explicitely stating it). You are right that your build will run on any device that has an sdk between the minSDKVersion and MaxSDKVersion. But I ask because gradle will use the build tools for the version specified in the targetSDK. So if you have build tools-30, check that you also have targetSDK 30. – Mister_CK Jan 13 '23 at 10:05

2 Answers2

0

From the error logs I think it cannot find your ANDROID_SDK_ROOT, please check if it is set like this in your environment variables:

export ANDROID_SDK_ROOT=/Users/[USERNAME]/Library/Android/sdk
export PATH=$ANDROID_SDK_ROOT/tools:$PATH

I believe you should also set the path to your build- and platform tools like so (for your versions/paths of course):

export PATH=${PATH}:/Users/[USERNAME]/Library/Android/sdk/build-tools/33.0.0uild-tools/30.0.3
export PATH=${PATH}:/Users/[USERNAME]/Library/Android/sdk/platform-tools

Can you check that you have set al of these, or something similar? Also be aware that you may have to fix something in your build tools (this is the case for several versions, I don't know of the top of my head which ones, so it's worth to check): Android Studio error "Installed Build Tools revision 31.0.0 is corrupted"

Mister_CK
  • 668
  • 3
  • 13
0

I want to offer the solution that worked for me for Ubuntu. I suddenly remembered I had written a tutorial for mac here on SO. Remembering this made me realize I forgot to set the JAVA_HOME which Cordova looks for while Checking Java JDK and Android SDK versions. Also, ANDROID_HOME is completely obsolete and deprecated. Set the same path for ANDROID_HOME to ANDROID_SDK_ROOT (same thing).

export PATH=$PATH:$ANDROID_HOME/platform-tools 
export ANDROID_SDK_ROOT=/home/iam/Android/Sdk
export JAVA_HOME=/opt/android-studio-2021.3.1/android-studio/jre

Create a bash profile and paste the above codes then save

sudo gedit ~/.bash_profile

Run this

source ~/.bash_profile

Now when running

cordova build android --prod

Gradle should be able to configure for the first time and do the necessary tasks and then boom

BUILD SUCCESSFUL in 7m 4s
48 actionable tasks: 48 executed
Grogu
  • 2,097
  • 15
  • 36