这是我第一次尝试使用Android Studio。我安装了0.8.0并更新到0.8.2。只要一个项目被创建,我就会得到错误消息:

错误:(1,0)插件id 'com.android。未找到应用程序

C:\Users\Bob\ AndroidStudioProjects \ HelloAgain6 \ app \ build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.example.bob.helloagain6"
        minSdkVersion 15
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

和C:\Users\Bob\ AndroidStudioProjects \ HelloAgain6 \ 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:0.12.+'

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

allprojects {
    repositories {
        jcenter()
    }
}

当前回答

如果您错过添加顶级构建文件,就会发生这种情况。

只需添加构建。Gradle到顶级。

应该是这样的

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.xx.y'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

其他回答

在这种情况下,检查下面的代码

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

和gradle-wrapper。properties在你的项目目录检查下面distributionurl:

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

如果它们彼此不兼容,那么你就会陷入这个问题。

com.android.tools.build: gradle: 1.5。你需要至少2.8的版本,但如果你切换到更高的版本,如com.android.tools.build:gradle:2.1.0,那么你需要将你的gradle更新到2.9,这可以通过在gradle-wrapper中更改distributionUrl来完成。属性为2.9或更高,如下所示

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

这也可能发生时,您有两个设置。Gradle和settings.gradle.kts文件在项目根目录中(可能包含相同的模块)。您应该只有其中一个文件。

作为将来的参考:对我来说,这个问题完全是由于我没有作为管理员运行Android Studio而引起的。我在Windows上将快捷方式配置为始终以管理员身份运行,但在重新安装Android Studio后,快捷方式被替换了,因此它在没有管理员权限的情况下运行。这导致了很多不透明的错误,包括这个问题中的错误。

打开你的成绩档案,你可以看到:

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


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

并将类路径更改为:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
//        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.android.tools.build:gradle-experimental:0.7.0-alpha1'

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

如果你在模块目录下运行android插件1.2.3的模块任务,就会出现这个问题。试试这个:

../gradlew -b ../build.gradle  -c ../settings.gradle  :module:xxx