Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does publishing android libraries that can be imported easily by other people work?

It is possible to easily use third party libraries with gradle. For example, the following allows me to use Retrofit in my app.

   dependencies {
       compile 'com.squareup.retrofit:retrofit:1.9.0'
   }

How does this work? Where does the library come from? In general terms, how would I go about publishing a library so that other people can import it like this?

Note: this is not a duplicate of Publish jar library to bintray using gradle/publish-jar-library-to-bintray-using-gradle. That question was asking a spefic question about one particular way to publish libraries.

like image 815
Justin Watkins Avatar asked Sep 27 '22 12:09

Justin Watkins


1 Answers

Lots of this is answered in this tutorial.

How does this work?

Gradle imports the libraries from a Maven repository. The Maven repository can contain both regular .jar files and regular .aar files.

Where does the library come from?

By default, new versions of Android Studio import from JCenter. JCenter is a Maven Repository run by the company Bintray.

If you look at your Android Studio project's build.gradle, you'll see the following lines

repositories {
    jcenter()
}

This tells gradle where it should look when attempting to import com.squareup.retrofit:retrofit:1.9.0.

In general terms, how would I go about publishing a library so that other people can import it like this?

You need to create a Bintray account in order to upload to JCenter since Bintray owns JCenter. Bintray's website is pretty easy to use compared to what Maven Central, the past default Maven Repository used by Android Studio.

After you've created a normal Library module inside Android Studio, you'll need to hand tweak your library module's build.gradle file in order to configure it for Maven. Finally, you use a pre-baked script to upload everything to Bintray.

like image 146
Brian Attwell Avatar answered Oct 06 '22 19:10

Brian Attwell