How to publish and distribute your Android AAR package?

How to publish and distribute your Android AAR package?

Table of Contents

  • JCenter vs Maven Central
  • Add build script dependencies
  • Configure the library module
  • Sign up an account in bintray
  • Sample


1 JCenter vs Maven Central

I don't know since when Android Gradle's default repository started to use jcenter instead of the older maven central as the default archive repository.

According to some talks, Jcenter can leverage the JFrog's technology, which is a superset of Maven central, so it improved and promoted the efficiency of Android project compilation. In a word, Jcenter is better than Maven Central.

2 Add build script dependencies

dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3.1'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
}

Add above code to your root build.gradle

3 Configure the library module

apply plugin: 'com.android.library'

apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

android {

    ...
}


apply from: './bintray_upload.gradle'

apply plugins in the header of the library module's build.gradle.

Following is the detailed configuration script bintray_upload.gradle.

version = android.defaultConfig.versionName

def siteUrl = 'https://github.com/suzp1984/jbig-android'      // Homepage URL of the library
def gitUrl = 'https://github.com/suzp1984/jbig-android.git'   // Git repository URL

group = "org.jacob.lib.jbig"

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'
                artifactId 'jbig-android'

                // Add your description here
                name 'jbig library aar project for android'
                url siteUrl

                // Set your license
                licenses {
                    license {
                        name 'GNU GENERAL PUBLIC LICENSE, Version 3'
                        url 'http://www.gnu.org/licenses/gpl.txt'
                    }
                }

                developers {
                    developer {
                        id 'suzp1984'
                        name 'suzp1984'
                        email 'suzp1984@gmail.com'
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl

                }
            }
        }
    }
}

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
    // options.encoding = 'UTF-8'
}

artifacts {
    archives javadocJar
    archives sourcesJar
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")

    configurations = ['archives']
    pkg {
        repo = "maven"
        name = "jbig-android"
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["GPL-3.0"]
        publish = true
    }
}

4 Sign up an account in bintray

Then, sign up an account in bintray. First, upload the archive into a bintray repository, then link to JCenter on the website.

Add your account info into project's local.properties, in this case is two values: bintray.user and bintray.apikey.

5 Sample

refer to my project jbig-android to get some details as a real sample, But there are still some flaws left, because of the un-standard pom format and content, bintray send me an email to illustrate that he can not accept my request to link it into Jcenter.

Comments

Popular posts from this blog

Bluedroid stack in android

How to setup a NAT server?

Network programming in elisp