1

I need to have a String that varies in value based on my app's productFlavors:

I need to have something like this:

    def flavorName = new String()

    productFlavors {
    closedBeta {
        versionName "1.0.0-BETA"
        flavorName = "closedbeta"
    }
    alpha {
        versionName "1.0.0-ALPHA"
        flavorName =  "alpha"
    }
    production {
        versionName "1.0.0-PROD"
        flavorName =  "prod"
    }
}

This code apparently does not work because it just sets the value of flavorName as the declaration for each productFlavor proceeds. How can I have static value of flavorName to each productFlavor?

Ulf Gjerdingen
  • 1,414
  • 3
  • 16
  • 20
Dale Julian
  • 1,560
  • 18
  • 35
  • What is your question or problem ? – Wasim K. Memon Jul 26 '16 at 06:26
  • @androidnoobdev this code apparently does not work because it just sets the value of flavorName as the declaration for each productFlavor goes – Dale Julian Jul 26 '16 at 06:28
  • use a switch case statement to determine which version the user is using & based on it, you can set the flavourName. – Arshak Jul 26 '16 at 06:28
  • 1
    how can I retrieve the current product flavor to put in the switch case statement? – Dale Julian Jul 26 '16 at 06:30
  • possibly related to this unanswered question [Is there a way to change gradle variable value based on selected productFlavor?](http://stackoverflow.com/questions/35956182/is-there-a-way-to-change-gradle-variable-value-based-on-selected-productflavor) – Richard Le Mesurier Jul 26 '16 at 10:13
  • What are you trying to do with `flavorName` in this context? If you are using it within the app, maybe what you need is different string resources per flavor? – Richard Le Mesurier Jul 26 '16 at 10:23
  • This might help you: http://stackoverflow.com/questions/17197636/is-it-possible-to-declare-a-variable-in-gradle-usable-in-java – nasch Jul 27 '16 at 03:45

0 Answers0