Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
757 views
in Technique[技术] by (71.8m points)

java - Create a gradle dependency to import from git

This is how import dependencies in Android Studio. In this case okhttp:

dependencies {
    compile 'com.squareup.okhttp:okhttp:2.5.0'
} 

I would like to import a dependency created by myself. For example:

dependencies {
    compile 'my_library:1.0.0'
}

At this point if I learn how to create a dependency and import in Android Studio project would be enough.

But I would like host my library on a git(github) repository if possible. This would be awesome.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. publish the aar in a local maven repo (local o private)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...