简体   繁体   English

项目级或全局build.gradle中的公共gradle配置

[英]Common gradle config in project-level or global build.gradle

I have a project that has multiple modules in it, and each of those modules has a signingConfig that is the same to all modules. 我有一个项目,其中包含多个模块,每个模块都有一个与所有模块相同的signingConfig。 I want to move that singingConfig to the global gradle which is located at the root of the project to get rid of the redundancy of that config. 我想将singConfig移动到位于项目根目录的全局gradle中,以摆脱该配置的冗余。

Same problem with the androidTestCompile, I get an error if I moved it to the global build.gradle. 与androidTestCompile相同的问题,如果我将它移动到全局build.gradle,我会收到错误。 Does anyone have experience on how to move it to the global gradle? 有没有人有关于如何将其移至全球平台的经验?

btw, there are reasons why I always signed my app in every module, one is for the unit and instrumentation test, since testing will only cover that particular module and others. 顺便说一下,有理由说我总是在每个模块中签署我的应用程序,一个用于单元和仪器测试,因为测试将仅涵盖该特定模块和其他模块。

Thanks. 谢谢。

You may use the "apply" command in Gradle tool, like below : 您可以在Gradle工具中使用“apply”命令,如下所示:

apply from: "${rootDir}/config/common.gradle"

In the common.gradle file, you may write the common setting, like 在common.gradle文件中,您可以编写常用设置,例如

android{

    Properties configs = new Properties()
    ....

    defaultConfig {
       ... 
    }

    buildTypes {
        sourceSets {
            main {
                aidl.srcDirs = ['src/main/java']
            }
        }
    }

    packagingOptions {
          ...
    }
}

then you may have a concise build.gradle. 那么你可能有一个简洁的build.gradle。

The file structure looks like below : 文件结构如下所示:

rootDir
 |
 |-- config
 |      | -- common.gradle
 |      | -- util.gradle
 |
 |-- moduleA
 |      | -- build.gradle
 |      | -- src
 |
 |-- moduleB
 |      | -- build.gradle
 |      | -- src
 ...
 |
 |-- settings.gradle
 |-- build.gradle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM