skip to Main Content

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


  1. Check the buildToolsVersion in build.gradle file. It should be same as which you have installed from SDK Manager -> SDK Tools where you will find Android SDK Build-Tools 31.

    dx file will be available at the location of sdk Android SDK dirbuild-tools and you will find 31.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.

    Login or Signup to reply.
  2. In the Android SDK Build Tools 31.0.0, instead of dx files, we have d8 files. You can try to create a copy and rename it into dx files.

    1. Create a copy of d8.bat and rename it to dx.bat.
    2. In the lib folder, create a copy of d8.jar and rename it to dx.jar.
    Login or Signup to reply.
  3. Issue resolved For me by changing the version 31 to 30 in build.gradle in following tags
    compileSdkVersion 30
    buildToolsVersion "30.0.0"

        targetSdkVersion 30
    
    Login or Signup to reply.
  4. 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

     "C:UsersuserAppDataLocalAndroidSdkbuild-tools31.0.0"
    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

    # 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 you can run the project

    Login or Signup to reply.
  5. 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 your

    dependencies{
        classpath 'com.android.tools.build:gradle:...'
    

    section. From here, choose to upgrade to the newest possible version (not just 4.x in my case).

    Quick fixes menu open. Option to "Invoke Upgrade Assistant for upgrade to 7.1.3" selected

    Then I run the upgrade steps for literally everything:
    Upgrade assistant window open with all items checked.

    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:
    Publishing Setting section open with "Custom Main Gradle Template" and "Custom Launcher Gradle Template" open

    Both files will have a line that looks like:

    buildToolsVersion '**BUILDTOOLS**'
    

    Which you can replace with:

    buildToolsVersion '30.0.0'
    

    From Unity, this lets me build and deploy projects as I had before without modifying the buildtools installation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search