plugins {
    id 'com.android.library'
    id 'maven-publish'
    id 'org.jetbrains.dokka'
}

android {
    namespace 'com.alan.serialportlib'
    compileSdk 34


    defaultConfig {
        minSdk 21
        targetSdk 34

//        ndk {
//            abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
//        }
    }

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

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

    packagingOptions {
        jniLibs {
            useLegacyPackaging true
        }
    }

    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    ndkVersion '26.2.11394342'

}

dependencies {}


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


afterEvaluate {
    publishing {
        publications {
            release(MavenPublication)
            noSignPublication(MavenPublication) {

                groupId = 'com.github.alanqjt'
                artifactId = 'SerialPortHelper'
                version = '2.0.0' // 实际上 JitPack 会使用 Git Tag，这里写什么都可以

                artifact("$buildDir/outputs/aar/${project.name}-release.aar") {
                    builtBy tasks.named("bundleReleaseAar") // 确保先打包
                }
                artifact(sourcesJar) {
                    classifier "sources"
                }

                pom {
                    name = 'SerialPortHelper'
                    description = 'A lightweight and simple Android serial port communication helper.'
                    url = 'https://github.com/alanqjt/SerialPortHelper'

                    licenses {
                        license {
                            name = 'The Apache License, Version 2.0'
                            url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
                        }
                    }

                    developers {
                        developer {
                            id = '9616b897-ffe8-4fe0-92f2-ce76e05256d8'
                            name = 'AlanQu'
                            email = 'alanqjt@163.com'
                        }
                    }

                    scm {
                        connection = 'scm:git:github.com/alanqjt/SerialPortHelper.git'
                        developerConnection = 'scm:git:ssh://github.com/alanqjt/SerialPortHelper.git'
                        url = 'https://github.com/alanqjt/SerialPortHelper'
                    }
                }
            }
        }

    }

}



