Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Gradle build type variants

samystudio edited this page Feb 21, 2016 · 3 revisions

It's pretty common to have different app versions, one for debugging and one for production, you can add these build types as following:

flair {

  appId "com.hello.world"
  
  buildTypes {
    debug {}
    release {}
  }
}

Adding these build types will automatically create new tasks, this means for example if you targeting ios, you'll have now:

  • assembleIosDebug
  • assembleIosRelease
  • compileIosDebug
  • compileIosRelease
  • ...

You may then customized each build types using any Flair properties but moduleName, packageName and autoGenerateVariantDirectories which are Flair global properties.

flair {

  appId "com.hello.world"
  
  buildTypes {
    debug {
      debug true
      appIdSuffix ".debug"
    }
    release {}
  }
}

debug property is a special property from Flair that will set all you need to treat that build type as a debug build so you don't have to set compile/package options manually. Platform containers can used these build types as well, you may add specific platform build type or add properties from a common build type:

flair {

  appId "com.hello.world"
  
  buildTypes {
    debug {
      debug true
      appIdSuffix ".debug"
    }
    release {}
  }
  
  ios {
    
    buildTypes {
      debug {
        packageSampler true
      }
      adhoc {
        packageTarget "ipa-ad-hoc"
      }
    }
  }
}

This will create an additional adhoc variant for ios only.

In your code you may access which build type is executing using compilation constants:

  • BUILD_TYPE::DEBUG
  • BUILD_TYPE::RELEASE
  • BUILD_TYPE::XXX
  • ...

Theses constants will be set to true or false depending which version you are running.

...
if( BUILD_TYPE::DEBUG )
{
  // do stuff only if debug
}

BUILD_TYPE::DEBUG
{
public function myFunction(){}
}

BUILD_TYPE::RELEASE
{
public function myFunction(){}
}

Learn more about compilation constants from Adobe documentation.