138

I am working on an app. In my app there is no error in code but when I try to run my project it gives following errors.

Error:(1, 1) A problem occurred evaluating project ':app'.

Failed to apply plugin [id 'com.android.application']

Could not create plugin of type 'AppPlugin'.

I try this also Gradle is issuing an error "Could not create plugin of type 'AppPlugin'"

and this also Gradle errors in Android Studio

Following is my build.gradle file

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {

    compileSdkVersion 23
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.praval.healthfreak"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'com.android.support:design:23.2.1'
    compile files('libs/YouTubeAndroidPlayerApi.jar')

}
Community
  • 1
  • 1
Praval Sharma
  • 1,921
  • 2
  • 14
  • 20

34 Answers34

126

Updated June 24, 2020

You need to update to the latest gradle version to solve this issue.

Please make sure you are on the latest Android Studio

and then update your project level build.gradle by updating this dependency

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

It might show a popup asking your permission to update gradle, please update and it will download the latest distribution automatically and the issue will be resolved.

Or else you can

Get Latest Gradle 5.6.4 from here and Add it manually

If you don't want to download it manually:

Open YourProject > gradle > wrapper > gradle-wrapper.properties and replace

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

With

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

Rebuild the project or just run gradle sync again.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
Atiq
  • 14,435
  • 6
  • 54
  • 69
  • Gradle 3.2: https://services.gradle.org/distributions/gradle-3.2-all.zip – odemolliens Nov 30 '16 at 10:43
  • 7
    Doesn't work for me. I also have low level exceptions like: IllegalStateException: Cache values are being processed. and at start he telling me: "Sync with Gradle for project 'android-app' failed: MALFORMED" – Archont Mar 24 '17 at 04:00
  • 3
    Where do we put the gradle folder that we downloaded and what do we name it? – user2602079 Sep 23 '17 at 01:59
  • 3
    Doesn't work for me too, I had to roll-back to gradle plugin 2.3.3 – Paolone Nov 03 '17 at 10:37
  • instead of apply plugin: 'com.android.application' instead add classpath dependency? – Thufir Nov 06 '17 at 03:28
  • go to file PATH: \platforms\android\cordova\lib\builers\projectBuilders.js. Look for line and update gradle to 5.6.4 : var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-5.6.4-all.zip'; – Pramod Kumar Sharma Jun 08 '20 at 17:13
  • I tried this as of Jun 5 2021 in a react-native app and it worked fine. Just changed the Gradle version number to the last one available and solved my problem. – Manuel Castillo Jun 05 '21 at 04:57
  • If this doesn't work, check this https://stackoverflow.com/a/66417992/5777189 There is a plugin version and a required gradle version, they need to match. – BabyishTank Aug 20 '21 at 16:40
  • changin version works for me - mine was 7.2bin.zip and I changed it to 7.2-all.zip, now it can download it. – aniran mohammadpour Apr 06 '22 at 22:02
  • In my case, im new to a big project. Downgrading gradle version matching all other coworkers, as you described solved my issue. – Muhammed Aydogan Jul 22 '22 at 10:46
13

I found the simplest answer to this.

Just go gradle.properties file and change the enableUnitTestBinaryResources from true to false

android.enableUnitTestBinaryResources=false

The snapshot is shown below

enter image description here

Tonnie
  • 4,865
  • 3
  • 34
  • 50
11

I faced the same issue in Android Studio version 3.5.3. This is how i fixed it.

I updated the dependecy com.android.tools.build:gradle in my project level build.gradle file from a lower version to 3.5.3 as below.

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

I then went ahead and edited the value of distributionUrl in gradle-wrapper.properties file as below. This file is in the directory /gradle/wrapper/ from the root of your project folder.

distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Nicodemus Ojwee
  • 744
  • 6
  • 12
  • 2
    Thanks, this helped solved it for me. Also needed to add google() to repos in build.gradle https://stackoverflow.com/a/57648844/3617528 – Tyeth Jul 29 '20 at 14:53
11

Feb 25th 2021:

For me, after over 8 hours of trials and errors, it was the re-ordering of the repositories sources in the project-level build.gradle file that solved the issue for me. So, instead of:

buildscript {
  ...
  repositories {
        google()
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
  }
  ...
}

I moved google() to the bottom:

buildscript {
  ...
  repositories {
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
        google()
  }
  ...
}

Of course, be sure to update the gradle android plugin and the matching gradle-wrapper distribution versions too.

Ugo
  • 587
  • 8
  • 12
6

Delete gradle cache files. It can be in path like C:\Users\username\.gradle\caches for Windows users. For UNIX based operating systems it will be ~/.gradle/caches.

Akito
  • 115
  • 2
  • 7
Cui Qing
  • 157
  • 2
  • 5
5

Just go to the gradle.properties file and change enableUnitTestBinaryResources from true to false

android.enableUnitTestBinaryResources=false
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
4

i fixed it by upgrade to gradle-5.6.4-all.zip in project\gradle\wrapper\gradle-wrapper.properties

#Wed Mar 11 15:20:29 WAT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

Mohamed Ben Romdhane
  • 1,005
  • 3
  • 11
  • 22
4

Android Gradle Plugin 7 requires Java 11. use short key Ctr+Alt+Shift+S or Go to File > Project Structure and change JDK location to Embedded JDK. enter image description here

kksal55
  • 500
  • 7
  • 14
3

Open the project on Android Studio and let it solve the problems for you

It immediately shows at the left bottom:

enter image description here

Then click that link, and it will fix the right files for you.

This ended up fixing the Gradle version as mentioned at: https://stackoverflow.com/a/37091489/895245 but it also fixed further errors, so it is the easiest thing to do.

Tested on https://github.com/googlesamples/android-vulkan-tutorials/tree/7ba478ac2e0d9006c9e2e261446003a4449b8aa3/tutorial05_triangle , Android Studio 2.3, Ubuntu 14.04.

Community
  • 1
  • 1
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
3

Error

Hello, I am Dipak, I faced this issue because I have downloaded and built a project on my PC, and it is on old java version 1.8, so when project building it will ask me to change the java version, and I have accepted that.

Here is the Solution, As you see my project need a java 11 version to build Gradle so,

  1. GoTo File -> Settings
  2. Build,Execution and Deployment -> Build Tools -> Gradle
  3. Change java version, Apply and click Ok.
  4. Sync build.gradle and run the project.

Solution

Boken
  • 4,825
  • 10
  • 32
  • 42
2

Solved it by setting gradle version 3.2.1

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

In Project level Gradle

Amine Messabhia
  • 357
  • 3
  • 14
2

On Mac Just Goto :

Android Studio -> Preference -> Gradle -> Gradle JDK -> Download JDK -> Ok

Here is screen

Yaqoob Bhatti
  • 1,271
  • 3
  • 14
  • 30
1

you just need to change your project.gradle file. And sync your Gradle.

dependencies {
 classpath 'com.android.tools.build:gradle:2.2.2'
}
umi
  • 157
  • 1
  • 6
1

As in Accepted post, the problem solved with updating gradle to 4.4.1.

  1. Get Latest Gradle 4.4.1 from here
  2. Extract and put it in "C:\Program Files\Android\Android Studio\gradle"
  3. Then from android studio go to "File -> Settings -> Build, Excecution, Deployment -> Gradle", from Project-level settings: Select Use local gradle Distribution and give the above
    address(folder with name "gradle-4.4.1" in "C:\Program Files\ ...")
  4. Then make project.

enter image description here

My Problem solved this way.

Mahdi Moqadasi
  • 2,029
  • 4
  • 26
  • 52
1

In my case, if your version of build tools in the build.gradle file in the root folder like :

classpath 'com.android.tools.build:gradle:3.x.x' <--- version of tools

is not supported by the Gradle installed in your project, you can check the build tools/plugin supported versions here, and make sure that the version installed in your project is supported by that version of Gradle.

You don't need to upgrade Gradle, you just check if it supports the plugin installed in your project or not.

Mihai Chelaru
  • 7,614
  • 14
  • 45
  • 51
1

When I had this problem was beacuse my directory had non ASCII characteres. Try changing it

1

First update the gradle to the latest version, if the issue still persists (in my case it did) then do the below- go to gradle.properties file and comment the line android.enableUnitTestBinaryResources=true

click on sync now.

it should solve the issue.

1

Try this simple and quick solution. Invalidating cache solved my problem. Just go to File>Invalidate Cache /Restart.

Yazdan Ilyas
  • 374
  • 4
  • 8
0

delete C:\Users\username\.gradle\caches folder.

Community
  • 1
  • 1
Reeonce Zeng
  • 392
  • 4
  • 14
0

My problem was I had czech characters (č,ú,ů,á,ó) in the project folder path.

Jan Málek
  • 531
  • 8
  • 21
0

I had the same issue and this is what I did and I was able to solve my issue:

  • I'm working with ShimmerAndroidAPI ( this library ) with Android Studio 3.6.1.
  • This worked well before I upgrade the Gradle and Android Studio to a new version using pop up upgrade suggestions appeared in android studio.
  • I followed the below steps as mentioned in this answer and I was able to make the project work.The steps I followed are as below.
  • Gradle file was updated from classpath 'com.android.tools.build:gradle:3.6.1' to

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

  • Then distribution URL in gradle-wrapper.properties file was updated from distributionUrl=https://services.gradle.org/distributions/gradle-5.6.4-all.zip to

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

  • Gradle was then synched.

Sachz
  • 391
  • 5
  • 21
  • 1
    Imagine reading your answer without having access to the links. Even if you have the link name (a/56...) do you think it would still mean anything? Can't you add at least the name of the stackoverflow question, and maybe its most important info that helped you? – B. Go Mar 17 '20 at 19:30
  • as @B.Go mentioned, link only answers are not considered high-quality. read [answer] for tips about improving your answer, and [edit] it. – JoSSte Mar 17 '20 at 19:34
  • I got it, thank you very much for suggestions. It really helps. I edited my answer with more information. – Sachz Mar 18 '20 at 14:05
0

Whenever you update your Gradle files do not forget to check the compatible Gradle wrapper distibutionUrl, in your case it happened because of the same.

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

Minion
  • 964
  • 14
  • 16
0

Inside my project there is a .gradle folder which had cached the previous gradle version I was using (5.4.1) and gradle kept using that instead of my newly downloaded one (5.6.4).

Simply:

  1. Close Android Studio
  2. Delete the older gradle version folders from your project.
  3. Restart Android Studio. Everything should be working correctly

In case this didn't work you can also try the following:

  • Delete all versions in project .gradle folder so only the new one is redownloaded by AS when reopening the IDE.
  • Check your project settings for gradle build version and make sure it is set to the latest one.
  • Check that other modules aren't using older versions of the gradle build. You can search for this using project search (Ctrl+Shift+F) for "distributionUrl" and making sure that all modules have the latest version.
  • Delete .gradle/caches under your root gradle folder, usually C://Users/{you}/.gradle
  • try gradle build --stacktrace, --info, --scan or --debug in your AS terminal to get help and more info to debug your problem.
RobC
  • 22,977
  • 20
  • 73
  • 80
Panos Gr
  • 667
  • 5
  • 13
0

In my case delete your gradle file and then again import your file again it will work

Aqif
  • 326
  • 3
  • 5
0

As of Android Gradle version above 7.0.0, Remove android.enableUnitTestBinaryResources from gradle.properties file

Karthick Ramanathan
  • 642
  • 3
  • 9
  • 20
0

One of the causes of the following error could be that exists an incompatibility with the configured version of the JVM in the project regarding the JDK location.

Error:

org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'com.android.application']

Caused by: java.lang.NoSuchMethodException: java.lang.invoke.MethodHandles.privateLookupIn(java.lang.Class, java.lang.invoke.MethodHandles$Lookup)
Caused by: java.util.concurrent.ExecutionException: java.lang.NoSuchMethodException: java.lang.invoke.MethodHandles.privateLookupIn(java.lang.Class, java.lang.invoke.MethodHandles$Lookup)
Caused by: java.lang.NoSuchMethodException: java.lang.invoke.MethodHandles.privateLookupIn(java.lang.Class, java.lang.invoke.MethodHandles$Lookup)

Workaround:

Note: For JVM version in compileOptions{} and kotlinOptions{}

  • For JVM version: JavaVersion.VERSION_1_8
  • Use JDK Location: /java-1.8.0-openjdk-amd64

  • For JVM version: JavaVersion.VERSION_11
  • Use JDK Location: /java-1.11.0-openjdk-amd64
Dharman
  • 30,962
  • 25
  • 85
  • 135
Braian Coronel
  • 22,105
  • 4
  • 57
  • 62
0

non of above solution not worked for me but this is worked for me just add in gradle.properties this line in android.overridePathCheck=true for more info : https://www.programmersought.com/article/59853994468/

The MJ
  • 453
  • 7
  • 17
0

I am facing same issue. But I am able to run app from Android Studio

  1. First, in a terminal/command-prompt, open Metro-Bundler, by running command: npm start from project folder (Ex: D:\AwesomeProject>npm start)
  2. Then in Android Studio, open ~/ProjectFolder/android (Ex: D:\AwesomeProject\android), and click Play icon (or press Shift+F10 for windows).

Note: This worked on Emulator only.

Sunny Jha
  • 101
  • 6
0

This answer is only valid if you cloned your project. For example. I had an app for USA only and wanted to clone it for other countries. I copied the project then renamed each project folder with country name. The names were already in excel so using copy-paste some projects gave me this error. When I sorted by name, I noticed the problematic ones were not in the correct alphabetical position.

So if this happened to you after cloning or renaming an existing project folder in file explorer (especially if you made names in excel and copy pasted) it introduces non-ascii characters.

  1. Close android studio
  2. Navigate to project location (in my case D://published apps/project name)
  3. right click and rename the project name without using paste, instead type it.
  4. When you open android studio again it should work, otherwise follow the other answers above.

TIP: It helps if you have multiple folders as you can sort by name and see project names that do not adhere to alphabetical order.

-1

First of all, before trying the most complicated things you should make the step easier, in my case this bug just happened on my way until the project contained 'spaces' for example:

Replace:

C://Users/Silva Neto/OneDrive/Work space/project

With:

C://Users/SilvaNeto/OneDrive/Workspace/project

Notice that we replaced spaces with camelCase but you can choose any naming scheme you like, and hopefully this could solve your issue.

I hope this will help.

Kosh
  • 6,140
  • 3
  • 36
  • 67
-1

Add the following to the top of your app/build.gradle file

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
phoenixstudio
  • 1,776
  • 1
  • 14
  • 19
-1
  1. flutter clean
  2. flutter run --debug
  3. flutter build apk --release

the debug will create the build gradle and building apk will work fine

-1

I changed the Gradle JDK version from 1.8 to 11 it's solve the issue for me.

Go to File>Settings>Build, Execution, Deployment>Build Tools>Grad

Now change Gradle JDK version from 1.8to 11

Hopefully this will solve your issue.

Raza
  • 57
  • 4
-2

In my case I'm using gradle version 7.0.3. It needed to add kotlin("android") in build.gradle.kts:

plugins {
    id("com.android.application")
    kotlin("android") //<---------- add this
   
}

Then you had to use JDK version 11 (download here) and add to android studio settings -> gradle and sync project

Erfan Eghterafi
  • 4,344
  • 1
  • 33
  • 44