Published on

Publish Android Library

Authors

Like you, as an Android developer that has benefitted from Github open source libraries a lot for long time, I start thinking how to repay this community. The best way, of course, is to share my contribution by publishing android library code. This post tells what to follow when you want to publish your Android library project on Github.

Github & Git

The first of the first, you should take some time to get familiar with Git and Github.

Gradle & Android Studio

Familiarize yourself with Gradle and Android Studio.

Choose a License

Choose a license for your project. If you do not know how to, check this page:
http://choosealicense.com/

"Apache License 2.0" is common to Android open source libraries on Github.

Add a readme

Add "readme.md" file to tell people what the project is about and how to use it.

Publish

When you are done with all the library code and Android Studio / gradle project code stuff, it is time to share it.

Android now jcenter uses by default. It is a good idea to share your library by jcenter too so that other Android developers can use your library by just adding gradle dependency, such as:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'android.lucas:swipeback:0.0.1'
}

There is no direct support in Android Studio or gradle now and it is a bit tricky to set up.

The post [TUT] Locally release an Android Library for JCenter or Maven Central inclusion](http://blog.blundell-apps.com/locally-release-an-android-library-for-jcenter-or-maven-central-inclusion/) is a good start to accomplish the task.
To simplify the life, you can customize your library project build.gradle file based on the following template:

https://gist.github.com/d860969fdda132b6d892.git

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
// This is the library version used when deploying the artifact
version = "0.0.1"
group = "android.lucas"
def siteUrl = 'https://github.com/xianminx/SwipeBack'
def gitUrl = 'https://github.com/xianminx/SwipeBack.git'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName version
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
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 = "SwipeBack"
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true
}
}
install {
repositories.mavenInstaller {
pom {
project {
packaging 'aar'
name 'Navigate back to the previous Activity by Swipe Gesture from the left edge of the screen. '
url siteUrl
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'xianminx'
name 'Lucas Xu'
email 'xianminx@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
}
artifacts {
archives javadocJar
archives sourcesJar
}
task findConventions << {
println project.getConvention()
}
// ./gradew bintrayUpload to upload archives to bintray.
view raw build.gradle hosted with ❤ by GitHub

Then publish with command:

./gradlew bintrayUpload

Github page

Give it a dedicated website or webpage makes your open source library project look professional.
Github provides "Github Pages" feature so that you can create a page for your project very easily.

Project->Setting -> Options -> Github Pages -> Automatic Page Generator

Then follow the instructions to create a webpage for your project.

Share it on Twitter, G+, Facebook, etc

Finally, after all these done, share it to all social platforms to let people find it.