Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android flavors signing not working as expected

I need to sign a product flavor with an specific signing configuration. I found some reference here at stackoverflow like this and this. It is working for my release version of flavor, but not the debug one. I have this configuration in gradle:

...
signingConfigs {
    release {
        storeFile file("../config/keystores/release_keystore")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }

    debug {
        storeFile file("../config/keystores/debug.keystore")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }

    other {
        storeFile file("../config/keystores/other")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }
}

flavorDimensions "dim"

productFlavors {
    production {
        dimension "dim"
    }

    other {
        dimension "dim"
    }
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        
        productFlavors.other.signingConfig signingConfigs.other
        productFlavors.production.signingConfig signingConfigs.release
    }

    debug {
        productFlavors.other.signingConfig signingConfigs.other
        productFlavors.production.signingConfig signingConfigs.debug
    }
}

This works pretty well for the flavor otherRelease. But my APK is not being sigined with other signing configuration when I use the build configuration otherDebug. The release version was signed correctly.

Does anyone knows why in debug mode the signing configuration is not being applied as configured?

like image 750
Paulo Morandi Avatar asked Dec 28 '25 22:12

Paulo Morandi


1 Answers

I finally figured out what was wrong, thanks to @AllanHasegawa with his comment in another issue: Signing product flavors with gradle . For short, I had to add signingConfig null inside buildTypes because Android adds some default signing configuration. Even though I was trying to override it. Complete example based on my question:

...
signingConfigs {
    release {
        storeFile file("../config/keystores/release_keystore")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }

    debug {
        storeFile file("../config/keystores/debug.keystore")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }

    other {
        storeFile file("../config/keystores/other")
        storePassword "mysecurepassword"
        keyAlias "myultrasecurealias"
        keyPassword "myreallysecurekeypassword"
    }
}

flavorDimensions "dim"

productFlavors {
    production {
        dimension "dim"
    }

    other {
        dimension "dim"
    }
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        // this loop is a better implementation than my previous example
        productFlavors.all { flavor ->
                flavor.signingConfig signingConfigs.release
        }        
        productFlavors.other.signingConfig signingConfigs.other
    }

    debug {
        signingConfig null
        // this loop is a better implementation than my previous example
        productFlavors.all { flavor ->
                flavor.signingConfig signingConfigs.debug
        }
        productFlavors.other.signingConfig signingConfigs.other
    }
}
like image 120
Paulo Morandi Avatar answered Dec 31 '25 12:12

Paulo Morandi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!