How to add signing configs to Multi-FlavorDimensions (ProductFlavors)?

295 Views Asked by At

For example I have a gradle build as below:

signingConfigs {
        configFlavor1 {
        keyAlias 'alias1'
        keyPassword 'password1'
        storeFile file('location1')
        storePassword 'password1'
        v1SigningEnabled true
        v2SigningEnabled true
    }

    configFlavor2 {
        keyAlias 'alias2'
        keyPassword 'password2'
        storeFile file('location2')
        storePassword 'password2'
        v1SigningEnabled true
        v2SigningEnabled true
    }

    configFlavor3 {
        keyAlias 'alias3'
        keyPassword 'password3'
        storeFile file('location3')
        storePassword 'password3'
        v1SigningEnabled true
        v2SigningEnabled true
    }
}

flavorDimensions "dimen1", "dimen2"
productFlavors {
    flavor1 {
        dimension "dimen1"
    }
    flavor2 {
        dimension "dimen1"
    }
    testing {
        dimension "dimen2"
    }
    dev {
        dimension "dimen2"
    }
    prod {
        dimension "dimen2"
    }
}

now i want to use a signing config specific to a combination of this flavor dimension.. for example.. i would like to sign:

flavor1Prod with configFlavor1
flavor2Prod with configFlavor2
flavor1Dev with configFlavor3
etc...

I've tried something like this,

applicationVariants.all { variant ->
    def mergedFlavor = variant.mergedFlavor
    switch (variant.flavorName) {
        case "flavor1Prod":
            mergedFlavor.signingConfig = signingConfigs.configFlavor1
            break
        case "flavor2Prod":
            mergedFlavor.signingConfig = signingConfigs.configFlavor2
            break
        ... soo on...
    }
}

but still whenever i try to run, it still tries to generate an unsigned apk.

Can someone help me here?

0

There are 0 best solutions below