Glitch
4 min readJun 6, 2021

--

Creating an Android SDK library

An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest.

Now I will tell you how having something similar you can share it with the world. We’ll start with creating a module, then upload it to GitHub and make public using Bintray.

Creating a module in Android Studio

1. Create a project in Android Studio. For your convenience rename app module into sample. It will contain your library usage example.

2. Create a new module:

3. Choose Android Library type:

4. Enter a name — I will be using bottomtablayout.

5. Now settings.gradle should look like this:

include ':sample', ':bottomtablayout'

6. In the sample module add a dependency into build.gradle:

compile project(':bottomtablayout')

It is a temporary solution since currently our library is local.

7. Now you can write your own library (or move an existing code into it) and test it in a sample module.

8. When your library is ready, upload it to your GitHub account.

9. Write a readme tutorial.

Adding library to Bintray

1. If the library is ready, it’s time to show it to the whole world! Get yourself a Bintray account.

2. Add a dependency into a build.gradle file of the project:

dependencies {
...
classpath 'com.novoda:bintray-release:0.3.4'
}

3. In build.gradle file of library module (bottomtablayout in our case) apply a plugin:

apply plugin: 'com.novoda.bintray-release'

In the same file:

publish {
artifactId = 'contentmanager'
publishVersion = '0.1.1'
desc = 'Library that helps a few lines of code to get pictures and video from the android file system, or ures cloud, as well as the camera device.'
licences = ['Apache-2.0']
uploadName='ContentManager'
}

Where:

  • groupId — a package (can be different from the package of the module). I recommend to name groupId as follows: com.github.<username of your github account> since when you log in to upload your library to Maven Central you’ve got to be the owner of the domain used in the name groupId.
  • artifactId — module name.
  • publishVersion — version of publication.
  • desc — library description.
  • licences — licence.
  • uploadName — library name.
  • website — link to project GitHub.

4. Now you need an API Key of your Bintray account. Go to your Bintray profile page:

5. Find Edit button and click it:

6. Now go to API Key:

7. Put your key into a safe place.

8. Open Android Studio terminal and run:

gradlew clean build bintrayUpload -PbintrayUser=<юзернейм на bintray> -PbintrayKey=<api ключ с bintray> -PdryRun=false

9. Wait for library to be assembled and uploaded to server.

10. Now go to Bintray website and find a page of your newly added library.

11. Currently if you want to use a library you’ve got to add a link to the repo into build.gradle project file:

repositories {
maven {
url "http://dl.bintray.com/<username>/maven"
}
}

But can we simplify the last step somehow? Sure, we can!

Adding Android library to jCenter

Recently jCenter became a default Android repository (previously Maven Central was used). Still, adding your library into jCenter is very simple.

1. On your library page click add to jCenter and send a query for adding your library. Within 24 hours your library will be added to jCenter and you will get an email notification.

2. Now you can connect your library via build.gradle of the module by adding a respective dependency which you have set.

Congratulations! Now you know to create libraries which can be worked and used by others

--

--