29

I want to create the library and have access to it through the Internet. In Android Studio (via Gradle) dependency may be added in this way:

In build.gradle (Module app):

dependencies { ... compile 'com.android.support:design:23.1.0' compile 'com.squareup:otto:1.3.8' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.j256.ormlite:ormlite-core:4.48' compile 'com.j256.ormlite:ormlite-android:4.48' ... } 

How can I add my own library in this way from github?

1

3 Answers 3

22

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:

Sign up to request clarification or add additional context in comments.

4 Comments

once you mark it as a compile time dependency, as above, and add it to the classpath, assuming it's also a run-time dependency, where is the JAR? It should show in build/libs/?
It is not a jar. You should find the library in build/intermediates/exploded-aar
I would love it if you could take a look at my question here. Following the simple JitPack instructions did not work there: stackoverflow.com/questions/44841415/specific-jitpack-issue
JCenter is not an option anymore, it seems.
14

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

For more information refer Gabriele Mariotti answer

4 Comments

Thanks for the quick response!
While this may answer the question, it is better to provide the actual information here and not just a link. Link-only answers are not considered good answers and will probably be deleted.
How can I do it if I want the library to take only a folder inside the library repository? ... Like github.com/username/library/folder .... Take what's inside 'folder' only? .. Is it possible? Thanks in advance
JitPack is very useful for public repositories. You can read some examples in this post: solidgeargroup.com/jitpack-public-repositories-android
2

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.

1 Comment

JCenter is not an option anymore, it seems.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.