Background:
I am generating builds using build variant. Below are the configurations:
signingConfigs {
production {
storeFile file("some_path/buildsystem/keystore/some.release.keystore.jks")
storePassword "somepassword"
keyAlias "somekeyalias"
keyPassword "some"
v2SigningEnabled false
}
develop {
storeFile file(".some_path./buildsystem/keystore/someother.debug.keystore.jks")
storePassword "someother"
keyAlias "someotherkeyalias"
keyPassword "someother"
v2SigningEnabled false
}
}
productFlavors {
production {
signingConfig signingConfigs.production
}
develop {
applicationIdSuffix ".develop"
signingConfig signingConfigs.develop
}
}
buildTypes {
debug {
minifyEnabled false
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
Problem
As, of now for example if I talk about flavour production
then productionRelease
uses signingConfigs.production
to sign the apk. But, productionDebug
doesn't uses signingConfigs.production
.
Expected output
When I generate the signed apk I want the gradle to do the following for me:
developRelease
and developDebug
should be signed with only signingConfigs.develop
productionRelease
and productionDebug
should be signed with only signingConfigs.production
Another question that is similar to this which led me to do the above: SHA-1 different for buildTypes (debug and release) for same productFlavors Firebase?
Remove the
signingConfig signingCongigs.develop
elsewhere in the code block
And add new property within the buildTypes like
Now add signingConfig
to it
Thereby your updated gradle file look like as below
signingConfigs {
production {
storeFile file("some_path/buildsystem/keystore/some.release.keystore.jks")
storePassword "somepassword"
keyAlias "somekeyalias"
keyPassword "some"
v2SigningEnabled false
}
develop {
storeFile file(".some_path./buildsystem/keystore/someother.debug.keystore.jks")
storePassword "someother"
keyAlias "someotherkeyalias"
keyPassword "someother"
v2SigningEnabled false
}
}
productFlavors {
production {
}
develop {
applicationIdSuffix ".develop"
}
}
buildTypes {
/* NOTE: the debug block is not required because it is a default
* buildType configuration; all of its settings are defined implicitly
* by Gradle behind the scenes.
*/
debug {
minifyEnabled false
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.production
}
withProduction {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.production
}
withDevelop {
minifyEnabled false
signingConfig signingConfigs.develop
debuggable true
}
}
In the terminal use the below gradle commmand:
gradle assembleProduction
to generate build with production certificates
similarly gradle assembleDevelop
or you can also use gradle assemble
You cannot force gradle to choose the certificates for debug
property rather you could create own buildTypes
As per documentation
Automate signing your applications. Debug build variants are, by default, signed with a debug key for installation on development devices. Declare additional signing configurations for publication to the Google Play store.
Update: As the other answer pointed out,
Add debuggable true property under custom buildTypes against which you want to debug build and see the logs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With