android - 错误 :(19, 0) 找不到 Gradle DSL 方法: 'android()'

标签 android build.gradle

Android Studio 在编译项目时出现此错误。我搜索了一下,发现这可能是因为

android

阻塞在 build.gradle 的顶部。但在我的 build.gradle 中它可能不是问题所在。 这是我的 gradle 文件。

构建.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:1.1.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}
allprojects {
repositories {
    jcenter()
  }
}

android {
compileSdkVersion 19
}
dependencies {

应用程序.gradle

  apply plugin: 'com.android.application'

  android {
  compileSdkVersion 20
  buildToolsVersion "20.0.0"

    defaultConfig {
    applicationId "com.ptrprograms.chromecast"
    minSdkVersion 14
    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'])

compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.android.support:mediarouter-v7:19.0.+'
compile 'com.google.android.gms:play-services:6.1.11'

最佳答案

在应用该插件之前,您正在使用 Android 插件中定义的 Gradle 域特定语言 (DSL)。

删除

android {
compileSdkVersion 19
}

在您的顶级 build.gradle 中。您的应用程序 build.gradle 文件中已经有 compileSdkVersion 20,它确实很重要。

now its showing "Error:(16, 0) Gradle DSL method not found: 'runProguard()'

runProguard 前段时间在 Android Gradle 插件中被重命名为 minifyEnabled。您还应该在构建脚本中重命名它。

关于android - 错误 :(19, 0) 找不到 Gradle DSL 方法: 'android()',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29913502/

相关文章:

android - 改造异步调用和屏幕旋转

java - 如何通过 Android 应用程序与外部 SQL 数据库通信?

gradle - 使用 Gradle 将 Artifactory 上传到 Artifactory

Android 资源链接失败 AAPT : unknown option '--no-proguard-location-reference'

java - 使用 Gradle 构建 EAR,在 WAR 之间共享依赖关系

java - Android 6.0 Manifest.xml 中的 <uses-permission> 与 <permission>

java - 如何防止通过 AutoClose InputStream 关​​闭 InputStream

android - NetBeans+Android : after update i have error: build. xml:77: Android 目标未设置

jar - 如何从 gradle jar 任务中提取公共(public)代码到方法中

android - 更新 Android 项目中的 Gradle 依赖项