apply plugin: 'com.android.library'
apply plugin: 'maven'

android {
    compileSdkVersion 27

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 27
        versionName androidGitVersion.name()
        versionCode androidGitVersion.code()

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        setProperty("archivesBaseName", "${archivesBaseName}-${dsVersionString}")

        ndk {
            abiFilters = []
            abiFilters.addAll(ABI_FILTERS.split(';').collect{it as String})
        }

        externalNativeBuild {
            cmake {
                cppFlags ""
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }

    adbOptions {
        timeOutInMs 15 * 60 * 1000  // 10 minutes
        installOptions "-d","-t"
    }

    // Avoid scanning libstt_doc
    sourceSets {
        main.java.srcDirs = [ 'src/main/java/ai/coqui/libstt/' ]
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    testImplementation 'junit:junit:4.12'

    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

task printABIs {
    print ABI_FILTERS.split(';').join(" ")
}

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

artifacts {
    archives sourcesJar
}

uploadArchives {
    repositories {
        mavenDeployer {
            pom.packaging  = 'aar'
            pom.name       = 'libstt'
            pom.groupId    = 'ai.coqui'
            pom.artifactId = 'libstt'
            pom.version    = dsVersionString + (project.hasProperty('snapshot') ? '-SNAPSHOT' : '')

            pom.project {
                description 'A library for doing speech recognition using a Coqui STT model'
                url 'https://github.com/coqui-ai/STT'

                licenses {
                    license {
                        name 'MPL-2.0'
                        url 'https://www.mozilla.org/en-US/MPL/2.0/'
                        distribution 'repo'
                    }
                }

                developers {
                    developer {
                        id 'coqui'
                        name 'Coqui GmbH'
                        email 'maven@coqui.ai'
                    }
                }

                scm {
                    connection 'https://github.com/coqui-ai/STT.git'
                    developerConnection 'https://github.com/coqui-ai/STT.git'
                    url 'https://github.com/coqui-ai/STT'
                }
            }

            repository(url: "file://${project.buildDir}/maven")
        }
    }
}

task zipMavenArtifacts(type: Zip) {
    from "${project.buildDir}/maven"

    include '**/*.aar'
    include '**/*.jar'
    include '**/*.pom'
    include '**/*.md5'
    include '**/*.sha1'
    include '**/*maven-metadata.xml*'

    archiveName "${archivesBaseName}.maven.zip"
    includeEmptyDirs = false
    destinationDir(file("${project.buildDir}"))
}
