• Non classé
  • 0

Publish a library to Jcenter

Most Android libraries are published on JCenter, allowing everyone to access them directly from gradle. This enables us to import a multitude of useful plugins directly in our project, with only few lines.

In this tutorial, I will show you how to publish your Android library, in my case the ExpectAnim library, so that any developer can import it in his project thanks to gradle.

compile 'com.github.florent37:expectanim:1.0.2'

Bintray.com

JCenter is a public Maven repository, directly available from the default android projects configuration.

Jcenter is hosted on Bintray.com.

Sign Up

The first step to publish a library on Jcenter is to signup on Bintray !

Get the Api Key

Once you have an account, get your API key, which will allow you to upload your artifact on bintray
Go the the profile section and click on the sub-section API Key

 

Here, for example, my API key is 53fd629a7c75e0da9b2fe13ff908e2d4740cefe7

Configure your Android project

To continue, add your username and your apikey in the local.properties file

bintray.user=florentchampigny
bintray.apikey=53fd629a7c75e0da9b2fe13ff908e2d4740cefe7 

We will use the plugin gradle-bintray-plugin to push our libraries directly from Android Studio. To enable this convenient feature, add the following dependency in your project’s file build.gradle

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'

        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
       
    }
}

Download then the 3 following files, and move them inside the directory gradle/

bintray-android-v1.gradle
bintray-java-v1.gradle
install-v1.gradle

It only remains to describe our artifact inside our module. To do this, write the following lines at the bottom of your module’s file build.gradle :

ext {
    bintrayRepo = 'maven' //the maven repo name (created on bintray)
    bintrayName = 'ExpectAnim' //the name you want to give at your project on bintray
    orgName = 'florentchampigny' //your user name

    publishedGroupId = 'com.florentchampigny' //aaaa : the librairy group
    artifact = 'expectanim' //BBBB : the library name
    libraryVersion = "1.0.2" //the librairy version

    //the library will be : aaaa:BBBB:version

    libraryName = 'ExpectAnim'
    libraryDescription = 'Animate views easily'

    siteUrl = 'https://github.com/florent37/ExpectAnim'
    gitUrl = 'https://github.com/florent37/ExpectAnim.git'

    developerId = 'florentchampigny'
    developerName = 'Florent Champigny'
    developerEmail = 'champigny.florent@gmail.com'

    licenseName = 'The Apache Software License, Version 2.0'
    licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
    allLicenses = ["Apache-2.0"]
}

apply from: rootProject.file('gradle/install-v1.gradle')
apply from: rootProject.file('gradle/bintray-android-v1.gradle')

You can now push your artifact on bintray using the gradle task bintrayUpload

./gradlew bintrayUpload

Your library is now available on your (bintray) maven !

 

Publish our library on Jcenter

The only task that now remains is to make bintray publish our library on Jcenter. To publish your library, just click on the project’s name, in our case ExpectAnim and then click on the button Add to JCenter

 

 

Once this request is accepted (an email will be sent to you), all developers will be able to use your library directly from JCenter

compile 'com.florentchampigny:expectanim:1.0.2'

 

Don’t hesitate to share a lot of your github libraries on Jcenter ! This reinforce the android community and highly helps developers 🙂

CONTRIBUTOR : I would like to thanks the all mighty Paul Vidal for his hard work in translating my article 🙂

Vous aimerez aussi...

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *