Android Studio 0.4.6上的gradle错误

时间:2014-02-28 17:59:15

标签: android-studio

Hello StackOverflow
我最近将我的Android Studio更新到最新版本(0.4.6),我遇到了奇怪的问题。首次创建项目时,我收到此错误:

Image1

所以我显然去了我的SDK Manager并将我的Build Tools更新到版本19.0.2。但是,我仍然收到此错误消息。我查看了我的build.gradle文件,看到我错过了android段落,所以我改变了它:

// 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.8.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

对此:

// 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.8.+'
    }
}

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.2'

    //Other Configuration
}

allprojects {
    repositories {
        mavenCentral()
    }
}

但是现在我在尝试构建时遇到此错误消息(以及较旧的Build Tools错误):

Image2

我不知道现在该怎么办..我怎么解决这个问题?

2 个答案:

答案 0 :(得分:2)

根据Scott的建议,保留您的根级别 build.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.8.+'
    }
}

allprojects {

        repositories {
            mavenCentral()
        }
    } 

此文件的内容将包含在Gradle同步或编译类型的每个模块级build.gradle文件中。

检查模块中的所有 build.gradle 文件。它们都应该与此类似

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.2'

    //Other Configuration
}



dependencies{
  // Your all module dependencies here
}

答案 1 :(得分:0)

撤消对顶级构建文件所做的更改,并对单个模块中的构建文件进行更改。特别是,以这种方式在您的顶级构建文件中放置apply plugin: 'android'语句或android块将不起作用。您看到的错误消息正在发生,因为构建系统正在尝试从项目的根目录构建Android应用程序,但此类项目的源文件都不存在。