Rupam Das
Rupam Das

Reputation: 473

Failed to find Build Tools revision 31.0.0

I had to reinstall Android Studio for some reason. After installing, I am not able to build my project, getting this error

Failed to find Build Tools revision 31.0.0

There's no warning or error showing in build.gradle file

enter image description here

I have tried changing compiledSdkVersion,buildToolsVersion and targetSdkVersion to 30

enter image description here

As you can see, if I change the version to 30, it is saying me to update to 31.

This is my project structure.

enter image description here

I have also tried Sync project with gradle files, Invalidate cashes, and restart, but no help. I don't know what to do now.

Upvotes: 2

Views: 8960

Answers (6)

Ashif AL
Ashif AL

Reputation: 539

Solution:

The Problem is you didn't installed the Android Studio build tools for the respective version.

Step 1: Go to Android Studio:

First Download the desired version in android studio > SDK manager > sdk Tools > android sdk build-tools 34 > 31.0.0 //install this in android studio.

Step 2: Go to Terminal:

 ~ cd home

 ~ cd yourDirectory   //eg:ashif

 ~ cd Android

 ~ cd build-tools

 ~ cd 31.0.0         //your desired build-tools version

 ~ cp d8 dx          //copy d8 and create directory dx

 ~ cd lib

 ~ cp d8.jar dx.jar  //copy d8.jar and create directory dx.jar

 ~ ls                //to list and check the changes

That's it! It Works 😊.

Upvotes: 0

Gayatri Patel
Gayatri Patel

Reputation: 866

try this one, it worked for me

compileSdk 31

defaultConfig {
    applicationId "com.app"
    minSdk 23
    targetSdk 31
    versionCode 1
    versionName "1.0"

Upvotes: 0

Amer Al zibak
Amer Al zibak

Reputation: 1951

in the app - build.gradle , change the buildToolsVersion to:

buildToolsVersion "30.0.3"

Upvotes: 2

Bankole Emmanuel
Bankole Emmanuel

Reputation: 11

I changed my build tools version to 30.0.2 at the project structure tab and it worked for me

Upvotes: 1

Rupam Das
Rupam Das

Reputation: 473

Problem fixed.

Previously the class path in my project level gradle was 4.2.2, it was not showing any warning though.

classpath "com.android.tools.build:gradle:4.2.2"

I had to replace it with

classpath 'com.android.tools.build:gradle:7.0.0'

And the project compiled successfully.

@SweetD3v's answer was helpful.

Upvotes: 1

Dev4Life
Dev4Life

Reputation: 3307

Make sure to replace the line containing classpath "com.android.tools.build:gradle:<gradle_version>" in your project level gradle with

classpath "com.android.tools.build:gradle:4.2.2"

It will add the latest gradle to your project.

If you still getting the error, then check if your compileSdkVersion & targetSdkVersion are 31.

Hope these little changes will solve your problem. :)

You will also need to change the "distributionUrl" in your gradle-wrapper.properties to distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip

And yes, as last option, try switching the buildToolsVersion from 31.0.0 to 30.0.2

Upvotes: 1

Related Questions