Android Studio error “Installed Build Tools revision 31.0.0 is corrupted”

The question:

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”, 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 StructureProperties 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, and it really shouldn’t be this hard.

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

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:

  1. dx.bat
  2. 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

  1. go to the location

     "C:UsersuserAppDataLocalAndroidSdkbuild-tools31.0.0"
    
  2. find a file named d8.bat. This is a Windows batch file.

  3. rename d8.bat to dx.bat.

  4. in the folder lib (“C:UsersuserAppDataLocalAndroidSdkbuild-tools31.0.0lib”)

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

# change below to your Android SDK path
cd ~/Library/Android/sdk/build-tools/31.0.0 
  && mv d8 dx 
  && cd lib  
  && mv d8.jar dx.jar

Now run your project.

Method 2

The same problem was encountered and solved with a few line changes.

Check the Project code panel, and go to Gradle Scriptsbuild.gradle file,

  1. Change three places from 31 to 30: compileSdkVersion, buildToolsVersion, and targetSdkVersion
  2. You’ll notice a lightbulb hit occurring on modified lines. Click and choose sync [to version 30]. Android Studio will automatically download BuildTool V30 and change project settings.

Now run the app. It works for me.

Method 3

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:

  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

Method 4

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.

  • Open the terminal application and type the commands below
  • Hit Enter after every command line you type to execute the command
  • Type cd /Users/admin/Library/Android/sdk/build-tools/
  • Attention: Your user directory name may be different from “admin”
  • Navigate to the corresponding version: type cd 31.0.0
  • Type cp d8 dx
  • Type cd lib
  • Type cp d8.jar dx.jar

This fixed my issues on macOS v10.13.6 (High Sierra).

Method 5

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"
    }

Method 6

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

C:UsersUserAppDataLocalAndroidSdkbuild-tools31.0.0

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

Then go to:

C:UsersUserAppDataLocalAndroidSdkbuild-tools31.0.0lib

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

Your problem will be solved now.

Method 7

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.

  - bash: |
      $ANDROID_SDK_ROOT/tools/bin/sdkmanager --uninstall 'build-tools;31.0.0'

The environment variable $ANDROID_SDK_ROOT is in the preset variables

Method 8

Version 31.0.0 itself is corrupt, and we need to downgrade to 30.

Steps I followed for the same:

  1. Open project structure → press Ctrl + Alt + Shift + S

  2. Go to Moduleproperties → *Compiled SDK Version: 30 Build Tools Version: 30.0.2

  3. Go to Default ConfigTarget SDK Version: 30

  4. Apply and Close.

  5. Menu ToolsSDK Manager

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

  7. Apply.

Method 9

If you carefully look at the logs you’ll see:

Build-tool 31.0.0 is missing DX at path-to-sdkbuild-tools31.0.0dx.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.

Method 10

In file build.gradle (Module: HelloWorld.app):

  • compileSdkVersion 30
  • buildToolsVersion “30.0.0”
  • targetSdkVersion 30

Change the above configuration to this:

Android Studio error "Installed Build Tools revision 31.0.0 is corrupted"

Method 11

Change your Gradle build from :

android {
    compileSdkVersion 31
    buildToolsVersion '31.0.0'

    defaultConfig {
        applicationId "com.example.eg"
        minSdkVersion 23
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

to:

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.eg"
        minSdk 23
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

This will work

Method 12

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 the dx.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.

Method 13

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.

Method 14

To uninstall only Build-Tools 31.0.0 from Android Studio

Navigate to:
Configure -> SDK Manager -> SDK Tools  -> Show Package Details [check box]
click on Android SDK Build-Tools 31
uncheck 31.0.0
and Hit OK

Android Studio error "Installed Build Tools revision 31.0.0 is corrupted"

Method 15

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:

ln %ANDROID_HOME%/sdk/build-tools/31.0.0/d8 %ANDROID_HOME%/sdk/build-tools/31.0.0/dx && ln %ANDROID_HOME%/sdk/build-tools/31.0.0/lib/d8.jar %ANDROID_HOME%/sdk/build-tools/31.0.0/lib/dx.jar

Method 16

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:

buildToolsVersion "31.0.0-rc2"

Method 17

My 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)

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle (Module)

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdk 31
    buildToolsVersion "31.0.0"

    defaultConfig {
        applicationId "com.example.android12"
        minSdk 21
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

gradle-wrapper.properties

#Fri Sep 10 13:52:36 ICT 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

Method 18

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

Method 19

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.

Method 20

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

compileSdkVersion 30
buildToolsVersion "30.0.0"
defaultConfig {
    targetSdkVersion 30
}

Method 21

It’s a conflict issue with Android studio and SDK 31.

Convert your build.gradle file like this:

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
}

Method 22

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.

Method 23

In build.gradle(Module) file. Change the following settings.

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.0"

    defaultConfig {
        applicationId "com.recycleview.mvvm"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

Android Studio error "Installed Build Tools revision 31.0.0 is corrupted"

Method 24

You don’t need to specify android.buildToolsVersion from Build Tools 27.0.3 or higher.

Build Tools 27.0.3 or higher. Keep in mind, you no longer need to
specify a version for the build tools using the
android.buildToolsVersion property—the plugin uses the minimum
required version by default.

Source (Developers.Android)

Method 25

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 worked

Android Studio error "Installed Build Tools revision 31.0.0 is corrupted"

Method 26

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.

Method 27

Check your Gradle build:

android {
    compileSdkVersion 30
    buildToolsVersion "31.0.0" // Solution 1: // Downgrade it to 30.0.3

    defaultConfig {
        applicationId "com.mobiz.lottotemplate440"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

Or,

Solution 2

Download SDK 31 from SDK manager.

Method 28

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.

Method 29

Upgrade gradle to 7.0.2 might helps

Method 30

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 sync your project and it’s done.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment