How to create own gradle dependency library in Android Studio?
Asked Answered
W

4

10

For developing android applications by using Android Studio, generally we used to add dependencies in build.gralde instead of adding jars or libraries. Example given 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 my own gradle dependency library in Android Studio?

Womanhood answered 11/8, 2016 at 11:42 Comment(2)
You can create module for that.Marks
Do you need a library module?Kaif
A
10

I've already created my own library CustomSpinner and its Gradle's dependency is

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

I'm pretty sure that this is what you're expecting.

I made it using Jitpack.io and following steps in that great Medium article:

Create and Distribute your own Android Library after reading this post!

I don't want copy-paste what was here already said, so please patiently read this article.

Hope it will help

Accipiter answered 11/8, 2016 at 18:19 Comment(0)
T
1

You have to make your Android library (New project->Android library project), and upload it to bintray.

Toshikotoss answered 11/8, 2016 at 11:44 Comment(0)
H
1

JitPack is amazing for this. You can very simply make a library you have created available to anyone if it is hosted on GitHub (or other git host) and you add some config stuff Gradle and JitPack want. Have a look here at the JitPack publishing docs.

Homocentric answered 11/8, 2016 at 11:52 Comment(0)
K
0

You can 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'])
    }

Also you can use aar files defining a flatDir:

repositories {
    flatDir {
        dirs 'libs'
    }
}

then adding the dependency:

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

To create a library module just create a module in Android Studio and use in the module/build.gradle

apply plugin: 'com.android.library'

Then you can use it as:

  • a project (compile project(":mylibrary"))
  • you can build the aar file and use it as aar file
  • upload the library in a maven repository and use it as remote dependency
Kaif answered 11/8, 2016 at 14:32 Comment(1)
we want to create a own gradle dependency file which can be integrated in android studio project . For ex. compile "com.example.myowndepen" like this.Rigadoon

© 2022 - 2024 — McMap. All rights reserved.