How to make your library in Github importable to A

2019-09-06 10:27发布

问题:

I know that you can import Github libraries in android studios using Gradle:

compile 'com.github.someone.something:xxx-yyy:+'

What is that part: xxx-yyy:+ ? How do I build the project so that it can be imported with the previous line?

So far if I just upload a library and import it without that last xxx-yyy:+, I get an error that it is an invalid description. If I write a version then I get an error saying that it can't be found

回答1:

This is all handled via Maven by way of Gradle's Maven Plugin.

It's apparent that you've already grasped that someone is the Github user and something is their fork of the repo.

Here's the documentation for Maven dependency (it was easier to find and it is the same as compile)

http://maven.apache.org/plugins/maven-compiler-plugin/dependency-info.html

The xxx-yyy is the artifactId. Maven artifact IDs must match this regex: [A-Za-z0-9_\-.]+. Note that the artifact ID doesn't even need the dash. It could just be "library".

Finally the last bit is the version (I believe this is the tag in Github). + indicates you want the latest, but you could specify a specific version.



回答2:

To achieve it, you have to publish your library on Maven.

It requires some gradle knowledge. Here you can find some useful links.

EDIT 30/10/2015:

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

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:

  • Publish on JCenter

  • Publish on Central Maven. Another blog for Central Maven