bhadz bhadz - 6 months ago 30
Android Question

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. 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.

Same problem with the androidTestCompile, I get an error if I moved it to the global 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.



You may use the "apply" command in Gradle tool, like below :

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

In the common.gradle file, you may write the common setting, like


    Properties configs = new Properties()

    defaultConfig {

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

    packagingOptions {

then you may have a concise build.gradle.