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"
    }
}

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       = 'libdeepspeech'
            pom.groupId    = 'org.mozilla.deepspeech'
            pom.artifactId = 'libdeepspeech'
            pom.version    = dsVersionString + (project.hasProperty('snapshot') ? '-SNAPSHOT' : '')

            pom.project {
                description 'Speech recognition library'
                url 'https://github.com/mozilla/DeepSpeech'

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

                developers {
                    developer {
                        id 'deepspeech'
                        name 'Mozilla DeepSpeech Team'
                        email 'deepspeechs@lists.mozilla.org'
                    }
                }

                scm {
                    connection 'https://github.com/mozilla/DeepSpeech.git'
                    developerConnection 'https://github.com/mozilla/DeepSpeech.git'
                    url 'https://github.com/mozilla/DeepSpeech'
                }
            }

            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}"))
}
