I’m on Android Studio 4.2.2. I created a new project and haven’t added anything to the starter code and whenever I click build or run, I get this error:
Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.
I’ve looked at other posts’ suggestions, but neither of those solutions worked. Here’s what I’ve tried:
- SDK Manager → SDK Tools → check "Show package details", uncheck 31.0.0, and click "Apply" → Uninstall 31.0.0 → check 31.0.0 and reinstall it
- In SDK Manager, deselect 31.0.0 and try installing an older version (e.g., I’ve tried 30.0.3) and update "buildToolsVersion" in build.gradle to the installed version
- Went to Project Structure → Properties and verified that 31.0.0 is selected for "Build Tools Version" and "Compiled SDK Version"
- Manually remove the stuff in the build-tools folder; i.e.,
rm -rf /path/to/android/sdk/build-tools/31.0.0
(it doesn’t end in "-rc" like some other posts have described) - Restart Android Studio
- Reinstall Android Studio
I’m an Android noob just trying to set up a Hello, World! project, and it really shouldn’t be this hard.
37
Answers
After changing these settings, it seems to work fine. I downloaded SDK version 30 from SDK Manager.
If you carefully look at the logs you’ll see:
You can try copying it from previous versions, but that won’t lend well if you have to tell your entire team to do the same and it still fails on your server pipeline. This happened to me on 31.0.0-rc5 release as well.
The same problem was encountered and solved with a few line changes.
Check the Project code panel, and go to Gradle Scripts → build.gradle file,
Now run the app. It works for me.
I unchecked 31 under the SDK Manager, clicked Android 11.0(R) to revert back to 30, and updated the Build Gradle (project) to change compileSdkVersion and targetSdkVersion from 31 to 30.
I also had to update buildToolsVersion to "30.0.2" instead of 30. Now it works.
Press Ctrl+Alt+Shift+S to open project structure. The select Module from the left.
Open Properties tab and change the followings:
Compiled Sdk Version: 30
Build Tools Version: 30.0.2
After that open Default Config tab and change:
Target SDK Version: 30
First of all, guys if you’re facing these types of issues you can try the solution where we need to shift 31 to 30.
And after that some important steps are required to do:
Step:
Build Tools Version: 30.0.2
After that, your task is not, in some cases still, you can see this configuration is not accepted, you need to do these steps also:
Go to the top Right area, and click on SDK Manager Icon.
Select Android SDK > image 1 where you need to tick all Android version which you need*
After tick Click OK and then install.
Android SDK > SDK Tool > right down side > show Package detail >
tick on 30.0.2 option and then install.
image 2 > select 30.0.2
5) Now done click OK install> apply your good to go.
Version 31.0.0 itself is corrupt, and we need to downgrade to 30.
Steps I followed for the same:
Open project structure → press Ctrl + Alt + Shift + S
Go to Module → properties → *Compiled SDK Version: 30 Build Tools Version: 30.0.2
Go to Default Config → Target SDK Version: 30
Apply and Close.
Menu Tools → SDK Manager
Uncheck API 31 to uninstall and check Android 11.0(R) to install (30.0.3) in my case.
Apply.
First of all, I faced this issue in Android Studio 4.2.2 and you do not need to downgrade the SDK build tool from 31 to 30 or change compile SDK version.
The main problem is the two files missing in SDK build tool 31 that are:
The solution is that these files are named d8 in the file location so changing their name to dx will solve the error.
The steps are below.
For Windows
go to the location
find a file named d8.bat. This is a Windows batch file.
rename d8.bat to dx.bat.
in the folder lib ("C:UsersuserAppDataLocalAndroidSdkbuild-tools31.0.0lib")
rename d8.jar to dx.jar
Remember AppData is a hidden folder. Turn on hidden items to see the AppData folder.
For macOS or Linux
Run the following in the Terminal:
Now run your project.
The point is not to downgrade target API level, but to build exactly for API level 31 to prepare and test an app for Android 12!
It looks like DX is removed from SDK in favor of D8.
It looks like that Android Gradle plugin 4.x is not aware of that.
At the moment I see only two solutions:
I don’t have enough reputation for commenting yet, but there is the solution with symbolic links for Windows, and I’d like to add that it works for macOS, too.
That’s the command for Mac’s terminal:
Try to reinstall the SDK 31 again and restart Android Studio, it should work. Otherwise, from the SDK Manager, install the SDK 30 to the System and configure the app build Gradle file as
To uninstall only Build-Tools 31.0.0 from Android Studio
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 go to:
Then find the file d8 (Executable Jar File) and rename is to dx.
Your problem will be solved now.
In file build.gradle (Module: HelloWorld.app):
Change the above configuration to this:
For those who are using Azure DevOps and require things to work with 30.0.3 you need to uninstall version 31.0.0
I added this to my pipeline to make my builds work again.
The environment variable $ANDROID_SDK_ROOT is in the preset variables
I unistalled and installed the 31.0.0 package and still it was showing the error.
I used RC2 build tools and it compiled and ran fine without downgrading to SDK version 30.
In file app/build.gradle:
It’s a conflict issue with Android studio and SDK 31.
Convert your build.gradle file like this:
There are so many wrong and misleading answers here.
The only thing you should really do is to install the latest Android Studio Beta version if you’re using the Beta SDK. With the latest Android Studio Beta comes support for the latest AGP, which correctly supports SDK 31.
The solution for Mac is pretty similar to Windows, yet not fully conclusive from reading the Windows solution. The paths and file names are different, but the problem is basically the same.
cd /Users/admin/Library/Android/sdk/build-tools/
cd 31.0.0
cp d8 dx
cd lib
cp d8.jar dx.jar
This fixed my issues on macOS v10.13.6 (High Sierra).
Check your Gradle build:
Or,
Solution 2
Download SDK 31 from SDK manager.
I downloaded
dx.bat
file from https://android.googlesource.com/platform/dalvik/+/master/dx/etc/dx.bat.I put it in
build-tools31.0.0
and then downloaded thedx.jar
file (which was also missing, by the error message I got)from http://www.java2s.com/Code/Jar/d/Downloaddxjar.htm.
I put it into directory
build-tools31.0.0lib
.Then it worked.
There are multiple solutions to this issue though one which should logically fix it does not work i.e. uninstalling build tool version 31.0.0 and reinstalling that. This solution does not work and Android Studio team probably need to look into it.
Currently which seems to work is:
Solution 1 (Downgrade Build Tool Version being used in project)
Check the Project code panel, and go to Gradle Scripts –> build.gradle file,
Change 3 places: compileSdkVersion, buildToolsVersion, targetSdkVersion from 31 to 30
You’ll notice a lightbulb hit occurring on modified lines, click and choose sync [to version 30]. The Android Studio will automatically download BuildTool V30 and change project settings.
Solution 2 (Get missing dx.bat and dx.jar files from previous version build tools)
Build-tool 31.0.0 is missing DX at path-to-sdkbuild-tools31.0.0dx.bat and
Build-tool 31.0.0 is missing DX at path-to-sdkbuild-tools31.0.0libdx.jar
You can try copying it from previous version build tools. I did from Version 30.0.3 and it worked for me.
I tried uninstalling tool 31 from the SDK manager. It successfully did so, but when building a project, it will reinstall and the same problem happens.
Then I tried the rename d8 to dx suggestion. And it starts running a bunch of tasks and causes the entire computer to hang. Seeing as how the project is just a simple activity. I’m not sure why Gradle needs to constantly connect to the Internet and take up so much of CPU usage.
After a hard reboot and fsck later, the project builds fine.
I first followed user16475264’s answer, but the real issue (at least in my case) turned out to be the version of the AGP (Android Gradle Plugin). So, after upgrading to v7, I rolled back my changes for both, the executable and the JAR file:
dx
->d8
in~/Library/Android/sdk/build-tools/31.0.0
. This workedMy
Android Studio Arctic Fox 2020.3.1 Patch 2
with
downloaded
Android 12 and Android SDK Build-Tools 31 in Android SDK
working with
buildToolsVersion "31.0.0"
build.gradle (Project)
build.gradle (Module)
gradle-wrapper.properties
In build.gradle(Module) file. Change the following settings.
Upgrade gradle to 7.0.2 might helps
Go to Android Studio setting → Android SDK → SDK tools →. In the list, mark Google Play licensing and Apply.
It will download you a file and then synchronise your project and it’s done.
Change your Gradle build from:
to:
This will work.
You don’t need to specify android.buildToolsVersion from Build Tools 27.0.3 or higher.
Source (Developers.Android)
I answered this question over here, but I’ll copy/paste the answer as it’s relevant:
As pointed out in other issues, the problem is that dx (or dx.bat) is no longer available. This was a purposeful change announced in 2018.
Suggested resolutions of renaming d8 to dx or copying it from build tools 30.0.0 will resolve the issue, but dx isn’t likely to return. So you’ll be stuck patching every build tools installation on every developer’s machine going forward.
The more forward-compatible solution is to upgrade your Android Gradle plugin. This isn’t as straightforward as just changing the number in Gradle, but I find that Android Studio’s upgrade process works well for my projects. If you open your project-level
build.gradle
file, open up the quick fixes menu from the lightbulb over yoursection. From here, choose to upgrade to the newest possible version (not just 4.x in my case).
Then I run the upgrade steps for literally everything:
My issue was Unity-specific though: I needed to use the system Android SDK rather than the one built in, but Unity itself likes to regenerate these build files and will just grab the newest buildtools it can find. To reduce manual steps and to avoid having to export my project, I instead chose to generate my module-level
build.gradle
files from my "Player Settings>Publishing Settings" window:Both files will have a line that looks like:
Which you can replace with:
From Unity, this lets me build and deploy projects as I had before without modifying the
buildtools
installation.If you were using a Mac and finished deleting build tools 31/32 and installed it again, but it still didn’t work:
Try to restart your Mac. I just did it and it solved all my problems.
For CircleCI, add this step before building, as build tools 31 is not available by default on
cimg/android:2022.08-ndk
.Remember pointing to the
cmdline-tools
, so thatsdkmanager
can run without error with Java 11.For android 12 target sdk API 31
The Android gradle plugin(AGP) should have minimum version set as
android gradle wrapper version could be set
With above configuration the build error will be resolved and you no need to downgrade the build tool version to 30.0.2
Also, if you face and intellij annotations related build error, add below configuration in your app/build.gradle file
My problem was in unity when creating .abb file.
The only thing i did was to uncheck "Split Application Binary".
The error i had before was saying, installed build tools revision 33.0.1 is corrupted.
Also the JAVA_TOOL_OPTIONS error.
I have Gradle 6.1.1 (to build .abb), and Android SDK paths (the one that is installed from android studio). NDK & SDK I use the unity default.
My build finished fine. I ran it with scripting backend Mono setting. Hopefully works with the IL2CPP too.
If this works for you, give my solution a vote 🙂
M1 Macbook solution:
go to Terminal:
Step1 :
cd ~/Library/Android/sdk/build-tools/31.0.0
Step2:
mv d8 dx
Step3:
mv d8.jar dx.jar
Step 4: Rebuild your project in Android studio. or simply run your project from android studio
Note if you are running a different version other than 31.0.0 then change the version in the step 1 command line.
In many blogs, you will find that the solution is to downgrade to the API 30, however, if you want to experiment with the API 31, downgrading isn’t a real solution. Fortunately, there’s a way to make the build tools work for API 31. The cause of the corruption of the build tools for API 31 is 2 missing files:
These files exist however with another name, specifically:
So the workaround to prevent this exception from appearing is either to copy the mentioned files that exist with the new names or create a symbolic link (shortcut in Windows) and it will magically work. This will work in all the operative systems, however the way to do it will depend of every platform.
Windows
You can do this manually or with the command prompt, to create the symlink for dx.bat (remember to replace the SDK directory with yours):
And the command to create the symlink for dx.jar:
After copying and renaming the mentioned files or running the previous commands to create the symbolic links (shortcuts), you will have new 2 files in the build-tools and build-tools/lib directory:
MacOS and Linux
If you are using MacOS or Linux, running the following command in the terminal will do the trick (it switches to the build tools directory and then moves the d8 to dx and d8.jar to dx.jar):
Try to build your project in Android Studio once again and the exception shouldn’t appear anymore!