Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android build fails with Android SDK Build-Tools 31.0.0 #1288

Closed
3 tasks done
kputh opened this issue Jul 21, 2021 · 26 comments
Closed
3 tasks done

Android build fails with Android SDK Build-Tools 31.0.0 #1288

kputh opened this issue Jul 21, 2021 · 26 comments
Milestone

Comments

@kputh
Copy link

kputh commented Jul 21, 2021

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
@kputh
Copy link
Author

kputh commented Jul 21, 2021

Workaround

My first attempt to work around this issue was upgrading to cordova-android 10.0.0, and my second one was pinning the Android SDK Build-Tools version as seen above. When both failed, uninstalling the offending dependency did the trick. It can be done in Android Studio or on the command line:

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

@breautek breautek transferred this issue from apache/cordova Jul 21, 2021
@breautek breautek added this to the 11.0.0 milestone Jul 21, 2021
@breautek
Copy link
Contributor

breautek commented Jul 21, 2021

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.

@miketimofeev
Copy link

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

image

@breautek
Copy link
Contributor

breautek commented Jul 23, 2021

@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:

buildToolsVersion cordovaConfig.LATEST_INSTALLED_BUILD_TOOLS

LATEST_INSTALLED_BUILD_TOOLS gets set by:

cordovaConfig.LATEST_INSTALLED_BUILD_TOOLS = doFindLatestInstalledBuildTools(
cordovaConfig.BUILD_TOOLS_VERSION
)

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:

if (ext.cdvBuildToolsVersion == null) {
ext.cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
//ext.cdvBuildToolsVersion = project.ext.defaultBuildToolsVersion
}

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.

@pawan-logiciel
Copy link

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

@kputh
Copy link
Author

kputh commented Jul 26, 2021

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

@kputh kputh closed this as completed Jul 26, 2021
@kputh
Copy link
Author

kputh commented Jul 26, 2021

Sorry, I hit the wrong button.

@kputh kputh reopened this Jul 26, 2021
@breautek
Copy link
Contributor

The PR #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.

@breautek
Copy link
Contributor

We also merged in #1294 which will fix cordova-android to not blindly take in any build tools version, but limit the scope to use the latest patch of a particular major version. We are planning on doing a patch release sometime soon (cannot give any more details then that) so this should address the issue without using any actual parameters, though using the gradle argument to pin to a specific version might be still ideal.

As for supporting build tools 31, it looks like cordova android needs to use AGP 7 which also requires Java 11. These are all breaking changes, so I'll leave this issue open and inside our 11.x milestone.

@LucasFebatis
Copy link

I'm working with Ionic and it's forcing me to use cordova-android 9.1.0 and I'm getting the same error build tools 31.0.0

I found out that in the cordovaLib module that is generated, in build.gradle it generates with this snippet

ext {
    apply from: 'cordova.gradle'
    cdvCompileSdkVersion = privateHelpers.getProjectTarget()
    cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
    if (project.hasProperty('cdvMinSdkVersion') && cdvMinSdkVersion.isInteger()) {
        cdvMinSdkVersion = cdvMinSdkVersion as int
        println '[Cordova] cdvMinSdkVersion is overridden, try it at your own risk.'
    } else {
        cdvMinSdkVersion = 22; // current Cordova's default
    }
}

Which makes any attempt to change buildtools by environment variable or arguments impossible, because it will always use the most current version installed on the machine.

What is simple to be solved in a local development, boring but simple.

But now to update on my CI/CDs that already come with all versions available to me, what do I do?

I only see two work around

  • Create a vm image with the version of BuildTools I need (Too much work)

  • Create a step to replace the generated build.gradle with a template (Which is really annoying, since one day Android or Cordova or Ionic will fix these problems, and then I'll have to discard this step)

@breautek
Copy link
Contributor

@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.

@boredom2
Copy link

boredom2 commented Jul 31, 2021

Hi there.
After "cordova platform add android@10.0.1" and then "cordova build" (without any Plugins, just the Skeleton App), I still get "Failed to find Build Tools revision 31.0.0-rc5". What am I missing?

(before that message, I receive "Build-tool 31.0.0 rc5 is missing DX at C:\Users*\AppData\Local\Android\sdk\build-tools\31.0.0-rc5\dx.bat") Shouldnt the Fix only consider Build Tools from 30.* instead of 31?

Thanks!

@dattakadiyala
Copy link

dattakadiyala commented Aug 4, 2021

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
Copy link
Contributor

breautek commented Aug 4, 2021

(before that message, I receive "Build-tool 31.0.0 rc5 is missing DX at C:\Users*\AppData\Local\Android\sdk\build-tools\31.0.0-rc5\dx.bat") Shouldnt the Fix only consider Build Tools from 30.* instead of 31?

Thanks!

cordova-android@10.0.1 does include a patch that does just that. I wonder if the pre-release label however is causing problems. This was tested against a production release version (e.g. version 31.0.0).

@jaydrogers
Copy link

jaydrogers commented Aug 5, 2021

Just adding a note that I adopted @breautek's work around from this comment: #1288 (comment)

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!

@pcwSlide
Copy link

pcwSlide commented Aug 7, 2021

The PR #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.

Hey Norman,
I agree it needs to addressed correctly. I just removed the 31 sdk - works ok BUT- and yes - another 6 months has passed :) - it does NOT invoke the emulator automatically - it has to be open to be seen by Cordova - an issue ( we - you ) finally fixed last round.. Do I open a new ticket for this?
Phil

@NitzDKoder
Copy link

@pawan-logiciel saved by day!

@breautek
Copy link
Contributor

The PR #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.

Hey Norman,
I agree it needs to addressed correctly. I just removed the 31 sdk - works ok BUT- and yes - another 6 months has passed :) - it does NOT invoke the emulator automatically - it has to be open to be seen by Cordova - an issue ( we - you ) finally fixed last round.. Do I open a new ticket for this?
Phil

Sorry for the late response. I'm not sure if I'm fully understanding your statement but Build Tools 31 requires breaking changes to be done on our end. I don't think we need a new ticket for this, I think this ticket is sufficient is in our cordova-android@11 milestone so we can keep track of issues required to be resolved once cordova-android@11 development starts.

@pcwSlide
Copy link

Yes Build 31 does not work - so I went back a version and it did compile but once again sending to the android emulator fails to engage - you have to manually open the emulator first - same old issue.

@breautek
Copy link
Contributor

Yes Build 31 does not work - so I went back a version and it did compile but once again sending to the android emulator fails to engage - you have to manually open the emulator first - same old issue.

Ok, emulator usage is definitely not related to this issue and should be reported as a separate ticket.

@webb24h
Copy link

webb24h commented Aug 25, 2021

Just adding a note that I adopted @breautek's work around from this comment: #1288 (comment)

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!

I confirm this works. Solution for me.

@almothafar
Copy link

almothafar commented Sep 2, 2021

(before that message, I receive "Build-tool 31.0.0 rc5 is missing DX at C:\Users*\AppData\Local\Android\sdk\build-tools\31.0.0-rc5\dx.bat") Shouldnt the Fix only consider Build Tools from 30.* instead of 31?
Thanks!

cordova-android@10.0.1 does include a patch that does just that. I wonder if the pre-release label however is causing problems. This was tested against a production release version (e.g. version 31.0.0).

I got version 10.1.0 And seems does not solve the issue

image

I manually changed it in Android Studio to 30.0.3

@balaji-subramaniyam
Copy link

Hi @breautek, I have doubt that cordova build android --release -- --gradleArg=-PcdvBuildToolsVersion=30.0.3 by using this the app can able to work on Android 11 devices.

Thanks in advance.

@almothafar
Copy link

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

@JC0NN0R
Copy link

JC0NN0R commented Dec 31, 2021

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

Bro I spent all day trying to get the Android Mobile setup for the Unreal Engine and this absolutely worked....I'm running on Windows 11 so I don't know if that had anything to do with it. Your comment made my day.

@breautek
Copy link
Contributor

Resolved by #1427

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests