How do android library publications work that can be easily imported by other people?

Using gradle, you can easily use third-party libraries. For example, the following allows me to use Retrofit in my application.

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

How it works? Where did the library come from? In general terms, how can I publish a library so that other people can import it like that?

Note: this is not a duplicate of Publishing a jar library for bintray using gradle https://stackoverflow.com/a/416829/ This question asked a particular question about one specific way to publish libraries.

+5
source share
1 answer

This is reported a lot in this guide .

How it works?

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

Where did the library come from?

By default, new versions of Android Studio import from JCenter. JCenter is a Maven repository managed by Bintray.

If you look at the Android Studio build.gradle , you will see the following lines

 repositories { jcenter() } 

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

In general terms, how can I publish a library so that other people can import it like that?

You need to create a Bintray account to upload to JCenter, since Bintray owns JCenter. The Bintray site is pretty easy to use compared to what Maven Central, the past Maven repository by default, used by Android Studio.

Once you have created the normal library module inside Android Studio, you will need to configure your build.gradle library module to configure it for Maven. Finally, you use a pre-baked script to load everything into Bintray.

+3
source

All Articles