546

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mr_broccoli
  • 5,759
  • 4
  • 9
  • 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 Jul 15 '21 at 03:17
  • 55
    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 Jul 15 '21 at 03:21
  • 44
    So the real problem is 31.0.0 is actually corrupted – Abraham Mathew Jul 16 '21 at 05:20
  • 7
    that is weird because I did a fresh installation of android studio and got the same problem – gzinho Jul 16 '21 at 23:27
  • use buildtoolsversion 31.0.0-rc2 for now.. – Monster Brain Jul 24 '21 at 10:07
  • 1
    Use the latest Android Studio Beta, it will solve this issue. Also, if you're still here OP, please don't flag a workaround as correct answer, but rather the actual solution. – joe1806772 Jul 28 '21 at 12:52
  • this solved it for me in android studio: https://stackoverflow.com/a/70015429/859849 – jfaron Jan 25 '22 at 19:41
  • I have one project (Android Studio Chipmunk) that builds fine with build tools 31.0.0 but another project which gives the error. So far I have been unable to find any differences between the two projects that should account for that error. – Brian Reinhold Jul 09 '22 at 12:03
  • Even if you rename d8.bat to dx.bat, it doesn't help - old commands to produce "dex" files don't work anymore. How Google clowns supposed to make transparent transition to d8 ??? Normal docs are needed. – Vincent Dec 12 '22 at 21:11

40 Answers40

1405

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:\Users\user\AppData\Local\Android\Sdk\build-tools\31.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:\Users\user\AppData\Local\Android\Sdk\build-tools\31.0.0\lib")

  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

Run the following in the Terminal:

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

אורי orihpt
  • 2,358
  • 2
  • 16
  • 41
Vikrant Pandey
  • 14,097
  • 2
  • 5
  • 5
  • 32
    Dug too deep to find an answer that doesn't require me to downgrade the API level. Instead of copying these files, I've created symlinks. This can be easily done from a command line: `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`. It's still a workaround though, but the cleanest one. – itachi Jul 19 '21 at 09:09
  • 71
    This should be the accepted answer. On Mac: `cd ~/Library/Android/sdk/build-tools/31.0.0 && mv d8 dx && cd lib && mv d8.jar dx.jar`. – Christopher Pickslay Jul 28 '21 at 01:17
  • tamhan@TAMHAN18:~/Android$ cd Sdk/build-tools/31.0.0/ tamhan@TAMHAN18:~/Android/Sdk/build-tools/31.0.0$ mv d8 dx tamhan@TAMHAN18:~/Android/Sdk/build-tools/31.0.0$ cd lib tamhan@TAMHAN18:~/Android/Sdk/build-tools/31.0.0/lib$ mv d8.jar dx.jar tamhan@TAMHAN18:~/Android/Sdk/build-tools/31.0.0/lib$ – Tam HANNA Aug 04 '21 at 20:03
  • another way is to install another build-tools 29.0.3 then copy those dx.bat and dx.jar into build-tools 31.0.0 folder – Tung Do Sep 07 '21 at 05:06
  • 10
    `cd $ANDROID_HOME/build-tools/31.0.0; ln -s d8 dx; ln -s lib/d8.jar lib/dx.jar; ` – Joost Sep 09 '21 at 13:08
  • 4
    Unfortunately no longer seems to work on Mac (Studio 2020.3.1 patch 2). There's only the d8 file, and renaming it to dx had no effect. There's no d8.jar file in that location. – Oscar Sep 24 '21 at 02:52
  • One culprit might be that the Gradle plug-in upgrade currently hangs forever, so it's stuck at some earlier version after other components have been updated. – Oscar Sep 24 '21 at 02:58
  • Tested and worked on Android Studio Arctic Fox 2020.3.1 Patch 3 with these settings `compileSdkVersion 31` `buildToolsVersion "31.0.0"` `targetSdkVersion 31` in the `AndroidManifests.xml` file. – Thiam Hooi Oct 15 '21 at 02:21
  • 1
    I have the same issue with 32.0.0. The above solution works fine, just change the version from 31.0.0 to 32.0.0 in the command path ;) – Tomas Dec 10 '21 at 17:12
  • This is **NOT** the correct solution, it is only a workaround. See [Andrey Alekseenko's answer](https://stackoverflow.com/a/68437642/2716245) for the correct solution. – Jim May 25 '22 at 06:58
  • I think You should try below: https://github.com/flutter/flutter/issues/51670#issuecomment-592930511 – Đức Vĩnh Lê Aug 01 '22 at 14:17
  • 1
    Verified still an issue on win10pro/intellij2020.3/builtTools33.0.0; also verified that this is the fix. – Michael McPherson Oct 19 '22 at 18:40
  • 1
    How is it possible that mobile development is so horrible? I remember how much devs complained about flash bugs back in the day and you guys are happy with this? – jacmkno Dec 20 '22 at 22:22
  • 3
    wtf Android/Google, this is such a silly issue and you have so many well-paid engineers—I shouldn't have to ask, but why is this silliness still causing *anyone* grief?! – Pyr3z Feb 09 '23 at 03:34
  • I had this issue with build tools 33.0.1 and gradle 4.1.2 – jackofallcode Mar 30 '23 at 08:34
  • Thanks! It worked for me in 2023 for Targeted SDK Version 30 -> 31 – Hashan Shalitha Jul 04 '23 at 12:42
  • AGPBI: {"kind":"warning","text":"An API level of 33 is not supported by this compiler. Please use an API level of 30 or earlier","sources":[{}],"tool":"D8"} – Engr.Aftab Ufaq Jul 25 '23 at 05:35
128

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jack Wang
  • 1,525
  • 1
  • 8
  • 3
  • 2
    If we are downgrading the build tools, it will work accepted but will not work with 31.0.0 – Abraham Mathew Jul 17 '21 at 07:21
  • 42
    Your answer is fine as a workaround. But it does not solve the actual problem if you have to work with SDK31 and build tools 31.0.0. In build tools 31.0.0, the following files "dx.bat" and "libs/dx.jar" are missing. The latest working build tools version was 31.0.0-rc4. To solve the problem in build tools 31.0.0, just copy the mentioned files from 31.0.0-rc4. However, even this is nothing more than a workaround. But at least this lets you work with build tools 31.0.0. – gal Jul 18 '21 at 10:49
  • @gal Everything works all good on local, but my CI seems to be complaining that it `Failed to find Build Tools revision 31.0.0-rc4` – CyberShark Aug 01 '21 at 13:48
  • 1
    @CyberShark That makes sense. If you work with other developers who all have to build the same project, then all of them need a working environment. So if you made a hack by copying the files "dx.bat" and "libs/dx.jar" from another build tools folder to build tools 31.0.0, then all others who work in the team must do the same. At the end, it's Google who should fix it in the next build tools version. – gal Aug 02 '21 at 15:08
  • This does not answer the question, it only provides a probably unacceptable tradeoff. Look at the highest voted answer for the working solution. – Teodor Sandu Sep 07 '21 at 22:05
64

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 10
    To clarify, it appears (from my testing) that Build Tools 31 and up are **incompatible** with AGP 4.x and below. With AGP 4.x, stay with Build Tools 30.0.3 (it seems to build with SDK 31 fine). Once you have upgraded to AGP 7.x (and Gradle 7), you can use Build Tools 31 or 32 without any issues. – big_m Dec 14 '21 at 14:14
  • Unfortunately, upgrading AppCompat to 1.4 requires to compile against API 31. – Konsumierer Dec 21 '21 at 07:56
  • 1
    I have AGP 7.2.1 and had the same issue which was resolved with file renaming :-( – hanzolo Jun 29 '22 at 17:07
56

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Chris S.
  • 1,199
  • 11
  • 25
22

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"
    }
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Anurag Singh
  • 226
  • 1
  • 4
21

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

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

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

Then go to:

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

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

Your problem will be solved now.

MYJ World
  • 820
  • 1
  • 5
  • 16
17

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

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265
  • What path do you set for ANDROID_SDK_ROOT? – H_H Jul 30 '21 at 13:02
  • In my case it was Windows - https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md – H_H Jul 30 '21 at 14:21
14

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Meghna Saha
  • 141
  • 2
11

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ramin
  • 474
  • 6
  • 22
10

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ishant Garg
  • 829
  • 9
  • 6
7

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

  • compileSdkVersion 30
  • buildToolsVersion "30.0.0"
  • targetSdkVersion 30

Change the above configuration to this:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
vinay shetty
  • 895
  • 1
  • 9
  • 15
6

I answered this question over here, but I'll copy/paste the answer as it's relevant:


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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Patrick Martin
  • 2,993
  • 1
  • 13
  • 11
6

enter image description here

In many blogs, you will find that the solution is to downgrade to the API 30, however, if you want to experiment with the API 31, downgrading isn't a real solution. Fortunately, there's a way to make the build tools work for API 31. The cause of the corruption of the build tools for API 31 is 2 missing files:

  • dx.bat
  • dx.jar

These files exist however with another name, specifically:

  • d8.bat
  • d8.jar

So the workaround to prevent this exception from appearing is either to copy the mentioned files that exist with the new names or create a symbolic link (shortcut in Windows) and it will magically work. This will work in all the operative systems, however the way to do it will depend of every platform.

Windows You can do this manually or with the command prompt, to create the symlink for dx.bat (remember to replace the SDK directory with yours):

mklink C:\Users\username\AppData\Local\Android\Sdk\build-tools\31.0.0\dx.bat C:\Users\username\AppData\Local\Android\Sdk\build-tools\31.0.0\d8.bat

And the command to create the symlink for dx.jar:

mklink C:\Users\username\AppData\Local\Android\Sdk\build-tools\31.0.0\lib\dx.jar C:\Users\username\AppData\Local\Android\Sdk\build-tools\31.0.0\lib\d8.jar

After copying and renaming the mentioned files or running the previous commands to create the symbolic links (shortcuts), you will have new 2 files in the build-tools and build-tools/lib directory:

enter image description here

MacOS and Linux If you are using MacOS or Linux, running the following command in the terminal will do the trick (it switches to the build tools directory and then moves the d8 to dx and d8.jar to dx.jar):

cd ~/Library/Android/sdk/build-tools/31.0.0 && mv d8 dx && cd lib && mv d8.jar dx.jar

Try to build your project in Android Studio once again and the exception shouldn't appear anymore!

5

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
Dmitry
  • 91
  • 6
5

I downloaded dx.bat file from https://android.googlesource.com/platform/dalvik/+/master/dx/etc/dx.bat.

I put it in \build-tools\31.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-tools\31.0.0\lib.

Then it worked.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Yuval A.
  • 5,849
  • 11
  • 51
  • 63
5

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)

Ngima Sherpa
  • 1,397
  • 1
  • 13
  • 34
4

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.

4

To uninstall only Build-Tools 31.0.0 from Android Studio

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

enter image description here

Sachin Chillal
  • 393
  • 4
  • 6
3

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"
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Monster Brain
  • 1,950
  • 18
  • 28
3

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
Linh
  • 57,942
  • 23
  • 262
  • 279
3
  1. In Finder/File explorer, go to Android's build-tools folder. In Mac, it's at /Users/<username>/Library/Android/sdk/build-tools.
  2. Rename d8.exe to dx.exe
  3. Go inside lib folder
  4. Rename d8.jar to dx.jar
Yuvraj Patil
  • 7,944
  • 5
  • 56
  • 56
3

I was getting the same error for API 33. I tried several solutions answered above but what worked for me was uninstalling all the API and dependencies of version 33.0.0 and reinstalling them back.

It takes some time but it worked. Here's how you can uninstall and install them back in Android Studio - https://stackoverflow.com/a/54851554/7584658

Hope that helps. Thanks

Supercool
  • 453
  • 1
  • 4
  • 9
2

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Meg
  • 21
  • 1
2

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

Mubtasim Fuad
  • 339
  • 2
  • 4
2

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
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
neelkanth_vyas
  • 192
  • 1
  • 7
2

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"
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
joe1806772
  • 506
  • 6
  • 20
2

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

enter image description here

vinay shetty
  • 895
  • 1
  • 9
  • 15
2

M1 Macbook solution:

go to Terminal:

Step1 : cd ~/Library/Android/sdk/build-tools/31.0.0

Step2: mv d8 dx

Step3: mv d8.jar dx.jar

Step 4: Rebuild your project in Android studio. or simply run your project from android studio

Note if you are running a different version other than 31.0.0 then change the version in the step 1 command line.

Mirza Q Ali
  • 477
  • 5
  • 6
1

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 Gradle Build plugin

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ddsultan
  • 2,027
  • 1
  • 19
  • 19
  • Which one did you change to here? be specific – TheRealChx101 Jan 05 '22 at 16:33
  • @TheRealChx101, by default (with my Android Studio version) the AGP (Android Gradle Plugin) was `4.x` and I followed user16475264's answer but after upgrading to `v7` that original problem was gone so I rolled back what I had done with user16475264's answer. – ddsultan Jan 05 '22 at 17:56
1

Upgrade gradle to 7.0.2 might helps

kevinzhow
  • 74
  • 5
1

For android 12 target sdk API 31

compileSdkVersion 31
buildToolsVersion 31.1.0

The Android gradle plugin(AGP) should have minimum version set as

7.0.2 or above

android gradle wrapper version could be set

gradle-7.2-bin.zip

With above configuration the build error will be resolved and you no need to downgrade the build tool version to 30.0.2

Also, if you face and intellij annotations related build error, add below configuration in your app/build.gradle file

configurations {
        compile.exclude group: 'com.intellij', module: 'annotations'
        implementation.exclude group: 'com.intellij', module:'annotations'
    } 
Ashok Kumar
  • 1,226
  • 1
  • 10
  • 14
0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

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-sdk\build-tools\31.0.0\dx.bat and Build-tool 31.0.0 is missing DX at path-to-sdk\build-tools\31.0.0\lib\dx.jar

You can try copying it from previous version build tools. I did from Version 30.0.3 and it worked for me.

Akhilesh
  • 196
  • 3
  • 5
0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
placid chat
  • 179
  • 10
0

Go to Android Studio setting → Android SDKSDK tools →. In the list, mark Google Play licensing and Apply.

It will download you a file and then synchronise your project and it's done.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bagher
  • 29
  • 3
0

If you were using a Mac and finished deleting build tools 31/32 and installed it again, but it still didn't work:

Try to restart your Mac. I just did it and it solved all my problems.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
chandra
  • 19
  • 3
0

For CircleCI, add this step before building, as build tools 31 is not available by default on cimg/android:2022.08-ndk.

- run:
      name: Preinstall SDK 31, fix SDK 31 and 33 missing DX files
      command: |
        echo yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "build-tools;31.0.0"
        cd $ANDROID_HOME/build-tools/33.0.0 && mv d8 dx && cd lib && mv d8.jar dx.jar
        cd $ANDROID_HOME/build-tools/31.0.0 && mv d8 dx && cd lib && mv d8.jar dx.jar

Remember pointing to the cmdline-tools, so that sdkmanager can run without error with Java 11.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tuan Dat Tran
  • 425
  • 5
  • 7
0

My problem was in unity when creating .abb file.

The only thing i did was to uncheck "Split Application Binary".

The error i had before was saying, installed build tools revision 33.0.1 is corrupted. Also the JAVA_TOOL_OPTIONS error.

I have Gradle 6.1.1 (to build .abb), and Android SDK paths (the one that is installed from android studio). NDK & SDK I use the unity default.

My build finished fine. I ran it with scripting backend Mono setting. Hopefully works with the IL2CPP too.

If this works for you, give my solution a vote :)

alfredo-fredo
  • 652
  • 7
  • 7
0

I had this same issue using SDK Build tools 34.0.0. My fix was to update gradle:

gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip

android/build.gradle:

       classpath("com.android.tools.build:gradle:7.3.1")
Glenn
  • 1,996
  • 2
  • 24
  • 32