Android studio构建脚本错误,不支持gradle DSL方法发现:android()!

时间:2014-06-11 12:58:13

标签: android-studio

我将Android Studio升级到AS 0.6,然后导入了在AS 0.3中开发的项目

我收到的错误如下:

Build script error,unsupported Gradle DSL method found : android()'!,

Possible causes could be:  

 - you are using Gradle version where the method is absent 
    ("open_gradle_settings">Fix Gradle settings</a>)

 - you didn't apply Gradle plugin which provides the method 
    (<a href="apply_gradle_plugin">Apply Gradle plugin</a>)

or there is a mistake in a build script (<a href="goto_source">Goto source</a>)

我将build.gradle中的依赖关系路径更改为:

dependencies {
    classpath 'com.android.tools.build:gradle:0.11.+'
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 14
}

可能出现什么问题?

是否有任何指南说明如何升级项目?

2 个答案:

答案 0 :(得分:2)

实际上它在错误消息中说明了。所以只需添加

apply plugin: 'com.android.application'

dependencies部分和android部分之间

答案 1 :(得分:-1)

将“Gradle DSL方法”视为Java方法。因此,在Gradle中,方法可以通过{}或“。”来区分。所以

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

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

其中“dependencies”和“compile”都是方法。

因此,您在build.gradle文件中的某个位置包含了一个程序不支持的方法。例如,将您的依赖项设为:

dependencies {
    nothing 'this.does.nothing.build:gradle:0.7.+'
}

与写作相同:

dependencies.nothing 'this.does.nothing.build:gradle:0.7.+'

你会看到一个错误,说“找不到支持的Gradle DSL方法:'没什么()'!” 显然,“没有”不是一个真正的方法。我刚刚完成了。

所以你的一个“android”方法是错误的。