Adam Lins Adam Lins - 1 year ago 117
Android Question

How to use artifactoryPublish to publish release and debug artifacts

I have Android Studio projects that build AARs or APKs in both release and debug versions. I'd like to publish these to different to different repositories on my Artifactory server. The JFrog examples don't appear to cover this case.

Does this mean that it's considered best practice to simply build either only the release or only the debug version, and choose what and where to upload based on the type of build?

Answer Source

I configured my android library build.gradle file that compiled aar file could be uploaded in different repos, dependent on build type.
For example you want to publish debug artifats to 'libs-debug-local' repository and release artifacts to 'libs-release-local' repository.

//First you should configure all artifacts you want to publish
publishing {
    publications {

        //Iterate all build types to make specific 
        //artifact for every build type
        android.buildTypes.all { variant ->

            //it will create different 
            //publications ('debugAar' and 'releaseAar')
            "${}Aar"(MavenPublication) {
                def manifestParser = new

                //Set values from Android manifest file
                groupId manifestParser.getPackage(android.sourceSets.main.manifest.srcFile)
                version = manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile)
                artifactId project.getName()

                // Tell maven to prepare the generated "*.aar" file for publishing

//After configuring publications you should
//create tasks to set correct repo key
android.buildTypes.all { variant ->

    //same publication name as we created above
    def publicationName = "${}Aar"

    //new task name
    def taskName = "${}Publication"

    //in execution time setting publications and repo key, dependent on build type
    tasks."$taskName" << {
        artifactoryPublish {
            doFirst {
                clientConfig.publisher.repoKey = "libs-${}-local"

    //make tasks assembleDebug and assembleRelease dependent on our new tasks
    //it helps to set corrent values for every task

//Inside artifactory block just set url and credential, without setting repo key and publications
artifactory {
    contextUrl = ''
    publish {
        repository {
            username = "username"
            password = "password"
        defaults {
            publishArtifacts = true

            // Properties to be attached to the published artifacts.
            properties = ['qa.level': 'basic', '': 'core']

That's all. Now if you run command

gradle assembleRelaese artifactoryPublish

aar file will be uploaded to 'libs-release-local' repository.
And if you ran

gradle assembleDebug artifactoryPublish

it will be uploaded to 'libs-debug-local' repository

One minus of this configuration is that you should always run artifactoryPublish task with assembleDebug/Release tasks

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download