Android Studio - Failed to apply plugin [id 'c

2019-03-22 12:24发布

问题:

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')

}

回答1:

Updated July 22, 2018

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

Please make sure you are on the latest Android Studio 3.2 or above

Get Latest Gradle 4.9 from here

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

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

and gradle will update build tools which are causing the issue.

Note: If you are on Android Studio 2.3 or below please use

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



回答2:

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

It immediately shows at the left bottom:

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.



回答3:

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

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


回答4:

Delete gradle cache files. It can be in path like C:\Users\username\.gradle\caches for windows users. For Unix like sys it will be ~\.gradle\caches



回答5:

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.

My Problem solved this way.



回答6:

Solved it by setting gradle version 3.2.1

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

In Project level Gradle



回答7:

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.