apply plugin: 'com.android.library'

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1'
    }
}

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        targetSdkVersion 22
        minSdkVersion 4
        versionCode 1
        versionName "1.0.4"
    }

    sourceSets {
        main {
            jni.srcDirs = []
            jniLibs.srcDirs = ['src/main/libs/']
        }
    }

    archivesBaseName=getName()
    version='1.0.'+(System.getenv('BUILD_NUMBER') ? System.getenv('BUILD_NUMBER') : '0-LOCAL')

    //rename the aar to {archivesBaseName}-{version}.aar
    libraryVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.aar')) {
                def fileName = "${archivesBaseName}-${version}.aar"
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }
}

// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
    String ndkDir = android.ndkDirectory
    commandLine "$ndkDir/ndk-build", '-j8', '-C', file('src/main/jni').absolutePath
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}
task cleanExtra(type: Delete) {
    delete 'src/main/obj'
}
clean.dependsOn(cleanExtra)

group = 'me.everything'

apply plugin: 'com.jfrog.artifactory-upload'
apply plugin: 'android-maven'
