无法修复“没有找到带有id'com.android.application'的插件”

时间:2017-02-20 22:27:35

标签: android android-studio gradle android-gradle

  

未找到ID“com.android.application”的插件

这是我每次同步项目时得到的错误。

项目级别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.2.3'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'io.realm:realm-gradle-plugin:2.3.1'

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

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app level gradle文件

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'realm-android'

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

//    packagingOptions {
//        exclude 'META-INF/INDEX.LIST'
//        exclude 'META-INF/DEPENDENCIES'
//        exclude 'META-INF/LICENSE'
//        exclude 'META-INF/spring.handlers'
//        exclude 'META-INF/spring.schemas'
//        exclude 'META-INF/cxf/bus-extensions.txt'
//    }

    android {
        lintOptions {
            abortOnError false
        }
    }

}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    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:25.1.1'
    compile 'com.android.support:design:25.1.1'
    compile 'com.android.support:support-v4:25.1.1'
    compile 'com.android.support:cardview-v7:25.1.1'
    compile 'com.android.support:recyclerview-v7:25.1.1'
    compile 'com.jakewharton:butterknife:8.5.1'
    compile 'jp.wasabeef:recyclerview-animators:2.2.4'
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'commons-io:commons-io:2.5'
    compile 'io.reactivex:rxjava:1.2.4'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'io.realm:android-adapters:1.4.1'
    compile 'com.squareup.okhttp:okhttp:2.7.5'
    testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
    testCompile 'junit:junit:4.12'
    apt 'com.jakewharton:butterknife-compiler:8.5.1'
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
    compile project(':poishadow-all')
}

修复它的效果

  1. 尝试this popular answer

  2. 尝试过的文件>使高速缓存无效/重新启动

  3. 复制另一个项目应用和项目级别build.gradle文件

  4. 观察

    如果我删除apply plugin: 'com.android.application并同步,则错误变为

      

    找不到ID'android-apt'的插件

    如果我也删除Plugin with id 'android-apt' not found,则错误变为

      

    '找不到id realm-android'的插件。

    修改 我跑了./gradlew build --stacktrace,我得到了这个:

    * Exception is:
    org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'app'.
            at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:92)
            at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$2.run(DefaultScriptPluginFactory.java:176)
            at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:77)
            at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:181)
            at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:39)
            at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
            at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
            at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:70)
            at org.gradle.configuration.project.LifecycleProjectEvaluator.access$000(LifecycleProjectEvaluator.java:33)
            at org.gradle.configuration.project.LifecycleProjectEvaluator$1.execute(LifecycleProjectEvaluator.java:53)
            at org.gradle.configuration.project.LifecycleProjectEvaluator$1.execute(LifecycleProjectEvaluator.java:50)
            at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
            at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
            at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
            at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:50)
            at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:628)
            at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:129)
            at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:35)
            at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:60)
            at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
            at org.gradle.initialization.DefaultGradleLauncher$1.execute(DefaultGradleLauncher.java:161)
            at org.gradle.initialization.DefaultGradleLauncher$1.execute(DefaultGradleLauncher.java:158)
            at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
            at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
            at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
            at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:158)
            at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
            at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
            at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
            at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
            at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
            at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
            at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
            at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
            at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
            at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
            at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
            at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
            at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
            at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
            at org.gradle.util.Swapper.swap(Swapper.java:38)
            at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
            at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
            at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
            at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
            at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
            at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
            at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
            at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
    Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with id 'com.android.application' not found.
            at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:110)
            at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyType(DefaultObjectConfigurationAction.java:113)
            at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:36)
            at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:80)
            at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:136)
            at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:44)
            at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.java:34)
            at org.gradle.api.Script$apply.callCurrent(Unknown Source)
            at build_adp866r1t6j1hlthh3am8fjsj.run(/home/ozuf/Android/Projects/appname/app/build.gradle:1)
            at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:90)
            ... 62 more
    
    
    BUILD FAILED
    
    Total time: 2.29 secs
    

3 个答案:

答案 0 :(得分:1)

我假设你在subProject文件夹中运行gradle build并且你自己创建了subProject。你在settigns.gradle中添加了subProject吗?

include 'project-name', 'another-project'

这应该在根项目settings.gradle中。

答案 1 :(得分:0)

我真的不知道出了什么问题但是由于其他项目没有任何问题(包括新项目),我创建了另一个具有相同包名称的项目并手动处理了 main 文件夹(PROJECT_NAME / app / src / main)并将其替换为新项目的文件夹,并且有效。

如果遇到类似问题,旧项目和新项目不应位于同一文件夹中。这非常重要。

答案 2 :(得分:0)

当我不小心删除build.gradle时,我已经看到了这种情况。