7

My modularized Android project makes use of subprojects in the root build.gradle in order to minimize the configuration needed in each submodule's build.gradle. For example I can use it to add our custom buildType to each module

subprojects 
    afterEvaluate { project ->

        if (project.plugins.findPlugin('android') ?: project.plugins.findPlugin('android-library')) {
            android {
                buildTypes {
                    qa {
                        initWith debug
                        matchingFallbacks = ['debug']
                    }
                }
            }
        }
    }
} 

My assumption was that if I also added this build config to a module level build.gradle that it would override the project level defined configuration. However, this does not seem to be the case.

If I add the following to my app/build.gradle my app ends up with the suffix 'dev' when the QA buildType is selected.

buildTypes {
        debug {
            applicationIdSuffix = ".dev"
            signingConfig signingConfigs.debug
        }

        qa {
            initWith debug
            applicationIdSuffix = ".qa"
            matchingFallbacks = ['debug']
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

    }

The same problem also applies when I try to use buildType specific buildConfigFields in modules; they're ignored.

How do I get the module's buildType declaration to override that defined in the parent project? I read the gradle docs and it suggested a syntax like android.buildTypes.qa{...}, however this results in an error due to "method" qa not being recognised.

aaronmarino
  • 3,723
  • 1
  • 23
  • 36

0 Answers0