创建一个从 git 导入的 gradle 依赖项 [英] Create a gradle dependency to import from git

查看:25
本文介绍了创建一个从 git 导入的 gradle 依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是在 Android Studio 中导入依赖项的方式.在这种情况下 okhttp:

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'
}

此时,如果我学习如何在 Android Studio 项目中创建依赖项并导入就足够了.

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

但如果可能的话,我希望将我的库托管在 git(github) 存储库上.这会很棒.

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

推荐答案

要实现它,您有一些方法:

To achieve it you have some ways:

  1. 在中央 maven 或 jcenter 中发布您的库(工件).

  1. publish your library (artifact) in central maven or jcenter.

使用 github 存储库和 jitpack 插件

use a github repo and the jitpack plugin

在本地 Maven 存储库(本地或私有)中发布 aar

publish the aar in a local maven repo (local o private)

第 2 点.很简单.把你的代码推到github上,在你要使用的项目中修改gradle脚本即可.

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.

只需将此存储库添加到您的 build.gradle

Just add this repo tp your build.gradle

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

和依赖:

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

在中央Maven或JCenter中发布一个库,在一个答案中解释很长.但是,您可以阅读这些帖子:

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

发布在 Central马文

这篇关于创建一个从 git 导入的 gradle 依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆