/*
* Nodeclipse/Enide build.gradle template for classic Android project
*	https://github.com/Nodeclipse/nodeclipse-1/blob/master/org.nodeclipse.enide.editors.gradle/docs/android/build.gradle
* Gradle Plugin User Guide:
*	http://tools.android.com/tech-docs/new-build-system/user-guide
* Usage
*	1. put in project root
*	2. check version numbers
*	3. use from command line or with Gradle for Android	http://marketplace.eclipse.org/content/gradle
* Support for this template
*	https://github.com/nodeclipse/nodeclipse-1/issues/
* History
*	2014-03-13 android plugin updated to 0.9, see http://tools.android.com/tech-docs/new-build-system/migrating_to_09
*	2014-04-01 check for gradle version
*	2014-04-10 wrapper and runAndroidApplication tasks
*	2014-04-25 rename to run, add <<
* @author Paul Verest 
*/
println GradleVersion.current().prettyPrint()

buildscript {
    repositories {
        mavenCentral()
        //jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+' //0.9.2
    }
}
assert gradle.gradleVersion >= "1.10" // android plugin 0.9 requires Gradle 1.10, 1.11
// after `gradle wrapper` it is possible to use './gradlew build' with Gradle version specified
task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    //androidTestCompile 'com.jayway.android.robotium:robotium-solo:4.3.1'
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        androidTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

// runAndroidApplication
task run (type: Exec, dependsOn: ':installDebug') << {
	println 'asdasd'
	//TODO update Activity name below or find a way to get it from AndroidManifest.xml
	if (System.properties['os.name'].toLowerCase().contains('windows')) {
	    // windows
	    commandLine 'cmd', '/c', 'adb', 'shell', 'am', 'start', '-n', "com.example.androidapptorun.MainActivity"      
	} else {
	    // linux 
	    commandLine 'adb', 'shell', 'am', 'start', '-n', "com.example.androidapptorun.MainActivity"
	}
}
