【问题标题】:Android Studio: Plugin with id 'com.android.application' not foundAndroid Studio:未找到 ID 为“com.android.application”的插件
【发布时间】:2019-01-02 23:48:00
【问题描述】:

出乎意料,我收到了这个错误,我找不到解决方法。未找到 ID 为“com.android.application”的插件。如果你们还有其他需要查看的文件,请随时问我。谢谢!

它让我参考这个文件:

这是我的 build.gradle(Project OddJob):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.tamir.offen.actionbar"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    maven {
        url 'https://dl.bintray.com/spark/maven'
    }
}
configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-annotations:23.1.1'
    }
}

dependencies {
    implementation  fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation "com.google.android.gms:play-services-location:15.0.1"
    implementation 'com.android.support:support-v4:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'me.spark:submitbutton:1.0.1'
    implementation 'com.wdullaer:materialdatetimepicker:3.1.3'

// for the bottom nav bar:
implementation 'com.android.support:design:27.1.1'
}

这里是 build.gradle(Module App):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.tamir.offen.actionbar"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation  fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation "com.google.android.gms:play-services-location:15.0.1"
    implementation 'com.android.support:support-v4:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'me.spark:submitbutton:1.0.1'
    implementation 'com.wdullaer:materialdatetimepicker:3.1.3'

    // for the bottom nav bar:
    implementation 'com.android.support:design:27.1.1'
}

【问题讨论】:

    标签: java android android-studio android-gradle-plugin build.gradle


    【解决方案1】:

    Android Studio:未找到 ID 为 'com.android.application' 的插件

    • 您在顶级项目dependencies 中缺少classpath 'com.android.tools.build:gradle:3.1.3'

    • 检查顶级项目build.gradle

    build.gradle(Project OddJob):

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
    
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.3'
    
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
        }
    }
    
    //
    //task clean(type: Delete) {
    //    delete rootProject.buildDir
    //}
    

    【讨论】:

    • 我是否只是将其复制到 build.gradle(project) 中?
    • 我收到此错误:不允许在使用标准 Gradle 生命周期插件时声明自定义“清理”任务。还有你所说的“检查顶级项目 build.gradle”是什么意思
    • 只需删除干净的任务部分并重试,更新我的答案。
    • 感谢您的快速回放!我删除了清理任务部分并收到此错误:Cannot read packageName from C:\Users\tamir\Desktop\OddJob\src\main\AndroidManifest.xml
    • 尝试 Android Studio > 构建 > 清理项目。
    【解决方案2】:

    试试这个

    • 将以下代码添加到项目中 build.gradle 的顶部,如下所示:

      / Top-level build file where you can add configuration options common to all sub- 
        projects/modules.
      
        buildscript {
      
           repositories {
            google()
           jcenter()
         }
       dependencies {
      classpath 'com.android.tools.build:gradle:3.1.3'
      classpath 'com.google.gms:google-services:3.2.1'
      // NOTE: Do not place your application dependencies here; they belong
      // in the individual module build.gradle files
        }
        }
      
       allprojects {
        repositories {
      jcenter()
      google()
      }
       }
      
       task clean(type: Delete) {
       delete rootProject.buildDir
        }
      
    • 打开 gradle-wrapper.properties 并像这样添加 url:

           Wed May 30 16:36:49 IST 2018
           distributionBase=GRADLE_USER_HOME
           distributionPath=wrapper/dists
           zipStoreBase=GRADLE_USER_HOME
           zipStorePath=wrapper/dists
           distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip  //add this line in you project.
      

    对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-17
      • 1970-01-01
      • 2015-10-14
      • 2014-09-07
      相关资源
      最近更新 更多