Android Build Tools Revision Corrupted Error
Problem
When attempting to build or run a new Android project in Android Studio, you may encounter the error:
"Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager."
This issue typically occurs with Android Build Tools version 31.0.0 and prevents successful project compilation, even on simple "Hello, World!" projects.
Root Cause
The error occurs because Build Tools 31.0.0 is missing two critical files that Android Studio expects to find:
dx.bat
(Windows) ordx
(macOS/Linux)dx.jar
(in the lib subdirectory)
These files were intentionally removed from Android Build Tools 31+ as part of Google's transition from the DX tool to D8 for Dex compilation. However, some older versions of the Android Gradle Plugin (AGP) still expect these files to exist.
Solutions
Solution 1: Upgrade Your Android Gradle Plugin (Recommended)
The most future-proof solution is to update your project to use a compatible Android Gradle Plugin version that properly supports Build Tools 31+.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.2" // or higher
// For Kotlin projects:
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"
}
}
plugins {
id 'com.android.application'
id 'kotlin-android' // if using Kotlin
}
android {
compileSdk 31 // Modern syntax without buildToolsVersion
// buildToolsVersion is no longer needed from AGP 3.1.0+
defaultConfig {
minSdk 21
targetSdk 31
// ... other config
}
// ... rest of configuration
}
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
TIP
From Android Gradle Plugin 3.1.0+, you no longer need to explicitly specify buildToolsVersion
- the plugin automatically uses the minimum required version.
Solution 2: File Renaming Workaround
If you cannot immediately upgrade your Gradle plugin, you can manually create the missing files by renaming the newer D8 equivalents:
Windows
- Navigate to your Android SDK build-tools directory:cmd
cd %ANDROID_HOME%\build-tools\31.0.0
- Rename the files:cmd
ren d8.bat dx.bat cd lib ren d8.jar dx.jar
macOS/Linux
Run these terminal commands:
cd ~/Library/Android/sdk/build-tools/31.0.0 \
&& mv d8 dx \
&& cd lib \
&& mv d8.jar dx.jar
Using Symbolic Links (Alternative)
Instead of renaming, you can create symbolic links:
Windows:
mklink %ANDROID_HOME%\build-tools\31.0.0\dx.bat %ANDROID_HOME%\build-tools\31.0.0\d8.bat
mklink %ANDROID_HOME%\build-tools\31.0.0\lib\dx.jar %ANDROID_HOME%\build-tools\31.0.0\lib\d8.jar
macOS/Linux:
ln -s ~/Library/Android/sdk/build-tools/31.0.0/d8 ~/Library/Android/sdk/build-tools/31.0.0/dx
ln -s ~/Library/Android/sdk/build-tools/31.0.0/lib/d8.jar ~/Library/Android/sdk/build-tools/31.0.0/lib/dx.jar
Solution 3: Downgrade Build Tools Version
If you prefer to use an older, stable version of Build Tools:
- Open SDK Manager in Android Studio
- Go to SDK Tools tab
- Check "Show package details"
- Uncheck version 31.0.0
- Check version 30.0.3 (or another stable version)
- Click Apply to install
Then update your build.gradle
file:
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
// ... rest of configuration
}
Solution 4: Complete Reinstallation
Sometimes a complete reinstallation resolves the issue:
- Uninstall Build Tools 31.0.0 from SDK Manager
- Manually delete the directory:
%ANDROID_HOME%/build-tools/31.0.0
- Restart Android Studio
- Reinstall Build Tools 31.0.0 from SDK Manager
CI/CD Pipeline Fixes
For automated build environments like CircleCI or Azure DevOps, add these steps to your pipeline:
# For CircleCI
- run:
name: Fix missing DX files in Build Tools
command: |
cd $ANDROID_HOME/build-tools/31.0.0 && mv d8 dx && cd lib && mv d8.jar dx.jar
# For Azure DevOps
- bash: |
$ANDROID_HOME/tools/bin/sdkmanager --uninstall 'build-tools;31.0.0'
Additional Considerations
- Unity Developers: If working with Unity, you may need to uncheck "Split Application Binary" in player settings or customize Gradle templates
- Licensing Library: Ensure "Google Play Licensing Library" is installed in SDK Manager
- Annotation Conflicts: Add exclusion rules if you encounter annotation conflicts:
configurations {
compile.exclude group: 'com.intellij', module: 'annotations'
implementation.exclude group: 'com.intellij', module: 'annotations'
}
Prevention
To avoid similar issues in the future:
- Keep Android Studio and plugins updated
- Use the latest stable versions of Build Tools
- Regularly update your project's Gradle wrapper and Android Gradle Plugin
- Consider using the modern Gradle DSL without explicit
buildToolsVersion
WARNING
The file renaming workaround is a temporary solution. Plan to migrate to updated Android Gradle Plugin versions that properly support newer Build Tools.
By implementing these solutions, you should be able to resolve the "Build Tools revision is corrupted" error and continue with your Android development.