【问题标题】:Could not find method android() in root of multimodule project在多模块项目的根目录中找不到方法 android()
【发布时间】:2014-07-14 20:52:35
【问题描述】:

尝试为一组 Android 项目添加并行构建时

对于root build.gradle 我添加了from template

subprojects {
    android{
        //{ for classic Android Eclipse project
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                aidl.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']
            }

            // Move the tests to tests/java, tests/res, etc...
            androidTest.setRoot('tests')

            // Move the build types to build-types/<type>
            // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
            // This moves them out of them default location under src/<type>/... which would
            // conflict with src/ being used by the main source set.
            // Adding new build types or product flavors should be accompanied
            // by a similar customization.
            debug.setRoot('build-types/debug')
            release.setRoot('build-types/release')
        }
        //}
    }
}

但出现错误Could not find method android() ...

14:14:57.016 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
14:14:57.016 [ERROR] [org.gradle.BuildExceptionReporter]
14:14:57.017 [ERROR] [org.gradle.BuildExceptionReporter] * Where:
14:14:57.017 [ERROR] [org.gradle.BuildExceptionReporter] Build file 'D:\Workspaces\ws\project\src\build.gradle' line: 21
14:14:57.017 [ERROR] [org.gradle.BuildExceptionReporter]
14:14:57.017 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
14:14:57.018 [ERROR] [org.gradle.BuildExceptionReporter] A problem occurred evaluating root project 'src'.
14:14:57.018 [ERROR] [org.gradle.BuildExceptionReporter] > Could not find method android() for arguments [build_rp8mi2jisvr8vhjtgpkks742o$_run_closure1_closure2@6f762bb] on root project 'src'.
14:14:57.018 [ERROR] [org.gradle.BuildExceptionReporter]

我必须在每个模块中复制粘贴这样的配置吗?
有没有办法从一个根 build.gradle 配置一组 android 项目?

类似于Could not find property 'android' on root project 没有根级别的代码。

使用过的版本:

>gradle -v

------------------------------------------------------------
Gradle 1.10
------------------------------------------------------------

Build time:   2013-12-17 09:28:15 UTC
Build number: none
Revision:     36ced393628875ff15575fa03d16c1349ffe8bb6

Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy:          2.2.0
JVM:          1.8.0_05 (Oracle Corporation 25.5-b02)
OS:           Windows 7 6.1 amd64

【问题讨论】:

    标签: android build gradle multi-module


    【解决方案1】:

    您首先需要在subprojects 中应用android 插件。

    【讨论】:

    • 能否分享一下添加android插件的过程
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-06
    • 2019-01-20
    • 2012-01-21
    • 2013-05-21
    • 2017-04-27
    • 1970-01-01
    相关资源
    最近更新 更多