plugins {
    alias(libs.plugins.android.library)
    alias(libs.plugins.jetbrains.kotlin.android)
    id 'com.google.devtools.ksp'
    id 'maven-publish'
}

android {
    namespace 'com.za.servicing'
    compileSdk 35

    defaultConfig {
        minSdk 23

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
        vectorDrawables {
            useSupportLibrary true
        }

        manifestPlaceholders = [
                JPUSH_PKGNAME : "${applicationId}",
                JPUSH_APPKEY  : "a87e46d05e9f095a2b47a304", //JPush 上注册的包名对应的 Appkey.e6c51448340caba93fd418
                JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.

                XIAOMI_APPID  : "MI-2882303761518149120",
                XIAOMI_APPKEY : "MI-5381814934120",//MI-小米的APPKEY
                HUAWEI_APPID  : "appid=100923923",//appid=华为的APPID"
                OPPO_APPKEY   : "OP-c8ce8eafcd3940ceb85c1ccbee8863c7",//OP-oppo的APPKEY
                OPPO_APPID    : "OP-30136992",//OP-oppo的APPID
                OPPO_APPSECRET: "OP-25e2baa85b7946b1b365af515515c42d",//OP-oppo的APPSECRET
                VIVO_APPKEY   : "cfd443e2a1757cf537361588c988a12a",//vivo的APPKEY
                VIVO_APPID    : "105470845",//vivo的APPID
        ]
    }

    buildTypes {
        release {
//            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
    }
    buildFeatures {
        compose true
        buildConfig true // 生成 BuildConfig
        resValues true  // 允许资源值生成
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.5.15'
    }
    packaging {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
    publishing {
        singleVariant("release") {
            withSourcesJar()
        }
    }
}
publishing {
    publications {
        release(MavenPublication) {
            groupId = 'io.github.szl9'
            artifactId = 'zd_servicing'
            version = "1.0.1.9"

            pom {
                packaging = "aar"
                name.set("zd_servicing")
                description.set("zd_servicing: Library for Android Application")
                url.set("https://github.com/szl9/4dbki6r4uv.git")
                inceptionYear.set("2024")

                licenses {
                    license {
                        name.set("MIT License")
                        url.set("https://opensource.org/licenses/MIT")
                    }
                }

                developers {
                    developer {
                        id.set("zd")
                        name.set("zd szl")
                        email.set("17630035658@163.com")
                    }
                }

                scm {
                    connection.set("scm:git@github.com:szl9/4dbki6r4uv.git")
                    developerConnection.set("scm:git@github.com:szl9/4dbki6r4uv.git")
                    url.set("https://github.com/szl9/4dbki6r4uv.git")
                }
            }

            // 将 afterEvaluate 移到 publications 块内
            afterEvaluate {
                from components.release
                // 将依赖项处理放在这里
                pom.withXml {
                    def root = asNode()
                    def dependenciesNode = root.dependencies ? root.dependencies[0] : root.appendNode('dependencies')
                    configurations.api.allDependencies.each { dep ->
                        try {
                            if (dep.group != null && dep.name != null && dep.version != null) {
                                def dependencyNode = dependenciesNode.appendNode('dependency')
                                dependencyNode.appendNode('groupId', dep.group)
                                dependencyNode.appendNode('artifactId', dep.name)
                                dependencyNode.appendNode('version', dep.version)
                                dependencyNode.appendNode('scope', 'compile')
                            }
                        }
                        catch (Exception e) {
                            logger.warn("Failed to add dependency ${dep} to POM", e)
                        }
                    }
                }
            }
        }
    }

    repositories {
        maven {
            name = 'zd_servicing'
            url = layout.buildDirectory.dir("zd_servicing")
        }
    }
}

tasks.register('generateRepo', Zip) {
    def publishTask = tasks.named('publishReleasePublicationToZd_servicingRepository')
    from publishTask.map { it.getRepository().getUrl() }
    into 'zd_servicing'
    archiveFileName.set('zd_servicing.zip')
}
dependencies {
    api libs.androidx.core.ktx
    api libs.androidx.appcompat
    api libs.material
    api libs.androidx.lifecycle.viewmodel.compose
    api libs.androidx.lifecycle.runtime.ktx
    api libs.androidx.activity.compose
    api platform(libs.androidx.compose.bom)
    api libs.androidx.ui
    api libs.androidx.ui.graphics
    api libs.androidx.ui.tooling.preview
    api libs.androidx.material3
    api libs.androidx.work.runtime.ktx
    api libs.androidx.exifinterface

    testApi libs.junit
    androidTestApi libs.androidx.junit
    androidTestApi libs.androidx.espresso.core
    androidTestApi platform(libs.androidx.compose.bom)
    androidTestApi libs.androidx.ui.test.junit4
    debugApi libs.androidx.ui.tooling
    debugApi libs.androidx.ui.test.manifest

    api libs.coil.compose
    api libs.coil.gif

    api libs.permissionx
    api libs.utilcodex

    api libs.crashreport

    // 高德地图
    api libs.xdmap
    api libs.location
    api libs.search

//    // JPush
    api libs.jpush
    api libs.jcore
    api libs.gson

    // 网络
    api libs.retrofit
    api libs.converter.gson
    api libs.adapter.rxjava3
    api libs.rxjava
    api libs.rxandroid
    api libs.logging.interceptor
    api libs.fastjson

    // 本地数据
    api libs.room.runtime
    annotationProcessor libs.room.compiler
    ksp libs.room.compiler
    api libs.mmkv

    // 7z
    api libs.xz
    api libs.commons.compress

    api libs.core
    api libs.tbssdk

    // CameraX
    api libs.androidx.camera.core
    api libs.androidx.camera.camera2
    api libs.androidx.camera.lifecycle
    api libs.androidx.camera.view
    api libs.androidx.camera.extensions

    api libs.glide
    annotationProcessor libs.compiler

    api libs.org.eclipse.paho.client.mqttv3
    api libs.org.eclipse.paho.android.service
}

