// Project information
buildDir = 'bin'

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
    }
}

apply plugin: 'com.android.library'

android {
    defaultConfig {
        compileSdkVersion 23
        buildToolsVersion "25.0.2"
        multiDexEnabled true
    }

    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            jniLibs.srcDirs = ['libs/']
        }

        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

android {
    libraryVariants.all { variant ->
        def appName = "libmediastreamer2-sdk"

        variant.outputs.each { output ->
            def newSdkName = "bin/outputs/aar/${appName}.aar"
            output.outputFile = new File(newSdkName)
        }
    }
}

///////////// Task /////////////

task(releaseJavadoc, type: Javadoc, dependsOn: "assembleRelease") {
    source = ['src']
    excludes = ['**/**.html',
                '**/**.aidl']
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    classpath += files(android.libraryVariants.release.javaCompile.classpath.files)
}

task sourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}

task androidJavadocsJar(type: Jar, dependsOn: releaseJavadoc) {
    classifier = 'javadoc'
    from releaseJavadoc.destinationDir
}

task sdkZip(type: Zip, dependsOn: ["sourcesJar", "androidJavadocsJar"]) {
    String appName = "libmediastreamer2-sdk"
    String gitSha = 'git describe --always'.execute().text.trim()
    String newSdkName = appName + "-" + gitSha + ".zip"

    from('bin/libs',
         'bin/outputs/aar')
    include '*'
    archiveName newSdkName
}