No android sdk path could be found

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

Comments

kputh commented Jul 21, 2021

Bug Report

Problem

I get the following error:

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

Environment, Platform, Device

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

Version information

Project Installed Platforms:

Project Installed Plugins:

  • 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

The text was updated successfully, but these errors were encountered:

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:

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 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?

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:

Читайте также:  Полезный совет для андроида

Lines 175 to 177 in 0ce6624

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:

Lines 164 to 167 in c9108d8

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 commented Jul 24, 2021

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

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

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

Your problem will be solved now.

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

kputh commented Jul 26, 2021

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

kputh commented Jul 26, 2021

Sorry, I hit the wrong button.

breautek commented Jul 26, 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.

breautek commented Jul 26, 2021

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 commented Jul 27, 2021

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

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 commented Jul 27, 2021

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

Читайте также:  Media player bluetooth android

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 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?

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

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:

So I changed the command to:

I then installed version 30.0.3:

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

Thanks for your hard work!

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 commented Aug 19, 2021

breautek commented Aug 19, 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

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 commented Aug 19, 2021

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 commented Aug 19, 2021

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

Читайте также:  Как убрать кота андроид 11

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:

So I changed the command to:

I then installed version 30.0.3:

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

Источник

Help, adb is not found!

So you’ve downloaded Android Studio and installed the SDK. Eventually you may come across a tutorial telling you to type adb , maybe to enable debug mode in Firebase. That’s when it happens:

If your first instinct is to search for “how to install adb,” you’ll likely end up with some instructions about installing it in via your operating system’s package manager or downloading random zip files from phone customization websites. But this isn’t necessary! adb ships with the Android SDK installed by Android Studio, and with a couple of manual steps you can ensure that you’re always using the same up to date tools that your IDE is!

What’s the deal with adb?

adb stands for the “Android Debug Bridge,” which is a command line utility that is the debug multitool for Android. Typically it’s installed via Android Studio when you install the Android SDK under platform-tools , but it takes some amount of setup for your operating system to know to look there.

First open up Android Studio and navigate to “Tools > SDK Manager” from the menu.

Towards the top of the window, you can see the path where the IDE installed the Android SDK.

Now open up your terminal, type cd and paste in this path. This will work on Windows, MacOS, and Linux, but on Windows you may need to press shift+insert to paste into a terminal:

Next type cd platform-tools :

Then type ls (or dir on Windows). You should see adb or adb.exe depending on your operating system. From here you can type ./adb and see some program output.

You can run adb now, but I’ve never found a tutorial that starts with “copy your SDK path, cd into platform-tools, and type ./ before adb .” To get the experience many Android devs enjoy, you must update your PATH environment variable. This will be different on each operating system, and I’ll list out MacOS and Windows below. On Linux the steps can vary, but the MacOS instructions will work in some cases.

MacOS Configuration

MacOS (and Linux) users will typically use zsh or bash for their shell. To temporarily add the platform-tools directory to your PATH , type:

So in my example above, this becomes:

Now, whenever you type adb in this terminal window you can execute adb commands. But how do you get this to stick?

Since Android Studio tends to install the Android SDK in your user directory, you’ll want to edit the PATH for your user. And since it’s a command line utility, you’ll only need to update it for your terminal (as opposed to Mac GUI applications). To do this, you’ll want to edit the .profile file in your home directory (if this doesn’t exist, .bash_rc will achieve a similar result). This file will be hidden by default, so you may not see it Finder. Open this file in your favorite text editor:

and add this to the bottom:

Which, on my machine becomes:

Adding the extra define for ANDROID_SDK_ROOT is unnecessary, but it may help with some more complicated power user tools as well, such as the Cocos 2D command line utility.

With that, open a new terminal window and type adb . If you’ve done everything right, you’ll get a help page listing adb ‘s usage.

Windows Configuration

Windows is slightly different, and I’ll work entirely in Power Shell. Just like before, I can use the SDK manager to find my install location:

Источник

Оцените статью