Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 455
Ryan Newsom Avatar asked Jun 09 '15 19:06

Ryan Newsom


3 Answers

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.

like image 180
Andrejs Avatar answered Sep 20 '22 14:09

Andrejs


Make the relevant classes into a library module - you already seem to know how to do that - and then use the Gradle Bintray plugin to upload it to JCenter.

Let's say you set group in build.gradle to com.ryan-newsom, version to 1.0 and the project name is android-log-in-screen.

(part of) android-log-in-screen/build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:0.6"
    }
}

apply plugin: 'com.jfrog.bintray'

group = 'com.ryan-newsom'
version = '1.0'

bintray {
    // Omitted for brevity, refer to the examples on GitHub.
}

You (or anyone else) can then use it in your project by adding the following:

(part of) other-project/build.gradle:

repositories {
    jcenter()
}

dependencies {
    compile "com.ryan-newsom:android-log-in-screen:1.0"
}

The library will then be pulled from JCenter and added to the classpath.

like image 23
Raniz Avatar answered Sep 23 '22 14:09

Raniz


You can package the library into an AAR format. It will also contain the resources you used in your login module. After that you can push the AAR library format to bintray (which is free, and allows you to setup your own repository).

Your collaborators can then access the library using a dependency that looks like:

compile 'com.newsom:awesome-login-screen:0.5'

Check this starter tutorial if you are using AndroidStudio/Gradle and would like to push it to bintray. https://github.com/jimcoven/android-bintray-kit

like image 35
Peanuts Avatar answered Sep 23 '22 14:09

Peanuts