Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish apks to the Maven Central with gradle?

I create an android project with android studio.

It will generate some apks.

How can i publish apks to the Maven Central with gradle?

What can i write in the artifacts for the apk?

apply plugin: 'maven'
apply plugin: 'signing'

configurations {
    archives {
        extendsFrom configurations.default
    }
}

afterEvaluate { project ->
    uploadArchives {
        repositories {
            mavenDeployer {
                configurePOM(pom)
                beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

                repository(url: sonatypeRepositoryUrl) {
                    authentication(userName: nexusUsername, password: nexusPassword)
                }
            }
        }
    }

......

    artifacts {
       archives file: files(dir: '$buildDir/apk/*.apk', include: '*.apk')
        // archives androidReleaseApklib
        archives androidReleaseJar
        archives androidSourcesJar
        archives androidJavadocsJar
    }
}
like image 615
snowdream Avatar asked Nov 07 '13 10:11

snowdream


1 Answers

We publish our APK files to our local Nexus repository using gradle. This is what I've come up with. This example demonstrated using a "googlePlay" build flavor.

// make sure the release builds are made before we try to upload them.    
uploadArchives.dependsOn(getTasksByName("assembleRelease", true))

// create an archive class that known how to handle apk files.
// apk files are just renamed jars.
class Apk extends Jar {
    def String getExtension() {
        return 'apk'
    }
}

// create a task that uses our apk task class.
task googlePlayApk(type: Apk) {
    classifier = 'googlePlay'
    from file("${project.buildDir}/outputs/apk/myApp-googlePlay-release.apk")
}

// add the item to the artifacts
artifacts {
    archives googlePlay
}
like image 131
vangorra Avatar answered Nov 14 '22 11:11

vangorra