Android Studio:找不到ID为“ com.android.application”的插件

时间:2018-07-26 04:34:18

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

突然出现此错误,我找不到解决方法。找不到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(模块应用程序):

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

2 个答案:

答案 0 :(得分:1)

  

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

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

  • 检查顶级项目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
//}

答案 1 :(得分:0)

尝试一下

  • 将以下代码添加到项目中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并添加如下网址:

         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.
    

它可以帮助您