Multiple signingConfigs based on flavor and buildType

2,734 views
Skip to first unread message

Aditya Gore

unread,
Nov 26, 2014, 2:45:41 PM11/26/14
to adt...@googlegroups.com
I have an app that has several flavors: A, B, B1..Bn

The release buildType for Flavor A needs to be signed using one signingConfig and the release buildType for all "B" flavors need a second signingConfig. However I want all debug buildTypes to be unsigned or signed with the default debug key. The closest I got was to define a default signingConfig for the release buildType and then override that in the "A" productFlavor. But that causes both release and debug buildTypes for A to get the "A" signingConfig, which I don't want. I tried 
applicationVariants.find {it.name == "ARelease"}.signingConfig = signingConfigs.ARelease, but turns out that's a read-only property in the applicationVariants.* closure.  

Any pointers? Thanks much.

My build.gradle (summarized) :

android {
...
signingConfigs {
releaseA {
...
}
releaseB {
...
}
}
buildTypes {
release {
signingConfigs signingConfigs.releaseB
}
}
productFlavors {
A {
signingConfig signingConfigs.releaseA
}
B1 {
}
...
Bn {
}
}
}

Xavier Ducrohet

unread,
Dec 2, 2014, 2:31:15 PM12/2/14
to adt...@googlegroups.com
Dont set a signingconfig on the release build-type, it'll override the signing config set in the flavor (this is how the debug signing config works).

If you really have a lot of B* flavors, I would try to do something like this after you create the flavors/signingconfigs:

for (int i = 0 ; i < n ; i++) {
  android.produtFlavors.getByName("B${i}").signingConfig = android.signingConfigs.getByName("releaseB${i}")
}




--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Aditya Gore

unread,
Dec 4, 2014, 3:16:26 PM12/4/14
to adt...@googlegroups.com
Thank you for responding. But this will give both debug and release versions of the B* flavors the same signing config. I am looking for a way to differentiate between those. If I print a productFlavor object I don't see anything in there (at least in the toString() value) that indicates the BuildType. I went and looked at the source code for the Android plugin but nothing looked promising. Any pointers?

Xavier Ducrohet

unread,
Dec 4, 2014, 3:29:12 PM12/4/14
to adt...@googlegroups.com
No it won't.

If both productFlavors.B1.signingConfig and buildTypes.debug.signingConfig are non null, the build type one will be used.

Aditya Gore

unread,
Dec 5, 2014, 11:24:03 AM12/5/14
to adt...@googlegroups.com
Thanks much. This works. I am still a little fuzzy when it comes to the order of precedence for BuildType/BuildFlavor and friends. I guess I should go back and watch your tools video from IO.
Reply all
Reply to author
Forward
0 new messages