The Gradle Plugin User Guide says that you can:
have each release package use their own
SigningConfigby setting each
android.productFlavors.*.signingConfigobjects separately.
This is demonstrated in this answer (Debug Signing Config on Gradle Product Flavors) and this blog post (Building Multiple Editions of an Android App with Gradle).
However, specifying a separate signingConfig line for each flavor does not scale well, and was out of scope of the question. Unfortunately none of the provided answers showed how to correctly override a signingConfig correctly.
The trick came from this answer (How to get the currently chose build variant in gradle?) which shows how to loop over build variants (and by extension, flavors).
My solution uses a loop to set the signingConfig on each flavor instead of having a separate line for that. This scales perfectly well. The “override” is done with a single line that specifies the custom config after the loop.
Place the following code inside the buildTypes.release block:
// loop over all flavors to set default signing config
productFlavors.all { flavor ->
flavor.signingConfig signingConfigs.releaseConfig
}
// override default for single custom flavor
productFlavors.custom.signingConfig signingConfigs.custom