How to create your own gradle dependency library in Android Studio?

To develop Android applications using Android Studio, we usually added dependencies to build.gralde instead of adding banners or libraries. Example below

 compile 'com.android.support:support-v4:23.4.0' compile 'com.android.support:recyclerview-v7:23.4.0' compile 'com.google.android.gms:play-services:9.2.1' 

How to create your own gradle dependency library in Android Studio?

+5
source share
4 answers

You need to make your Android library (project project New project-> Android) and load it into bintray.

+1
source

JitPack for this is amazing. You can simply create the library that you created accessible to everyone if it is hosted on GitHub (or another git host) and you add some Gradle and JitPack configuration files. See here in the JitPack publication docs.

+1
source

I already created my own CustomSpinner library and its Gradle dependency

 dependencies { compile 'com.github.piotrek1543:CustomSpinner:0.1' } 

I am sure that this is what you expect.

I did this with Jitpack.io and completed the following steps in this wonderful Middle article:

Build and distribute your own Android library after reading this post!

I do not want to copy-paste what has already been said here, so please read this article patiently.

Hope this helps

+1
source

There can be different types of dependencies in a project:

 dependencies { // Dependency on the "mylibrary" module from this project compile project(":mylibrary") // Remote binary dependency compile 'com.android.support:appcompat-v7:24.1.0' // Local binary dependency compile fileTree(dir: 'libs', include: ['*.jar']) } 

You can also use aar files defining flatDir :

 repositories { flatDir { dirs 'libs' } } 

then adding a dependency:

 dependencies { compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar') } 

To create a library module , simply create a module in Android Studio and use in module/build.gradle

 apply plugin: 'com.android.library' 

Then you can use it like:

  • project ( compile project(":mylibrary") )
  • you can create aar file and use it as aar file
  • Download the library to the maven repository and use it as a remote dependency
0
source

All Articles