cordova-android: Android build fails with Android SDK Build-Tools 31.0.0

Bug Report

Problem

When I run

cordova build android --release -- --gradleArg=-PcdvBuildToolsVersion=30.0.3

I get the following error:

Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=undefined (DEPRECATED)
Using Android SDK: /Users/kaiputh/Library/Android/sdk
Reading build config file: /Users/kaiputh/code/project/feuerwehr/viewer/build.json
Subproject Path: CordovaLib
Subproject Path: app
Build-tool 31.0.0 is missing DX at /Users/kaiputh/Library/Android/sdk/build-tools/31.0.0/dx
Build-tool 31.0.0 is missing DX at /Users/kaiputh/Library/Android/sdk/build-tools/31.0.0/dx

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':CordovaLib:compileReleaseAidl'.
> Failed to query the value of task ':CordovaLib:compileReleaseAidl' property 'aidlFrameworkProvider'.
   > Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.

* 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

BUILD FAILED in 1s
Command failed with exit code 1: /Users/kaiputh/code/project/feuerwehr/viewer/platforms/android/gradlew cdvBuildRelease -b /Users/kaiputh/code/project/feuerwehr/viewer/platforms/android/build.gradle -PcdvBuildToolsVersion=30.0.3

The build seems to ignore the pinned Android Build-Tools version.

This issue started appearing in our build pipeline between July 19., 13:20 UTC and July 20., 08:38 UTC. I can’t tell when the Android SDK Build-Tools 31.0.0 were release, but cordova-android 10.0.0 was release July 20., 04:17 (timezone?). That may be no coincidence.

What is expected to happen?

The build should succeed.

What does actually happen?

The build fails.

Information

Command or Code

cordova build android --release -- --gradleArg=-PcdvBuildToolsVersion=30.0.3

Environment, Platform, Device

Azure Pipelines, vmImage ‘macOS-10.15’, and local development (see below)

Version information

Cordova Packages:

  • cli: 10.0.0
    • common: 4.0.2
    • create: 3.0.0
    • lib: 10.0.0
      • common: 4.0.2
      • fetch: 3.0.0
      • serve: 4.0.0

Project Installed Platforms:

  • android: 9.0.0
  • ios: 6.2.0

Project Installed Plugins:

  • none

Environment:

  • OS: macOS 11.4 (20F71) (darwin 20.5.0) x64
  • Node: v12.16.3
  • npm: 6.14.4

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 26 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Migrated this to cordova-android for you since this is the package that is responsible for handling the android environment.

Our supported API level on cordova-android@10 is API 30, so build-tools version 30 should work. I’ve placed this issue in the 11.x milestone because generally we only officially support the next API level in a major releases. However, if it is possible to fix this without introducing breaking changes, then we may include it in a future minor release.

Currently cordova-android will look for the latest installed version of build tools, which is probably a bad idea for this very reason. Which is why the uninstalling build-tools 31 is the necessary workaround.

Just adding a note that I adopted @breautek’s work around from this comment: https://github.com/apache/cordova-android/issues/1288#issuecomment-884423978

His workaround pointed me in the right direction, but I needed to make a few changes…

The error I was seeing

What brought me to this thread was seeing this error message:

No usable Android build tools found. Highest 30.x installed version is 30.0.2; minimum version required is 30.0.3.

Then when I upgraded to 31.0.0, I realized that did not work either 😅

First, I had a different ENV var

I saw @breautek’s comment and noticed his variable was ANDROID_HOME, but mine was ANDROID_SDK_ROOT. Thankfully I noticed this in my logs:

ANDROID_SDK_ROOT=/Users/jay/Library/Android/sdk (recommended setting)
ANDROID_HOME=undefined (DEPRECATED)

So I changed the command to:

$ANDROID_SDK_ROOT/tools/bin/sdkmanager --uninstall "build-tools;31.0.0"

I then installed version 30.0.3:

$ANDROID_SDK_ROOT/tools/bin/sdkmanager --install "build-tools;30.0.3"

Hope this helps as people smarter than me helps diagnose an actual solution 🤓

Thanks for your hard work!

Hey @kputh In order to fix the issue, firstly go to the following location:

C:\Users\User\AppData\Local\Android\Sdk\build-tools\31.0.0

Then find the file d8 (Windows batch file) and rename it to dx.

Then go to:

C:\Users\User\AppData\Local\Android\Sdk\build-tools\31.0.0\lib

Then find the file d8 (Executable Jar File) and rename is to dx.

Your problem will be solved now.

https://stackoverflow.com/questions/68387270/android-studio-error-installed-build-tools-revision-31-0-0-is-corrupted

I have also the same problem which gets resolved with above solution

if any one using Azure devOps, Microsoft hosted macOS agents, adding this as a command-line task before the build should do SDKMANAGER=$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager echo y | $SDKMANAGER --uninstall "build-tools;31.0.0"

@breautek am I right that none of these options will work and there is no way to pin the build-tools version?

Correct, and further investigation on the “why” identifies another bug.

The desired build tools get set here:

https://github.com/apache/cordova-android/blob/0ce66249dafc916c5c2197d4c92cc51b555f777b/templates/project/app/build.gradle#L192

LATEST_INSTALLED_BUILD_TOOLS gets set by:

https://github.com/apache/cordova-android/blob/0ce66249dafc916c5c2197d4c92cc51b555f777b/framework/cordova.gradle#L175-L177

Where BUILD_TOOLS_VERSION is comes from the config shown in your docs screenshot. As the doFindLatestInstalledBuildTools function name might suggest, it finds the latest build tools version, with the parameter being the “minimum” required version.

In fact, this behaviour did change as cordova-android 9.1 did:

https://github.com/apache/cordova-android/blob/c9108d8479641b92b1694b48237830ebbe6a6444/bin/templates/project/app/build.gradle#L164-L167

And only used findLatestInstalledBuildTools if the user parameter wasn’t specified. I do believe this wasn’t intentional and this issue probably should be reported as a separate issue, which I’ve already done here.

Any update on this? also android platform 32 and built tools 32.0.0 have already been released!

@LucasFebatis android version 10.0.1 (unreleased, pending votes) will fix the platform so that it will find the latest build tools release of a specific major rather than blindly choosing the latest available. Additionally the same version also fixes the flag (regression introduced in 10.0.0) so that if declared it will use a specific build tools version of your choice, as long as it’s >= our minimum build tools version.

You can give it a try by installing the nightly version. Note that Cordova android 9.x won’t be patched.

The PR https://github.com/apache/cordova-android/pull/1293 should provide a better workaround (by fixing the actual gradle arg parameter).

Hoping it will be reviewed and be included in our patch release.

@pawan-logiciel, thank you for the workaround. Unfortunately, I can’t use it in out build pipeline