在githu上面开源自己的android library,让项目依赖使用攻略

使用过Android studio的朋友都知道怎么使用gradle去依赖别人写的开源库。比如compile 'com.android.support:appcompat-v7:25.3.0' 。在github上面,这种方式比比皆是。但是,我们怎么将自己写的开源库,放到github给大家依赖使用呢?其实很简单,接下来我们就看看如何操作。

1.首先,我们需要有一个library。
新建一个project,命名为 MineTools。然后我们新建一个module,选择Android Library,这里命名为ToolsLibrary。



2.在ToolsLibrary中新建一个XString工具类进行测试。代码如下:

package tool.yc.com.toolslibrary;

public class XString {

    /**
     *判断字符串是否为空
     * @param string
     * @return
     */
    public static boolean isEmpty(String string) {
        return string == null || (string.trim().length() <= 0);
    }

}
3.Library现在就等于搞定了。我们需要将它放在github上,这里就不介绍如何上传到github上了。
MineTools的github地址:https://github.com/kabuqinuofu/MineTools。点击releases,创建新版本。填好版本号(很重要),描述等信息,就可以推送版本了。




4.现在是时候使用JitPack了,打开网址后https://jitpack.io/,输入对应的项目的github网址,点击Get it获取需要被依赖的版本号。下面就会出现依赖的方式了。这样就大功告成啦~


5、在其他项目中使用依赖这个开源库方式如下:


到这里就结束了,是不是很easy!

猜你喜欢

转载自blog.csdn.net/lvshuchangyin/article/details/70157962