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

老子叫甜甜 提交于 2019-12-22 07:53:50

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/31022373/how-does-publishing-android-libraries-that-can-be-imported-easily-by-other-peopl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!