36

Though I have an updated android studio I am getting the following error but I cannot find gradle 4.1 in the gradle folder but when I check file -> project structure -> gradle plugin is 4.

Error:Could not find com.android.tools.build:gradle:4.1.
Searched in the following locations:
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/4.1/gradle-4.1.pom
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/4.1/gradle-4.1.jar
https://jcenter.bintray.com/com/android/tools/build/gradle/4.1/gradle-4.1.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/4.1/gradle-4.1.jar
https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1/gradle-4.1.pom
https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1/gradle-4.1.jar

And my build.gradle file is this. I set it to 23 because I need to run it on 5.0.1 phone.

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
    applicationId "com.example.threewire.myapplication"
    minSdkVersion 10
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
threewire
  • 471
  • 1
  • 4
  • 13

5 Answers5

137

check your tools version, it should be 3.0.1

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

please note that google() repository is important. the newer plugin is posted there.

Gaurav Singh Faujdar
  • 1,662
  • 1
  • 9
  • 13
  • 22
    Same, I was missing `google()` and adding it resolved the issue for me. – Simon Dec 05 '17 at 15:55
  • 1
    This helped me out too, with a project that would build inside Android Studio but not from the command line. – Mike Playle Dec 13 '17 at 13:59
  • 3
    @threewire can you please change this as the correct answer. – vijay Feb 08 '18 at 18:49
  • Adding this just caused another error: Where: Build file 'C:\Users\mmo\StudioProjects\ListPro\build.gradle' line: 4 * What went wrong: A problem occurred evaluating root project 'ListPro'. > Could not find method google() for arguments [] on repository container. – mmo Mar 12 '18 at 10:40
  • Workaround to last error described here: https://stackoverflow.com/questions/45781489/error6-0-gradle-dsl-method-not-found-google – mmo Mar 12 '18 at 10:46
34

Try adding google() in repositories.

Derlin
  • 9,572
  • 2
  • 32
  • 53
kinich49
  • 486
  • 4
  • 8
11

For my project is correct next construction in "build.gradle":

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}
V.March
  • 1,820
  • 1
  • 21
  • 30
8

you can add this statement to your gradle.properties file

android.enableAapt2=false
Michael
  • 411
  • 2
  • 6
  • 15
  • 1
    I added that as your suggested but still I am getting the same error. – threewire Nov 28 '17 at 05:21
  • 1
    make sure that the gradle version in gradle-wrapper.properties file is 4.1 – Michael Nov 28 '17 at 07:25
  • like this distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip – Michael Nov 28 '17 at 07:26
  • My make project works fine but I am getting the following error.Earlier I was able to over come this error by changing few numbers in gradle settings but now I am unable to. What shall I do?Some one please help me as this is the only thing standing between my and my APK Error:Failed to complete Gradle execution. Cause: 'code' 'The version of Gradle you are using (3.3) does not support the forTasks() method on BuildActionExecuter. Support for this is available in Gradle 3.5 and all later versions.' – threewire Nov 29 '17 at 15:03
  • I now set it to 4.1 and it is now making the project but when I tried to build the APK I got the following error Error:Execution failed for task ':app:validateSigningDevRelease'. > Keystore file C:\.android\debug.keystore not found for signing config 'release'. – threewire Nov 29 '17 at 15:13
  • Worked now. After I set the keystore name, path and passwordand alias – threewire Nov 29 '17 at 15:39
  • Now it'll not work, Android Studio shows WARNING: The following project options are deprecated and have been removed: android.enableAapt2 This property has no effect, AAPT2 is now always used. Affected Modules: app, library – Ranjitsingh Chandel Feb 05 '19 at 15:39
0

Try to reinstall the android version you are using with standard settings. use stable version instead for your computer

Piyush raj
  • 19
  • 2