23

I just upgraded my Android studio from 2.3 to 3.0.1. But I get this error message(I have already installed API 27 ) and don't know how to fix it, because I couldn't find the the build tools version in new version of android studio!

Error:Failed to find Build Tools revision 26.0.2 <a href="install.build.tools">Install Build Tools 26.0.2 and sync project</a>

The gradle files are changed, also the project structure has only one tab!

Edit: this is the content of `app/build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.m.finalocr"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

As you can see, there is no buildToolsVersion in it. So, why my android studio looks for this specific version(26) of that when I have the 27 version installed on my computer? Also, where can I see the buildToolsVersion "26.0.2" and change it tobuildToolsVersion "27.0.3" ` ?

Hasani
  • 3,543
  • 14
  • 65
  • 125
  • If a specific version isn't specified, the latest one installed will be used by default. – samus Sep 11 '18 at 17:42
  • 4
    As the OP I too have found this NOT to be the case. It just asks for an older version without it being specified ANYWHERE in the project. The accepted answer does not tell us WHY it's looking for that specific version. – velis Sep 26 '18 at 16:23

1 Answers1

39

Your project is looking for Build Tools version 26.0.2, but you haven't yet downloaded and installed it on your computer.

To download it, go to Tools > Android > SDK Manager, then click on the "SDK Tools" tab at the top of the new window. Then select the "Show Package Details" checkbox in the lower right-hand corner. Finally, scroll down to where you see 26.0.2, check the checkbox next to it, and click "OK" to begin the install process.

If you want to change the Build Tools version in your project, that is specified in project's build.gradle file (in the 'app' module). Open the file and either add or update the Build Tools version you want to use by adding/updating the following property in the 'android' section:

android {
    buildToolsVersion "27.0.3"
    ...
}
shagberg
  • 2,427
  • 1
  • 12
  • 23
  • Where can I change the version? May you explain more ? In android studio 2.3 it was inside build.gradle(app) in the Android tree – Hasani Mar 06 '18 at 19:25
  • @user3486308 I edited the answer to include information on how to update the version; hopefully that answers your question - you are correct, it is in the build.grade file in the app module. – shagberg Mar 06 '18 at 19:33
  • 1
    @user3486308 In that case, you need to ADD the line: buildToolsVersion "27.0.3" in the android section of your build.gradle file. Look at the sample code in my answer, and add that to the android section of your code. I'm not sure why it is defaulting the way that it is, but as long as you specific the exact version you want, it should work for you. – shagberg Mar 06 '18 at 20:14
  • @shagberg What version of the build tools will be used by default if I don't specify it? – karl Sep 30 '19 at 17:33
  • 3
    @karl That is a good question... according to https://developer.android.com/studio/releases/build-tools, "If you're using Android plugin for Gradle 3.0.0 or higher, your project automatically uses a default version of the build tools that the plugin specifies." By default, the plugin uses the minimum version of the build tools required by the version of the plugin you're using. – shagberg Oct 02 '19 at 18:19
  • @shagberg Thanks for the info. I see why they did that, and that it makes it useful for starting out, but it makes it a little annoying when you want more control – karl Oct 03 '19 at 19:07
  • @shagberg I'm back with a new question - do you know if it's possible to set this for *all* modules at once? Or do I have to add this block to every single module? – karl Aug 31 '20 at 16:02
  • @karl Not sure what you mean by "all modules"... the buildToolsVersion is set once per application in the build.gradle file, so I don't understand what you mean by "all modules". – shagberg Sep 01 '20 at 21:42
  • 1
    @shagberg I have an application with multiple modules. I want to be able to set this once and not have to worry about remembering to specify the buildToolsVersion when I add a new module. I ended up using this: https://stackoverflow.com/a/30677615/1139908 – karl Sep 03 '20 at 13:59
  • `buildToolsVersion` property is no longer needed starting from gradle v3.0.0 – Zain Aug 13 '23 at 11:17
  • `buildToolsVersion` property is no longer needed starting from gradle v3.0.0 – Zain Aug 13 '23 at 11:17