Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Gradle build fails with build tools 31.0.0

Discussion in 'Android' started by JuliusM, Aug 11, 2021.

  1. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    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.
     
    dan_ginovker likes this.
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,001
    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 https://stackoverflow.com/questions...lled-build-tools-revision-31-0-0-is-corrupted )
     
    Sodding_Toddler and EyeDev44 like this.
  3. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    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.
     
    Last edited: Sep 13, 2021
  4. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    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.
     
    ilmario and ktanyi like this.
  5. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    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.
     
  6. strike01

    strike01

    Joined:
    Mar 26, 2017
    Posts:
    1
    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
     
  7. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    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.
     
  8. TR1KK

    TR1KK

    Joined:
    Feb 7, 2015
    Posts:
    8
    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?
     
    DungDajHjep likes this.
  9. KCGames47

    KCGames47

    Joined:
    Nov 3, 2014
    Posts:
    34
    facepalm
     
  10. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    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).
     
    leni8ec likes this.
  11. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,828
    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
     
    Last edited: Apr 1, 2022
    MM_Games likes this.
  12. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    660
    and how to do that

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

    remove from where?
     
  13. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,828
     
  14. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    660
    Thank you very much! I will try
     
  15. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    660
    it work!! thank you very much!!!
    my project is so big I need very much time to build
     
  16. orkunvemosi

    orkunvemosi

    Joined:
    Jul 19, 2021
    Posts:
    1
    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
     
  17. efelatte

    efelatte

    Joined:
    May 15, 2013
    Posts:
    8
    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.
     
    Voxel-Busters likes this.
  18. UmerFarooq904

    UmerFarooq904

    Joined:
    Jan 17, 2023
    Posts:
    1
    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 :)