【问题标题】:How you build a project using gradle?如何使用 gradle 构建项目?
【发布时间】:2014-07-07 06:20:16
【问题描述】:

下面给出了我的 build.gradle。我发现了这个错误。

Error:(15) A problem occurred evaluating root project 'smartwisher'.
> Could not find method android() for arguments [build_3rvo44ss7197kfip29gkh81rb6$_run_closure2@1d7a1869] on root project 'smartwisher'. 

这是我的 android studio 中的 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.12.+'
        }
    }
    allprojects {
        repositories {
            mavenCentral()
        }
    }
    android {
        compileSdkVersion 19
        buildToolsVersion '20.0.0'
        defaultConfig {}
        productFlavors {
        }
    }
    dependencies {
    }

【问题讨论】:

  • 你用的是什么gradle版本?
  • 不是,最新的是 1.12,我用的是 1.10。 1.11 给了我一些错误。检查安装 gradle 的文件夹的版本号
  • 哦,对不起,我使用的是 1.12

标签: android gradle android-gradle-plugin


【解决方案1】:

您不能使用顶级 build.gradle 来指定android 配置。

你必须移动你的module/build.gradle file.中的android块

您的文件夹。

root
  module
     build.gradle
  build.gradle
  settings.gradle

在您的顶级文件中:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}
allprojects {
    repositories {
        mavenCentral()
    }
}

在您的模块/build.gradle 中:

apply plugin: 'android'

android {

}

dependencies {
}

【讨论】:

    【解决方案2】:

    你的文件在这里不容易阅读,你应该把它放在一个代码块中。 对于我所看到的,您至少缺少一行:

    apply plugin: 'android'
    

    【讨论】:

    • 现在我得到了 fileNotFound 异常。 Error:Cause: java.io.FileNotFoundException: D:\smartwisher\src\main\AndroidManifest.xml (系统找不到指定的路径) D:\smartwisher\src\main\AndroidManifest.xml (系统找不到路径指定)
    【解决方案3】:

    你需要在build.gradle指定插件申请:

    apply plugin: 'android'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      • 2014-05-16
      • 2012-06-24
      • 1970-01-01
      • 1970-01-01
      • 2018-07-09
      相关资源
      最近更新 更多