title: Android Gradle 1.0 Computing Version code in multi-flavor setup
body: <p>The code to compute version code for different product flavors is no longer working in the Android Gradle 1.0 system.  I used the example code below before successfully.</p>
  
  <p><a href="http://tools.android.com/tech-docs/new-build-system/tips#TOC-Computing-Version-code-in-multi-flavor-setup" rel="noreferrer">http://tools.android.com/tech-docs/new-build-system/tips#TOC-Computing-Version-code-in-multi-flavor-setup</a>.</p>
  
  <p>productFlavors.get(0).versionCode is now computed as null.</p>
  
  <p>Gradle code..</p>
  
  <pre><code>android {
  
    buildscript {
      repositories {
        mavenCentral()
      }
      dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
      }
    }
  
    // This actual the app version code. Our given range is [0, 99999]
    defaultConfig.versionCode = 123
  
    // 2 dimensions of flavors. API is more important than ABI.
    flavorGroups "api", "abi"
  
    productFlavors {
      gingerbread {
        flavorGroup "api"
        minSdkVersion 10
        versionCode = 1
      }
      icecreamSandwich {
        flavorGroup "api"
        minSdkVersion 14
        // this must be higher than the gingerbread version to ensure update of the
        // app when the device gets a system update from GB to ICS
        versionCode = 2
      }
      x86 {
        flavorGroup "abi"
        ndk.abiFilter "x86"
        // this is the flavor part of the version code.
        // It must be higher than the arm one for devices supporting
        // both, as x86 is preferred.
        versionCode = 3
      }
      arm {
        flavorGroup "abi"
        ndk.abiFilter "armeabi-v7a"
        versionCode = 1
      }
      mips {
        flavorGroup "abi"
        // It must be higher than the arm one for devices supporting
        // both, as mips is preferred.
        ndk.abiFilter "mips"
        versionCode = 2
      }
      fat {
        flavorGroup "abi"
        // fat binary, lowest version code to be
        // the last option
        versionCode = 0
      }
    }
  
    // make per-variant version code
    applicationVariants.all { variant -&gt;
      // get the version code of each flavor
      def apiVersion = variant.productFlavors.get(0).versionCode
      def abiVersion = variant.productFlavors.get(1).versionCode
  
      // set the composite code
       variant.mergedFlavor.versionCode = apiVersion * 1000000 + abiVersion * 100000 + defaultConfig.versionCode
    }
  }
  </code></pre>