- How to Fix “SDK location not found” in Android Studio?
- When switching from one IDE to another (Like from Eclipse to Android Studio)
- How to install Android SDK and setup AVD Emulator without Android Studio
- Understanding the Android SDK
- Installing the Android SDK
- Step 1 — Download the tools package
- Step 2— You need Java 8!
- Step 3 — Download the essential packages
- Step 4 — Set your environmental variables
- Step 5 — Download the platform specific packages you want
- Step 5 — Create a AVD device
- Step 6 — Run the Android Emulator
- Android build fails with Android SDK Build-Tools 31.0.0 #1288
- Comments
- kputh commented Jul 21, 2021
- Bug Report
- Problem
- What is expected to happen?
- What does actually happen?
- Information
- Command or Code
- Environment, Platform, Device
- Version information
- Checklist
- kputh commented Jul 21, 2021 •
- Workaround
- breautek commented Jul 21, 2021 •
- miketimofeev commented Jul 23, 2021
- breautek commented Jul 23, 2021 •
- pawan-logiciel commented Jul 24, 2021
- kputh commented Jul 26, 2021
- kputh commented Jul 26, 2021
- breautek commented Jul 26, 2021
- breautek commented Jul 26, 2021
- LucasFebatis commented Jul 27, 2021
- breautek commented Jul 27, 2021
- boredom2 commented Jul 31, 2021 •
- dattakadiyala commented Aug 4, 2021 •
- breautek commented Aug 4, 2021
- jaydrogers commented Aug 5, 2021 •
- The error I was seeing
- First, I had a different ENV var
- So I changed the command to:
- I then installed version 30.0.3:
- pcwSlide commented Aug 7, 2021
- NitzDKoder commented Aug 19, 2021
- breautek commented Aug 19, 2021
- pcwSlide commented Aug 19, 2021
- breautek commented Aug 19, 2021
- webb24h commented Aug 25, 2021
- The error I was seeing
- First, I had a different ENV var
- So I changed the command to:
- I then installed version 30.0.3:
How to Fix “SDK location not found” in Android Studio?
Google developed Android SDK which is a Software Development Kit developed by Google for the Android platform. You can create Android apps using Android SDK, and you don’t need to be an expert to use it. Android SDK and Android Studio come bundled together, with Google’s official integrated development environment (IDE) for the Android operating system.
In this article, we see how to fix an error that is related to the main Android building component of Android Studio that is the Android SDK. The most common error related to Android SDK is “SDK location not found“. This message pops up stating that the location of Android SDK was not detected when the path of SDK is assigned incorrectly. There can also be other reasons for this error message as well and we will see ways to get rid of this error.
When switching from one IDE to another (Like from Eclipse to Android Studio)
Method 1
In this case, follow the below steps:
Method 2
In case the above procedure doesn’t work then add the ANDROID_HOME variable in “Environment Variables” as C:\Users\Username\AppData\Local\Android\Sdk.
Method 3
In case it does not work even then, then you need to change the directory path on Project Structure as well.
- Close the current project and you’ll see a pop-up with a dialog which will then proceed to Configure option.
- Configure -> Project Defaults -> Project Structure -> SDKs on left column -> Android SDK Home Path -> give the exact path as you did on local.properties and select Valid Target.
Method 4
A settings.gradle file might be missing from the project. Make sure that the file exists from the project you are importing. If not add the settings.gradle file with the following:
Save the file and put it in the top-level folder in your project.
Источник
How to install Android SDK and setup AVD Emulator without Android Studio
If you are trying to develop to Android, you probably will end up installing the Android Studio to get the Android SDK and the AVD Emulator working properly.
But if you are using another code editor, like Sublime Text or VSCode, installing the Android Studio will just mess up with your setup and consume your precious RAM for no good reason.
I had a hard time figuring out how to properly do this setup due the lack of documentation about it, so i hope this article helps you. 🙂
Recommended previous knowledge:
- SDK (Standard Development Kit); Read about on Wikipedia;
- AVD (Android Virtual Device); Read about on docs;
- CLI (Command Line Interface); Read about on Wikipedia;
- Android API levels; Read about on Vanderbilt University;
- How to open, navigate and execute files in your OS terminal;
- Know what are environmental variables;
Understanding the Android SDK
Basically, the Android SDK is a bunch of packages necessary to develop for Android.
These packages stays in subfolders of a folder called “sdk” (or “android-sdk” sometimes). You do not need to know how these packages really work, just what they do.
The picture below is my Android SDK folder, these are the basic packages you will need in order to get everything working properly.
Here is a brief explanation of each package:
- tools: This package is mainly used to manage the other packages and to create AVD’s;
- emulator: As the name suggest, this is the Android emulator;
- platform-tools: Some tools to communicate with Android devices when you plug then in your computer;
- patcher: This package is automatically downloaded by the SDK. I didn’t find what exactly this is for, so just leave it as it is;
The folders bellow contain sub-folders with the packages for each Android API level.
- platforms: The platform packages are required to compile your app for the specified API level.
- system-images: These are the android images used in the emulator.
- build-tools: These are necessary to build your Android apps
Installing the Android SDK
In order to install the SDK we will use the Command Line Tools. These are some quite simple CLI’s used to manage the Android SDK. You can read the documentation here for more details.
Step 1 — Download the tools package
First, you need to download the tools package. And with this package you can download the others.
- First, go to the Android Studio download page: https://developer.android.com/studio;
- Then click in “ Download Options”;
- There you will find a table named “ Command line tools only”;
- This table contain some zip files. Download the appropriate file for your system ( Windows, Mac or Linux);
- Extract this zip and you will get a folder called tools: This is the tools package i explained earlier;
Create a folder anywhere you prefer to place your SDK. I recommend you to stick with one of these commonly used places:
- Globally: C:\Android\sdk or C:\android-sdk (this is not default, but i usually set my SDK here on Windows)
- One user only: C:\Users\ \AppData\Local\Android\sdk
- Globally: /Library/Android/sdk
- One user only: /Users/ /Library/Android/sdk
And move the tools folder to this new sdk folder. Make sure you have admin access to this folder and any sub-folders inside it, or the tools package will fail to download new packages.
Note: You can also download a pre-build package for your SO (like the one available on Ubuntu repository). But i do not recommend you do to so, because they probably will not be updated and will be harder to manage, since it was automatically installed.
Step 2— You need Java 8!
The Android SDK packages require Java 8. If you do not have it, you need to download. If you are using a newer version, you have to downgrade to Java 8 or you will eventually get some errors, because it is not compatible.
If you do not have the Java 8 SDK, here is how you can install it:
On Ubuntu run these commands:
- # sudo apt-get update
- # sudo apt-get install openjdk-8-jdk
Sorry for MacOS users, i don’t know how to install it on this OS.
Step 3 — Download the essential packages
Now, download the platform-tools and the emulator packages, because they contain some CLI binary files you will need later. I decided to download these packages first in order to set all the necessary environment variables at once and make the rest of the process easier.
Open a terminal window (you need to use a terminal, not the file explorer), go to your sdk folder and navigate to the /tools/bin directory.
This folder contain the SDKManager binary: this is a CLI used to list the available packages in the Google’s repository and download, update or remove them from your SDK folder.
The bellow command will list all packages installed (the first items on the list) and all packages available to download:
To download the packages, simply copy the package names and pass it as a parameter to the SDKManager CLI using the terminal:
# ./sdkmanager platform-tools emulator
If you open your sdk folder you should see these packages folders there.
Step 4 — Set your environmental variables
You need to set the below environmental variables containing the path to our SDK, so any running program can find it in your pc:
ANDROID_SDK_ROOT = Path to your SDK folder
ANDROID_HOME = The same as ANDROID_SDK_ROOT. This variable is now deprecated, but i recommend setting it because some programs still using it to locate your sdk.
And add these folders to the PATH variable, making their binary files accessible from everywhere:
To add the environment variables on WIndows, just follow these steps:
- Open the “Control Panel”;
- Go to “ System and Security” option in the side menu;
- In the window “ System Properties” open the tab “ Advanced”;
- Click in the button “ Environment Variables” in the bottom of the page;
- In the “ Environment Variables” window you will see two tables: “User Variables” and ” System Variables”.
- If you created your sdk folder for one user only, set the variables in the “ User Variables” table;
- But, if you create your sdk folder globally, set the variables in the “ System Variables” table instead;
On Linux, you can set your environment variables in many places. So i choose the ones I found the most appropriate:
- If you created your sdk folder for one user only, set your environment variables in the file
/.bashrc;
Here is how i set these variables in my Ubuntu, using the file /etc/environment:
And sorry again, no MacOS instructions for this task.
You can find more about these environmental variables in the oficial docs here.
Now your SDK is ready! If you do not need to run the emulator there’s no need to follow the next steps.
Step 5 — Download the platform specific packages you want
You need more three packages: The platform, the system-image and the build-tools. You can download these packages for any Android version you prefer. In this article, i will download the packages for the API Level 28.
Use the “ sdkmanager — list” command to find these packages and download them using the command “ sdkmanager
Here’s an example:
Step 5 — Create a AVD device
Creating a AVD device is a simple task: run the AVDManager command (this is a binary file located in the tools/bin folder of your sdk) with the create avd option, a name for the new AVD and the image you want to use.
Here is a example:
# avdmanager create avd — name android28 — package “system-images;android-28;default;x86”
You will be asked if you want to alter some configurations. You can also modify these configurations later in the file config.ini, located in the avd folder (this folder usually is created in your user folder, under the android directory). The currently active configurations can be find in the file hardware-qemu.ini (this file just will be created after the emulator runs for the first time).
Step 6 — Run the Android Emulator
Now you just need to run the emulator command (remember that we added this package to the environmental variables?):
The emulator take some time to init for the first time. But if you done everything correctly you should see this screen:
Источник
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?
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:
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
Источник