apply plugin: 'com.android.application'
apply plugin: 'com.github.dcendents.android-maven'

dependencies {
    compile project(':vtm-gdx')
    compile project(':vtm-themes')
    compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
    compile 'com.noveogroup.android:android-logger:1.3.6'
}

android {
    compileSdkVersion androidCompileSdk()
    buildToolsVersion "$androidBuildVersionTools"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    defaultConfig {
        versionCode versionCode()
        versionName versionName()
        minSdkVersion androidMinSdk()
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src', 'assets']
            aidl.srcDirs = ['src', 'assets']
            renderscript.srcDirs = ['src', 'assets']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['natives/lib', "${rootDir}/vtm-android/natives/lib"]
        }
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

    lintOptions { abortOnError false }
}

android.applicationVariants.all { variant ->
    def name = variant.buildType.name
    if (name.equals("debug")) {
        print "Skipping debug jar"
        return; // Skip debug builds.
    }
    def task = project.tasks.create "jar${name.capitalize()}", Jar
    task.dependsOn variant.javaCompile
    task.from variant.javaCompile.destinationDir
    artifacts.add('archives', task);
}

android.applicationVariants.all { variant ->
    def name = variant.buildType.name
    if (name.equals("debug")) {
        print "Skipping debug jar"
        return; // Skip debug builds.
    }
    def task = project.tasks.create "nativesJar${name.capitalize()}", Jar
    task.classifier = 'natives'
    task.from('natives')
    artifacts.add('archives', task);
}

afterEvaluate {
    configurations.archives.artifacts.removeAll { it.file =~ 'apk' }
}

task run(dependsOn: 'installDebug') {
    doFirst {
        println(">> adb run...")
        String adb = System.getenv()['ANDROID_HOME'] + '/platform-tools/adb'
        String cmd = "${adb} shell am start -n org.oscim.gdx/.MainActivity"
        def proc = cmd.execute()
        proc.in.eachLine { line -> println line }
        proc.err.eachLine { line -> System.err.println('ERROR: ' + line) }
        proc.waitFor()
    }
}

// Automated Gradle project deployment to Sonatype OSSRH
if (isReleaseVersion && project.hasProperty("SONATYPE_USERNAME")) {
    afterEvaluate {
        project.apply from: "${rootProject.projectDir}/deploy.gradle"
    }
}