Now you should have 2 source type directories. main and qa, but in qa directory you will have just an empty java folder so you will have to add manually the other resource folders you wil need by always specifying the target source.

Product Flavors

Flavors are similar in a way to Build Types, but they are used in case you need different versions of the same app. The best example in this case is free version vs paid version of an app. Or also flavors are used in case of rebranding an app (different resource files and slightly different code).

Product Flavors Configuration

1

2

3

4

5

6

7

8

9

10

11

productFlavors{

free{

applicationId"com.example.myapp.free"

versionName"1.0-free"

}

paid{

applicationId"com.example.myapp.paid"

versionName"1.0-paid"

}

}

Open build.gradle file from app directory (your module-level), the same build.gradle used for Build Types.

Related Posts

if signing config can be set in both how it’s working?! As a result we have matrix of artefacts: freeDebug, freeQA, freeRelease, paidDebug, paidQA, paidRelease. I would like Debug & QA builds to use debug signing keys (1 for free & different one for paid debug & QA) as well as Release (2 signing keys for free & paid release). So I wonder where should one set signing config? in Flavors or buildTypes? Thanks

Hi @zaphodbeeblebroks:disqus , I updated the post, unfortunately I don’t have time now to add explanations there but you can take a look over the final configuration and you’ll notice that I added some new signingConfig fields and I think that should help you. You will have to add debug signing configs and update the build config properly and you should be ready to go :). Let me know if that works for you!

Zaphod Beeblebroks

seems like productFlavors need to be declared before types, otherwise it doesn’t compile.. Still having issues with debug. Do you maybe have Github repo for this?

Yup, sorry with that, could you please describe what errors do you have? I don’t have an example on github for this one but I could do that latter today or tomorrow if it still helps.

Zaphod Beeblebroks

I made reduced build.gradle gist and added comment.. Can’t really explain why, but debug builds of all flavors are signed with default system debug keystore.. It’s like there is implicit ‘debug’ signingConfig with default system key (like line 46, 47 in gist are ignored) https://gist.github.com/ewoks/57af91eb96b6f77e458a4485462d580b

Hi @zaphodbeeblebroks:disqus , sorry for the long delay, yes indeed, Android has only one debug keystore and that is the one provided by default, we can’t have custom ones it seems :(. But why would you need a custom debug key?

Zaphod Beeblebroks

No no no…. ;))) you CAN define your custom debug key.
The only thing is that in my use case, I wanted to use different custom define debug key for all my flavors of debug BuildType, which is not possible in my config, so I ended up signing all of debug flavors with same custom defined key (while every flavor can has its own release key).

This is VERY useful if you have more than one developer on project because debug version is always signed with the same key so developers don’t need to uninstall previous version installed by other team member because of different signature. Besides there is one and only debug key for 3rd party libraries that require it (i.e. google play services:maps or firebase)

@zaphodbeeblebroks:disqus thanks for your reply! Ok but the debug key is actually the same one with the debug key that the android tools offer, right? At least that is what I know.
Best regards!

Zaphod Beeblebroks

So it works: Android Studio / Tools will auto generate debug signing key _once_ on every development machine and by default use that auto generated debug-key for every app you develop on that machine if you don’t specify otherwise. You can generate your own debug signing key (similar like generating release keys) and add it to repository (therefore share it) so every developer can reuse that one instead default auto-generated one on their local machine. Glad I could help 😉

Want to donate?

Meta

In this post, I will try to explain how to write functions in Kotlin by doing a parallel with Java. It’s not rocket science or anything special in this post, but this is the way I understand and remember better... The post Functions – Kotlin appeared first on My Android Solutions.

This site uses cookies from Google to deliver its services, to personalize ads and to analyze traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies. AcceptRead More