Android Publish Library

Tram Ho

Hi everyone, as an Android developer, you must have used the Library in Android. It can be an open library shared on the internet, or a library you create yourself.

Today I will share a little knowledge that I know related to publishing the Android library below to Remote (Online) and Local. With concepts like Publish Library, Local Maven, etc.

I. Concepts

First, what is Android Library?

  • The Android Library has the same structure as the Android Application Module.
  • The Android Library can include everything needed to build a build application: Source code, Resource files and an Android Manifest.
  • Instead, the App build file becomes an APK file, the Library builds to an AAR file (Android Archive) and uses it as a dependency of the Android app module.

II. Uses and Benefits

So, when to use Android Library? When using multiple applications where you have some of the same components, such as an activity, service, or user UI layout.

One of the benefits of using the Library that we can mention is as follows:

  • Accelerate development time.
  • Reuse of source code is divided into specific functions.

III. Access

  • Create and keep Library in Project
  • Create and Publish it to global to access them remotely or share them to other projects. Some common ways to publish Library to remote. Some places can be mentioned
    1. Jitpack.io
    2. Maven Publish
    3. Jfrog Bintray Artifactory ( Refer )

IV. Create and Publish Library

  1. Create Library: To create a library module you do the following: Go to File > New > New Module. In the Create New Module window that appears, click Android Library, then click Next. At the new Module creation screen that appears, select Android Library, then click Next.

image

After completing the operations to create the Lib and implement the necessary functions

image

You can also create a purely library project without the App Module attached by changing the plugin in the Gradle file to

plugins { id ‘com.android.library’ }

image

Since this article focuses on publishing Libraries, I just made a simple example of this Library’s content about the calculation function.

  1. Push Project to Github

image

-> git init -> git add -> git commit -m “calculated Library 1.0.0” -> git remote add origin “Paste Your-Repository-Address” -> git remote -v -> git push origin master

  1. Create and publish version release on Github

image

  1. Add the repository to Jitpack.io and click “Get it” the desired version.

image

  1. Apply to Main Project as instructed

image

Specifically in Project:

image

image

After Sync and Download the library. Now we can use it in code.

Next post. I will continue to share more about Local Maven and about the specific situation of using it.

Thanks everyone.

Source code :

Thư viện

Main Project

Share the news now

Source : Viblo