Creating an Android library using Android Studio

As an Android developer, we use a lot of third parties libraries which are available on Github and it’s easy.It saves our time and reduces the complexity of the code.It’s fun to use.But have you ever thought of creating one for yourself? if yes, then you are at the right place.

Let’s start!

1.Create a package on Bintray

First of all. You need to create a package on bintray. To do so, you need a bintray account and create a package on the website.

  • Register for an account on bintray.com. (Follow the instructions)

signinpage

  • Once registration is completed, login to the website and click on Add a new repository 

adding

  • In repository, input name as maven(we can give any name)  and select type as maven
  • We can select license also like apache etc
  • Click on Create

addnewrepo

  • Click on Add New Package to start creating a new package for our library.

addingpackage

  • Enter all of that required information

packagedetails

  • Although there is no rule on how to name the Package Name but there is some name convention. Just set all of the characters to lowercase and separate each word with a hyphen (-), for example, library. Once every required field is done, click on Create Package to finish.
  • The website will redirect you to Edit Package page. Click at package’s name under Edit Package text to enter package’s details page.

mainpage

  • Done! We now have our own Maven Repository on Bintray which is ready to be uploaded the library.

lastpage

2.Create an android studio project

  • Create a new project in Android studio
  • Give your project name and click finish
  • Again go to File>New>New module

687474703a2f2f696d6775722e636f6d2f68627633456f342e706e67

  • Select android library

687474703a2f2f696d6775722e636f6d2f784455426a59672e706e67

  • Give your android library name

687474703a2f2f696d6775722e636f6d2f6b4e4b503531662e706e67

  • Click finish
  • Now go to build.gradle(Project) and add these dependencies
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

like

dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
  • Again come to build.gradle(library) and add and modify according to your data
ext {
    bintrayRepo = 'maven'
    bintrayName = 'LogR'

    publishedGroupId = 'com.colorssoftware.library' //this is GROUPID
    libraryName = 'library' //this is your library name
    artifact = 'library' //this is ARTIFACTID

    libraryDescription = 'A login and registration library for android'

    siteUrl = 'https://github.com/ColorsSoftwarePvtLtd/Framework-Android'
    gitUrl = 'https://github.com/ColorsSoftwarePvtLtd/Framework-Android.git'

    libraryVersion = '1.0.0' //this is version name

    developerId = 'braj24'
    developerName = 'Braj Bhushan Singh'
    developerEmail = 'braj.nmit@gmail.com'

    licenseName = 'The Apache Software License, Version 2.0'
    licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
    allLicenses = ["Apache-2.0"]
}
  • then add this at the bottom
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'

We will discuss something about ARTIFACT_ID, GROUP_ID and VERSION

Let’s take one famous library, Picasso

compile 'com.squareup.picasso:picasso:2.5.2'

In this library,

com.squareup.picasso - GROUP_ID
picasso -  ARTIFACT_ID
2.5.2 -  VERSION 

It is written as compile ‘GROUP_ID: ARTIFACT_ID: VERSION’

  • Now open local.properties(SDK Location)
  • and put
bintray.user=your bintary username
bintray.apikey=your api key(we can get this bintray profile settings)
bintray.gpg.password=1234(optional)

  • Now open android studio terminal
  • Run

./gradlew install 

buildsucessful

  • After BUILD SUCCESSFUL
  • Again run

./gradlew bintrayUpload

bintrayupload

  • After some time it will show BUILD SUCCESSFUL
  • And we are done.
  • Now open bintary repository.we will get all the details like version no.Click on version no.All the files will be available in file tabs.

packagefile

  • At last click on Add to jcenter and in another tab just click send(no comment is required)

addtojcenter

  • After 3-4 hours we will get one email like we can use our library after verification from bintray.

linkjcenter

  • Now we can use our library as compile ‘GROUP_ID: ARTIFACT_ID: VERSION

 

Happy coding!
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s