// Top-level build file where you can add configuration options common to all sub-projects/modules.


import groovy.json.JsonSlurper
import org.apache.tools.ant.taskdefs.condition.Os

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {

        /**
         * In Windows OS, gradle can't build the project
         * if the project path is containing more than 240 characters.
         * As a temporary fix, changing the 'buildDir' to 'windowsBuildDir' property in package.json file
         * if the 'windowsBuildDir' property not available it will build the apks in the default value
         * of 'buildDir' which is current repo.
         * refer: https://code.google.com/p/android/issues/detail?id=187430
         */
        def packagejson = new JsonSlurper().parseText(new File("./package.json").text)
        if (packagejson.windowsBuildDir) {
            buildDir = packagejson.windowsBuildDir + "/${rootProject.name}/${project.name}/build"
        }
    }
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
