0

I'm just starting to play with gradle. Can I assign variables based on their previously assigned value? For instance, how can I use versionName from the defaultConfig in the free and paid flavors?

For instance, how could I use

android {
   ...
   defaultConfig {
       ...
       versionName "1.0"
   }
   ...
   productFlavors {
      free {
         versionName = versionName + "_free"
         ...
      }
      paid {
        ...
      }
   }
   ...
}

so versionName is "1.0_free" for the free flavor. Is this possible?

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
steven smith
  • 1,519
  • 15
  • 31
  • how about using `versionNameSuffix "_free"`? – ישו אוהב אותך Feb 06 '17 at 03:08
  • 1
    You can use `versionNameSuffix`. As in this [SO answer](http://stackoverflow.com/a/19184323/3942452) – Yoni Gross Feb 06 '17 at 03:12
  • Possible duplicate of [how append date build to versionNameSuffix on gradle](http://stackoverflow.com/questions/19172565/how-append-date-build-to-versionnamesuffix-on-gradle) and [How to set versionName in APK filename using gradle?](http://stackoverflow.com/questions/18332474/how-to-set-versionname-in-apk-filename-using-gradle) – ישו אוהב אותך Feb 06 '17 at 03:16

1 Answers1

0

you can use versionNameSuffix "_free":

productFlavors {
      free {
         // you can also use this
         // applicationIdSuffix ".free"
         versionNameSuffix "_free"
         ...
      }
      paid {
        ...
      }
   }

For more information about the suffix, please visit Configure Build Variants and Gradle Plugin User Guide .

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • Works -- but seems too specialized to me. Works fine for VersionName but what if I want to do the same for ApplicationId. Also, I've read several older comments on this that say things like "Yep, I know it, but versionNameSuffix initialises before any gradle task, so you can not change it from some task" eg: http://stackoverflow.com/questions/21414399/android-gradle-dynamically-change-versionname-at-build-time – steven smith Feb 06 '17 at 18:05
  • Ah -- I see there is an applicationIdSuffix. Where is this stuff documented? – steven smith Feb 06 '17 at 18:09
  • @stevensmith: I've added the link for the documentation. Hope it help us ;) – ישו אוהב אותך Feb 07 '17 at 01:42