How to extend the existing BuildFlavor in android build.gradle

195 views Asked by At

I need to create the buildVarient "Premium" which will have the functionality of "Paid" variant with default main but NOT of the "free" variant.. so the new "Premium" variant will have all functionality of "Paid" with added functionality for "Premium". but not "free" .. with new dimension approach in buildVarient if i create the new variant for premium with new dimension "pro" it will create buildVarient like freePremiumDebug freePremiumRelease paidPremiumDebug paidPremiumRelease

but that not what i want it should be like freeDebug freeRelease paidDebug paidRelease premiumDebug (OR paidPremiumDebug) PremiumRelease (OR paidPremiumRelease)

in short i want to leverage the functionality of Paid in Premium and not free.. if I directly create the Premium variant in same dimension("tier") then.. i will not be able to levarage the existing functionality of Paid (OR i have to clone the code file of the paid in premium and use it with new changes for premium which is not ideal solution )..Please help me out. ` flavorDimensions "tier", "pro"

productFlavors { paid { dimension "tier" ... add variables here }

free {
    dimension "tier"
    versionName = android.defaultConfig.versionName + " free"
    ... add variables here
}

premium{ dimension "pro"

}`

1

There are 1 answers

0
Mr.Heisenberg On BEST ANSWER

The SourceSet in build.gradle approach help us here to solve the issue where we set the source path of the required Product Flavor which we want to extend.