343

This is my first attempt at Android Studio. I installed 0.8.0 and updated to 0.8.2. As soon as a project is created I get the error message:

Error:(1, 0) Plugin with id 'com.android.application' not found

C:\Users\Bob\AndroidStudioProjects\HelloAgain6\app\build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.example.bob.helloagain6"
        minSdkVersion 15
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

and C:\Users\Bob\AndroidStudioProjects\HelloAgain6\build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

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

allprojects {
    repositories {
        jcenter()
    }
}
Ovidiu Uşvat
  • 701
  • 1
  • 6
  • 29
Bob Kusik
  • 3,439
  • 2
  • 12
  • 3
  • 2
    I got this problem, but suddenly I see the top level `build.gradle` was deleted :), so I copy it from `git` repository and every things goes right – Mehdi Khademloo Oct 07 '16 at 20:11
  • Same thing for me, my build.gradle for project level was moved into the same folder as the wrapper properties during a funky merge so it wasn't finding it at the root where it should be – RESTfulGeoffrey May 08 '20 at 11:52
  • for #FLUTTER projects the solution was to run `./gradlew wrapper` in the `android` directory – Ovidiu Uşvat Jan 26 '23 at 11:45

25 Answers25

491

Updated Answer (Dec. 2, 2020)

Latest Gradle: 6.5

Version check:

  • ./gradlew -v

How to update:

  • Set URL: ./gradlew wrapper --gradle-version=6.5 --distribution-type=all
  • Update: ./gradlew wrapper

Latest Android Gradle Plugin: 4.1.0

If you add the following code snippet to the top of your build.gradle file. Gradle will update the build tools.

buildscript {
    repositories {
        google() // For Gradle 4.0+
        maven { url 'https://maven.google.com' } // For Gradle < 4.0
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
    }
}

Read more here: https://developer.android.com/studio/build/index.html and about version compatibility here: https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle and https://dl.google.com/dl/android/maven2/index.html.

Original Answer

I had this same error, you need to make sure your Gradle version is compatible with your Android Gradle Plugin.

The latest version of Gradle is 2.0 but you need to use 1.12 in order to use the Android Gradle Plugin.

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • 188
    +1 for still updating your answer a few months later – P1nGu1n Oct 30 '14 at 21:17
  • 4
    @P1nGu1n No problem! It is easier if every sees the most up-to-date information. – Jared Burrows Oct 30 '14 at 21:20
  • Could you please explain what that code snippet ist for? – Gerome Bochmann Dec 11 '14 at 17:26
  • @strom Explain what code snippet? This question was simply upgrading the android gradle dependency. – Jared Burrows Dec 11 '14 at 17:37
  • Like that. Being a complete Android/Gradle newbie I was confused by the code you posted. There was no explanation as to where I'm supposed to use it or what it does. – Gerome Bochmann Dec 13 '14 at 12:34
  • You should always start with the Android docs, such as the link I provided. – Jared Burrows Dec 13 '14 at 18:20
  • @JaredBurrows: Thanks a lot! This solution is working very well. I just get confused by adding these lines on top... – Martin Pfeffer Dec 28 '14 at 09:52
  • 4
    @MartinPfeffer No problem. I will continue to keep this updated! – Jared Burrows Dec 28 '14 at 16:51
  • 13
    Good answer, though I can't help but wonder why Google would deploy Android Studio like this.. This error is the first thing you see when starting a new project. I mean, what were they thinking!? – BdR Mar 27 '15 at 14:04
  • 1
    @BdR Very good question. I think Google releases everything in "beta" and does not really test their own software like you would think. They let us create questions on StackOverflow and send in crash reports in order to test their products out. However, all the Android tools are *FREE* and most are open source vs Apple's closed source and yearly subscription. – Jared Burrows Mar 27 '15 at 14:14
  • @JPM I totally agree the error messages are not helpful. Can you post a question and I might be able to help? Or did this answer help you? – Jared Burrows Apr 10 '15 at 21:05
  • This is the right idea but the formatting of the repositories declaration is no longer valid. 'repositories' now needs to be a root element of build.gradle instead of appearing inside of buildscript{}. See: http://stackoverflow.com/a/20574180/10505 – greg7gkb Dec 07 '15 at 18:03
  • @greg7gkb Your statement is only half correct. The `buildscript` lists the repositories for the project usually for plugins. You can specify `repositories` separately for dependencies. – Jared Burrows Dec 08 '15 at 05:07
  • Some information on Gradle Plugin and Gradle compatibiltiy [here](http://tools.android.com/tech-docs/new-build-system/version-compatibility) – iuq Dec 14 '15 at 12:42
  • what should I change on my android studio? to make it work? – Ryan May 22 '16 at 05:22
  • 16
    Android development has many stupid things. Why we should be bothered with all this gradle versions thing – user25 Aug 06 '16 at 13:28
  • When I try to do "./gradlew wrapper --gradle-distribution-url..." as you posted, I get this familiar error in the terminal: * What went wrong: A problem occurred evaluating root project 'OneTwoThree > Plugin with id 'com.android.application' not found. Any suggestions? – Mike Miller Sep 07 '17 at 17:40
  • I have no idea what `OneTwoThree > Plugin` is but I just tested this out again and it works. It is from gradle themselves: https://github.com/gradle/gradle/releases/tag/v4.1.0. – Jared Burrows Sep 07 '17 at 20:21
  • I first had to locate `gradlew` buried deep in `android-studio`. Then I had to set its executable bit. That can't be right, but running the command succeeded! – Tom Russell Aug 08 '18 at 08:39
  • I also had to do File > Invalidate Cache and Restart – Yohan D May 28 '20 at 05:53
  • @JaredBurrows I have this problem in my gitlab runner. when run gradle with cmd there is no problem, but when run gradle with powershell it's reporting the error in this question. do you have any idea? – MHSaffari Jan 20 '21 at 11:40
  • Just got this error on current working project. I didn't think to that, but it turns out it was my new anti-virus and firewall i freshly installed... –  Feb 10 '21 at 12:15
  • for #FLUTTER projects: was enough to run `./gradlew wrapper` in the android directory – Ovidiu Uşvat Jan 26 '23 at 11:43
37

This can happen if you miss adding the Top-level build file.

Just add build.gradle to top level.

It should look like this

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.xx.y'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

Ash
  • 1,391
  • 15
  • 20
14

In my case, I download the project from GitHub and the Gradle file was missing. So I just create a new project with success build. Then copy-paste the Gradle missing file. And re-build the project is working for me.

enter image description here

Md Imran Choudhury
  • 9,343
  • 4
  • 62
  • 60
  • this solved my problem after several hours of trying other methods – zyz82 Oct 23 '19 at 21:34
  • copy the file from where. I also have a missing gradle file, but in my case, its the one in the app directory – nyxee Oct 23 '20 at 11:59
5

Root-gradle file:

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

allprojects {
    repositories {
        jcenter()
    }
}

Gradle-wrapper.properties file:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-x.x-all.zip
Henadzi Rabkin
  • 6,834
  • 3
  • 32
  • 39
3

In the project level build.gradle file, I have replaced this line

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

with this one

classpath 'com.google.gms:google-services:4.3.3'

After adding both of those lines, and syncing, everything became fine. Hope this will help someone.

codersaif
  • 946
  • 9
  • 15
2

I am writing this not as a solution meant for many, but for some people who may commit a simple mistake like specifying the wrong url for importing projects from SVN. It is intended for those guys :)

This happened to me when I imported the project from SVN -> automatic prompt by Studio to open the project -> It asked for Gradle location -> D:\Software\Android\gradle-2.5 -> Then the error.

The same project in a different SVN branch works fine with the Gradle plugin and Gradle which I have configured in Studio. I tried changing Android Gradle plugin and Gradle to get it working on the erring branch without any success.

Finally, I figured out that it was my following mistake: I tried importing a specific Application alone instead of importing the application along with dependent library projects. The url which I used for import initially had the Application porject's name at the end. Once I removed it, and specified the parent directory which contained both application project and its dependent project, everything went smooth :)

garnet
  • 551
  • 5
  • 12
2

I found the problem after one hour struggling with this error message:

I accidentally renamed the root build.gradle to filename in builde.gradle, so Android Studio didn't recognize it anymore.

Renaming it to build.gradle resolved the issue!

David Rawson
  • 20,912
  • 7
  • 88
  • 124
Lorenzo Barbagli
  • 1,241
  • 2
  • 16
  • 34
2

I still got the error

 Could not find com.android.tools.build:gradle:3.0.0.

Problem: jcenter() did not have the required libs

Solution: add google() as repo

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {

        classpath "com.android.tools.build:gradle:3.0.0"
    }
}
Simon Fakir
  • 1,712
  • 19
  • 20
1

I was using IntelliJ IDEA 13.1.5 and faced with the same problem after I changed versions of Picasso and Retrofit in dependencies in build.gradle file. I tried use many solutions, but without result. Then I cloned my project from remote git (where I pushed it before changing versions of dependencies) and it worked! After that I just closed current project and imported old project from Gradle file to IntelliJ IDEA again and it worked too! So, I think it was strange bug in intersection of IDEA, Gradle and Android plugin. I hope this information can be useful for IDEA-users or anyone else.

John Smith
  • 605
  • 4
  • 14
1

Go to your grade file where you can see this:

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


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

And change classpath to this:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
//        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.android.tools.build:gradle-experimental:0.7.0-alpha1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
Volodymyr Kulyk
  • 6,455
  • 3
  • 36
  • 63
  • No. `gradle-experimental` is "experimental". This has nothing to do with the question. – Jared Burrows May 22 '16 at 14:09
  • @JaredBurrows The error in OP's question can happen with gradle-experimental as well. It is happening to me today. However, VladimirKulyk should know that using gradle-experimental is only recommended for NDK builds. – IgorGanapolsky Jul 28 '16 at 21:35
1

Make sure your two build.gradle and settings.gradle files are in the correct directories as stated in https://developer.android.com/studio/build/index.html

Then open "as existing project" in Visual Studio

Gradle is very finicky about this.

1

The other answers didn't work for me, I guess something wrong happens between ButterKnife and 3.0.0 alpha5.

However, I found that when I annotated any one sentence, either BUtterKnife or 3.0.0 alpha5, it works normally.

So, you should just avoid the duplication or conflict.

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
Lancer.Yan
  • 857
  • 13
  • 10
1

For future reference: For me, this issue was solely caused by the fact that I wasn't running Android Studio as administrator. I had the shortcut on Windows configured to always run as administrator, but after reinstalling Android Studio, the shortcut was replaced, and so it ran without administrator rights. This caused a lot of opaque errors, including the one in this question.

Wouter Florijn
  • 2,711
  • 2
  • 23
  • 38
1

This issue happened when I accidently renamed the line

apply plugin: 'com.android.application'

on file app/build.gradle to some other name. So, I fixed it by changing it to what it was.

Nathan Getachew
  • 783
  • 5
  • 16
1

[FOR FLUTTER] go to your build Gradle then check if you have three paths

dependencies {
    classpath 'com.android.tools.build:gradle:3.5.0'
    classpath 'com.google.gms:google-services:4.3.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

I somehow removed the android tools classpath and was getting the error.

A v o c a d o
  • 526
  • 4
  • 3
0

This just happened to me using Android Studio 1.3.2, however, since I had just created the project, I deleted it and created it again.
It seems that it had not been properly created by Android Studio the first time, not even the project folders where as expected.

Edison Spencer
  • 491
  • 1
  • 9
  • 24
0

If you run a the module task with android plugin 1.2.3 in module directory , the problem appears. Try this:

../gradlew -b ../build.gradle  -c ../settings.gradle  :module:xxx
Victor Choy
  • 4,006
  • 28
  • 35
0

I got this error message after making the following change in my top-level build.gradle to update to the latest version of gradle:

//classpath 'com.android.tools.build:gradle:2.3.2' old
classpath 'com.android.tools.build:gradle:2.3.3' //new

I foolishly made the change while I was connected behind a hostile workplace proxy. The proxy caused the .jar files for the new version of gradle to become corrupt. This can be verified by inspecting the jars to see if they are an unusual size or whether they can be unzipped.

In order to fix the mistake, I connected to my network at home (which is not behind a proxy) and did a refresh dependencies from the Terminal:

./gradlew --refresh-dependencies

This caused the newer version of gradle to be re-downloaded and the error no longer occurs.

David Rawson
  • 20,912
  • 7
  • 88
  • 124
0

Check the spelling, mine was 'com.android.aplication'

Amir Dora.
  • 2,831
  • 4
  • 40
  • 61
k4dima
  • 6,070
  • 5
  • 41
  • 39
0

This may also happen when you have both settings.gradle and settings.gradle.kts files are present in project root directory (possibly with the same module included). You should only have one of these files.

Igor
  • 2,039
  • 23
  • 27
  • Correct. This happened to me when I imported my project directly with build.gradle, found duplicate Gradle and properties file – Okikioluwa Jan 03 '20 at 01:03
0

i had similar problem and i did following things to resolve it. i referred to https://developer.android.com/studio/build and copy / pasted these following lines before apply plugin lines

repositories {
    google()
    jcenter()
}

dependencies {
    classpath 'com.android.tools.build:gradle:4.0.0'
}

}

-1

module app build.gradle file

apply plugin: 'com.android.application'

model{


    android {
        compileSdkVersion 23
        buildToolsVersion  "23.0.2"

        defaultConfig.with {
            applicationId "com.iamsafe"
            minSdkVersion 15
            targetSdkVersion 23





        }
     buildTypes {
            debug {
                minifyEnabled = false
                useProguard = true
                proguardFiles.add(file('proguard-rules.txt'))


            }
        }



    }

}



dependencies {
    compile 'com.android.support:support-v4:23.0.2'
    compile files('libs/asmack-android-8-0.8.10.jar')
    compile files('libs/commons-io-2.0.1.jar')
    compile files('libs/httpclient-osgi-4.2.1-sources.jar')
    compile files('libs/httpcore-4.3.2.jar')
    compile files('libs/httpmime-4.1.2.jar')
}


project build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.10'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
Mansuu....
  • 1,206
  • 14
  • 27
-1

In this case of issues check below code

dependencies {
    classpath 'com.android.tools.build:gradle:**1.5.0**'
}

and gradle-wrapper.properties inside your project directory check below disctributionUrl:

distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip

If these are not compatible with each other then you end up in this issue.

For com.android.tools.build:gradle:1.5. you need a version at least 2.8 but if you switch to a higher version like com.android.tools.build:gradle:2.1.0 then you need to update your gradle to 2.9 and above this can be done by changing distributionUrl in gradle-wrapper.properties to 2.9 or higher as below

distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
David Rawson
  • 20,912
  • 7
  • 88
  • 124
maruti060385
  • 707
  • 8
  • 11
-1

If you work on Windows , you must start Android Studio name by Administrator. It solved my problem

Тони
  • 129
  • 9
-3

Just make sure you put the http and https proxy correctly when you create the app