apply plugin: 'com.android.application'

//
//	Creates version.xml	
//
task createVersionXML {
	doLast {
        def versionP = 'git describe --tags --long --dirty=-x --abbrev=8'
						.execute()
        def version = versionP.text.trim()
		if ( versionP.exitValue() )
			throw new GradleException("Couldn't extract version. Git exited unexpectedly.")

        def githashP = 'git rev-parse HEAD'.execute()
        def githash = githashP.text.trim()
		if ( githashP.exitValue() )
			throw new GradleException("Couldn't extract git_hash. Git exited unexpectedly.")
		
		def builddate = new Date()

	    def versionFile = new FileWriter("app/src/main/res/values/version.xml")
		versionFile.println( '<?xml version="1.0" encoding="utf-8"?>' )
		versionFile.println( '<resources>' )
		versionFile.println( '<string name="git_version">' << version << '</string>' )
		versionFile.println( '<string name="git_hash">' << githash << '</string>' )
		versionFile.println( '<string name="build_date">' << builddate << '</string>' )
		versionFile.println( '<string name="version_code">0x00010001</string>' )
		versionFile.println( '</resources>' )
		versionFile.close()
	}
}
preBuild.dependsOn createVersionXML

//
//	Convert SVG images from art directory into PNG files.
//
task generateDrawablesFromArt {
	doLast {
		def buildDir = (new File(project.buildDir,'art')).toString()
        def p = ('make -C app/src/main/art RES=../res TMP='+buildDir).execute()
		p.consumeProcessOutput()
		p.waitFor()
		if ( p.exitValue() )
			throw new GradleException("Generation of art failed.")
	}
}
preBuild.dependsOn generateDrawablesFromArt

android {
    compileSdkVersion 10
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "org.vostan.sokoban"
        minSdkVersion 10
        targetSdkVersion 14
    }
    apply from: new File(getRootDir(),'/.secret.gradle')
    buildTypes {
        release {
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
            signingConfig signingConfigs.sokoban_release
        }

        debug {
            applicationIdSuffix ".debug"
        }
    }

    sourceSets {
        /*
        main {
            java.srcDirs = ['src']

            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']

            renderscript.srcDirs = ['src']

            res.srcDirs = ['res']
            assets.srcDirs = ['assets']

        }
        */
        debug {
            main.manifest.srcFile "src/main/AndroidManifest-debug.xml"
        }
        androidTest.setRoot("src/tests")
    }
}

//repositories {}

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
}
