4

我有三个构建变体 - android 库中的暂存、调试和生产。我需要在 maven 上发布 aar 文件,但限制是,如果当前选择的构建变体是调试或暂存,那么只有 debugAar 应该发布,如果选择了发布,那么 releaseAar 应该发布。默认情况下,gradle 只发布 releaseAar。

目前,每次我想要调试变体时,我都需要将“artifact(bundleReleaseAar)”更改为“artifact(bundleDebugAar)”

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'dexguard'

def libraryGroupId = '*.*'
def libraryArtifactId = 'xyz'
def libraryVersion = projectxyzVersion

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        flatDir { dirs 'lib' }
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath ':dexguard:'
    }
}

android {
    compileSdkVersion projectCompileSdkVersion


    defaultConfig {
        minSdkVersion projectMinSdkVersion
        targetSdkVersion projectTargetSdkVersion
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
    }

    buildTypes {
        debug {
            /*ext.enableHanselLocalization = false
            ext.enableHansel = false*/
            debuggable true
            buildConfigField ('String', 'BUILD_TYPE_STRING', '"debug"')

            //todo only for testing, remove while making final aar
            proguardFile getDefaultDexGuardFile('dexguard-library-debug.pro')
            proguardFile 'dexguard-project.txt'
        }
        staging {
            debuggable true
            buildConfigField ('String', 'BUILD_TYPE_STRING', '"staging"')
            /*ext.enableHanselLocalization = false
            ext.enableHansel = false*/
        }
        release {
            /*ext.enableHanselLocalization = false
            ext.enableHansel = false*/
            buildConfigField ('String', 'BUILD_TYPE_STRING', '"release"')
//             minifyEnabled true
//            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            proguardFile getDefaultDexGuardFile('dexguard-library-release.pro')
            proguardFile 'dexguard-project.txt'
        }
    }

}

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

    implementation "com.android.support:appcompat-v7:${projectSupportLibraryVersion}"
    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'
    implementation ("com.google.android.gms:play-services-safetynet:${projectSafetyNetVersion}") {
        exclude group: "androidx.core"
    }
    implementation "com.android.volley:volley:${projectVolleyVersion}"
    implementation "com.google.code.gson:gson:${projectGsonVersion}"
}

publishing {
    publications {
        aar(MavenPublication) {
            groupId libraryGroupId
            version libraryVersion
            artifactId libraryArtifactId

            artifact(bundleReleaseAar)

            pom.withXml {
                def dependenciesNode = asNode().appendNode('dependencies')
                def deps = configurations.implementation.allDependencies + configurations.compile.allDependencies + configurations.api.allDependencies
                deps.each {
                    if (it.group != null && (it.name != null || "unspecified".equals(it.name)) && it.version != null && !"unspecified".equals(it.version)) {
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', it.group)
                        dependencyNode.appendNode('artifactId', it.name)
                        dependencyNode.appendNode('version',it.version)
                    }
                }
            }
        }
    }
}

artifactory {
    contextUrl = 'https://artifactory.paytm.in/'
    publish {
        repository {
            repoKey = "xyz-android"

            username = xyz_artifactory_username
            password = xyz_artifactory_password
        }
        defaults {
            publications('aar')
            publishArtifacts = true

            properties = ['qa.level': 'basic', 'q.os': 'android', 'dev.team': 'core']
            publishPom = true

        }
    }
}
4

0 回答 0