Gradle build fails with build tools 31.0.0

Android Gradle Plugin 4.0.1 used in all latest Unity 2020LTS, 2021.1 and 2021.2 versions does not work with Android SDK build-tools version 31.0.0. Building a gradle project throws this error: “Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.”. The issue is not specific to Unity. It is also reproducible outside of Unity when creating Android projects with Android Gradle Plugin 4.0.1.
The recommended solution is to remove build-tools 31.0.0 and to install an older version instead.

1 Like

It is not reproducible outside of Unity if you export your Unity project and then let it upgrade your gradle plugin to 7.0.0.

Also, if people don’t want to roll back to 30, it is worth trying the following:

(from Android Studio error "Installed Build Tools revision 31.0.0 is corrupted" - Stack Overflow )

2 Likes

Gradle 4.0.1 is not supported for builds to the play store, and the lowest build allowed now is SDK 30 which requires Gradle 7.x and higher even if you succeed in rolling back the build tools, your project can’t deploy to the play store. Export your package out and bring it into Android Studio for update and rebuild, but that doesn’t seem to be compliant between Unity plugins and latest SDK 30 with the latest Gradle. Unfortunate side affect of Play Store latest requirements, ran into this brick wall the hard way for new projects.

You are mixing a few things up. Android SDK has multiple components. Build-tools is one of them, however build tools version 30 is not required by the Play store. What they require is for the apps to target API level 30, which is “platforms” component in the SDK. It is possible to use build-tools version 29 and then have platforms api level 30 installed and used as a target API level.

2 Likes

I am unable to use build tools 29 to build against SDK 30, at the end of the day I am still stuck with unable to build no matter which build tools I use and have it work, just need to target SDK 30, been working in android studio a bit trying to resolve this one way or another.

This might sound stupid, but did you uninstall build-tools 31 when using build-tools 29? Unity seems to use the latest build-tools it can find, so you’re might be still using build-tools 31 unknowingly.

Alternatively you can use the workaround posted above by AcidArrow

Yes, I uninstalled 31, started with that, android studio in its infinite wisdom, attempts to stubbornly re-install itself once removed, so you have to remove it, install the lower version, and make sure auto-update listens, which it seems to not want to do all the time.

Hi, as of October 7 2021. Is there any update about Unity build in Target API level 31 without exporting it? Just be able to build in a fresh empty project?

1 Like

facepalm

This is not about target API level 31 and it should not prevent apps from targeting API 31. You should be able to use build-tools version 30 and target API level 31 (which requires platforms;android-31 to be installed).

1 Like

As mentioned by @JuliusM , you can still target API 31 devices. You just need to do the following

  1. Open Android SDK path of Unity (you can find it in External Tools of unity preferences)
  2. Open build-tools folder
  3. Delete 31.x.x folder, if any.
  4. If you don’t have 30.x.x in the same folder, proceed to next step. Else, stop here and re-run unity
  5. Copy 30.x.x from build-tools folder of your system’s Android sdk path (which is installed through Android Studio)

Update : This workaround no longer works for 2018/2019 versions but works for >= 2020 LTS

1 Like

and how to do that

“remove build-tools 31.0.0 and to install an older version instead.”

remove from where?

3 Likes

Thank you very much! I will try

it work!! thank you very much!!!
my project is so big I need very much time to build

2 Likes

this also worked for me. I had 28.x.x in my build-tools folder and I replaced that with Android Studio’s 30.0.2

If you still encounter the error, it’s possible that your build-tools version differs from the one required by Unity.

In such a situation, navigate to your Unity editor’s folder and inspect the “modules.json” file. Inside this file, you’ll discover the specified versions required for the build-tools. Download those required versions and paste their contents into the “build-tools” folder.

1 Like

So, here is the solution for the problem.

Go to ProjectSettings, in the “Other Settings” scroll down to the “Target API Level”, choose appropriate target API level, for me Android 13(API level 33) worked. after choosing the right API level, build the apk again, you’ll be notified to install (missing)SDK, let unity install it and there you you go.

Remember in best wishes and have fun :slight_smile:

1 Like