javaandroidapipackagingcode-sharing

How to create my own android library and host it


I'm working on creating a log-in screen to be used with multiple different android applications. What would be the best way to package it so that other people could use my log-in function on their apps. It would be preferred that it would auto-sync for them in-case we were to make changes. ***EDIT**** It seems packaging it into a library module is the best option. How does one go about uploading this module so that if we make an update to this module it will seamlessly update without having to pull from github for example.

Thanks!


Solution

  • If you've pushed your code to GitHub then sharing the library (aar) is easy with JitPack.

    Your users will just need to add the repository to their build.gradle:

    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
    

    and then your GitHub repository as dependency:

    dependencies {
        // ...
        compile 'com.github.YourUsername:Repo:Release'
    }
    

    The nice thing is that you don't have to upload your library. Behind the scenes JitPack will check out the code from GitHub and compile it. As you publish a new release on GitHub it becomes available for others to use.

    There is also a guide on how to prepare an Android project.