38
votes

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:

  1. SDK Manager > SDK Tools > Check "Show package details" and uncheck 31.0.0 and click "apply" > Uninstall 31.0.0 > Check 31.0.0 and reinstall it
  2. 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
  3. Went to Project Structure > Properties and verified that 31.0.0 is selected for "Build Tools Version" and "Compiled SDK Version"
  4. 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)
  5. Restart Android Studio
  6. Reinstall Android Studio

I'm an Android noob just trying to set up a hello world project, it really shouldn't be this hard. I'm going crazy, someone please help. Thank you for your time

9
I would add to this that I can't seem to downgrade to Build Tools 30.0 which would be my go-to solution to an issue like this.Kevin McCarpenter
Figured it out, uncheck "Show Package Details" and then you can select a lower version. If you're not building for android 12 (and you probably aren't yet), you can uncheck "31.0.0" and check "30.0.3". After that, go into the build.gradle in your app and change buildToolsVersion "31.0.0" to buildToolsVersion "30.0.3"Kevin McCarpenter
So the real problem is 31.0.0 is actually corruptedAbraham Mathew
that is weird because I did a fresh installation of android studio and got the same problemgzinho
this might be an issue with 31.0.0, wait for another update by Google!Paramjit Singh Rana

9 Answers

31
votes

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,

  1. Change 3 places: compileSdkVersion, buildToolsVersion, targetSdkVersion from 31 to 30
  2. 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.

Now run the app. It works for me

8
votes

First of all, I face this issue in Android Studio 4.2.2 and you not need to downgrade the SDK build tool 31 to 30 or not to change compile SDK version the main problem is 2 file missing on SDK build tool 31 that are 1. dx.bat 2. dx.jar

The solution is that these files are named d8 in file location so changing their name to dx will solve the error. The steps are below.

  1. go to location

"C:\Users\user\AppData\Local\Android\Sdk\build-tools\31.0.0"

  1. find a file named d8.bat this is windows batch file.
  2. rename d8.bat to dx.bat. after changing d8.jar to dx.jar // now rename d8.jar to dx.jar it will be in location

"C:\Users\user\AppData\Local\Android\Sdk\build-tools\31.0.0\lib"

Remember AppData is a hidden folder turn on hidden items to see AppData folder

Now run your project....

5
votes

After changing these settings it seems to work fine. I downloaded sdk version 30 from sdk manager.

android { compileSdkVersion 30 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.anurag.myapplication" minSdkVersion 23 targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" }

5
votes

If you carefully look at the logs you'll see

Build-tool 31.0.0 is missing DX at path-to-sdk\build-tools\31.0.0\dx.bat

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.

2
votes

Version 31.0.0 itself is corrupt, we need to downgrade to 30. Steps I followed for the same:

  1. Open project structure > Press Ctrl+Alt+Shift+S

  2. Go to Module > properties > Compiled Sdk Version: 30 Build Tools Version: 30.0.2

  3. Go to Default Config > Target SDK Version: 30

  4. Apply & close.

  5. Tools > SDK Manager

  6. Uncheck API 31 to uninstall & check Android 11.0(R) to install (30.0.3) in my case.

  7. Apply.

1
votes

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:

  1. To open project structure > Press Ctrl+Alt+Shift+S
  2. Open Module > properties > Compiled Sdk Version: 30 Build Tools Version: 30.0.2
  3. Click on Default Config > Target SDK Version: 30

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:

  1. Go to the top Right area, and click on SDK Manager Icon.

  2. Select Android SDK > image 1 where you need to tick all Android version which you need*

  3. After tick Click OK and then install.

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

0
votes

I unchecked 31 under the SDK Manager, and clicked Android 11.0(R) to revert back to 30 then updated the Build Gradle (project) to change compileSdkVersion and targetSdkVersion from 31 to 30 and I also had to update buildToolsVersion to "30.0.2" instead of 30. Now it works.

0
votes

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

0
votes

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!

Looks like DX is removed from SDK in favor of D8.

Looks like that android gradle plugin 4.x is not aware of that.

At the moment I see only two solutions:

  1. To stay with AGP 4.x one should copy DX from 30.0.3 to 31.0.0
  2. Upgrade AGP to 7.x