How to create a library on Github and use it through gradle dependencies in Android Studio

二次信任 提交于 2019-11-28 17:04:32

Refer Jitpack is best to import your project or libs from Github to gradle

For more information refer Gabriele Mariotti answer

To achieve it you have some ways:

  1. publish your library (artifact) in central maven or jcenter.
  2. use a github repo and the jitpack plugin
  3. use a private maven

The point 2. is very simple.

Just push your codein github and modify the gradle script in the project where you want to use it.

Just add this repo tp your build.gradle

repositories {
        // ...
        maven { url "https://jitpack.io" }
    }

and the dependency:

dependencies {
        compile 'com.github.User:Repo:Tag'
    }

To publish a library in Central Maven or JCenter, it is very long to explain in an answer. Hovewer you can read these posts:

For a quick solution, as the others have said JitPack is probably the way to go. However, if you want to make your library available to a wider audience you should probably add it to jcenter since this is set up by default in Android Studio now. (Previously it was Maven Central.)

This post gives a detailed walkthrough of how to do it. The following is a summary:

  1. Create the Android library
  2. Test to make sure the library is usable locally
  3. Publish the library on Bintray
  4. Add the library to Jcenter

Then all people will have to do to use your library is add a one liner to their build.gradle dependencies.

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