apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply from : '../common.gradle'

android {

    namespace 'com.hjq.permissions'

    defaultConfig {
        // 最低安装版本
        minSdkVersion 17

        // 框架的混淆配置
        consumerProguardFiles 'proguard-permissions.pro'
    }

    libraryVariants.configureEach { variant ->
        variant.packageLibraryProvider.configure { packageLib ->
            // 剔除 META-INF 目录
            packageLib.exclude 'META-INF/'
            // 剔除 R.txt 文件
            packageLib.exclude 'R.txt'
        }
    }
}

dependencies {
    // noinspection GradleCompatible
    implementation 'com.android.support:support-fragment:24.2.0'
    // 设备兼容框架：https://github.com/getActivity/DeviceCompat
    implementation 'com.github.getActivity:DeviceCompat:1.0'
}

publishing {
    publications {
        release(MavenPublication) {
            groupId = 'com.github.getActivity'
            artifactId = 'XXPermissions'
            version = android.defaultConfig.versionName
            // 指定 aar 文件的确切路径：https://cloud.tencent.com/developer/ask/sof/106381154
            afterEvaluate {
                artifact(bundleReleaseAar)
            }

            // 修正 Maven 插件在生成的 pom 文件没有携带 dependencies 信息的问题
            // 用于测试 Gradle 命令：./gradlew publishToMavenLocal
            // 相关 Github 地址：https://github.com/getActivity/XXPermissions/issues/371#issuecomment-3018735968
            pom.withXml {
                def dependencies = asNode().appendNode('dependencies')
                configurations.implementation.allDependencies.each {
                    def dependency = dependencies.appendNode('dependency')
                    dependency.appendNode('groupId', it.group)
                    dependency.appendNode('artifactId', it.name)
                    dependency.appendNode('version', it.version)
                    dependency.appendNode('scope', 'runtime')
                }
            }
        }
    }
}