Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.
Studio Version 4.2.1
Tried Reinstalling and removing previous versions
Tried adding dx.jar and dx.bat from build-tools-30.0.3 (This is not a good solution even after adding it shows dx.jar file is not there)
5
Answers
Check the
buildToolsVersion
inbuild.gradle
file. It should be same as which you have installed fromSDK Manager -> SDK Tools
where you will findAndroid SDK Build-Tools 31
.dx
file will be available at the location of sdkAndroid SDK dirbuild-tools
and you will find31.0.0-rc3 (Open this folder and check manually if dx file is there or not)
. If all works fine then restart and rebuild the project.If
dx
file is not there then uninstall the build tools from Android Studio and reinstall it again from Android Studio.In the Android SDK Build Tools 31.0.0, instead of
dx
files, we haved8
files. You can try to create a copy and rename it intodx
files.d8.bat
and rename it todx.bat
.lib
folder, create a copy ofd8.jar
and rename it todx.jar
.Issue resolved For me by changing the version 31 to 30 in build.gradle in following tags
compileSdkVersion 30
buildToolsVersion "30.0.0"
The main problem is the two files missing in SDK build tool 31 that are
dx.bat
dx.jar
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
Remember AppData is a hidden folder. Turn on hidden items to see the AppData folder.
For macOS or Linux
Now you can run the project
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.