skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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
    

  2. 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"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search