手把手指导把依赖库发布在github上

来源:互联网 发布:c语言32个关键字举例 编辑:程序博客网 时间:2024/05/17 13:40

把自己的库发布在github上是个很酷的事情,接下来就是实习以
compile ‘com.github.yujinzhao123:githubtest:1.0’
这种形式去添加自己的依赖库

第一步,创建库并配置
先随便创建一个个项目
这里写图片描述

这里写图片描述

把划线部分改为

apply plugin: 'com.android.library'apply plugin: 'com.github.dcendents.android-maven'

这里写图片描述

在注释掉 applicationId

这里写图片描述

在Project 的build.gradle加入

    dependencies {        classpath 'com.android.tools.build:gradle:2.3.0'        // 需要添加        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'    }

第二部,github上创建仓库

如果你会创建直接跳转到第三步,引用库

这里写图片描述

这里写图片描述

创建完回到android studio

这里写图片描述
开始创建git仓库

git initgit remote add origin https://github.com/yujinzhao123/testgithub.gitgit add .git commit -m "first commit"git pullgit push -u origin master//最好是提交时候加上版本号git tag 1.0git pushgit push --tags

还有一种方法就是直接在github上把空仓库下载下来 ,把项目复制进去,直接add就ok了。

第三步,开始引用

在需要引用的项目加入下面代码:

repositories {    maven { url = 'https://jitpack.io' }}compile 'com.github.yujinzhao123:githubtest:1.0'

地址是如何来的呢?按着你的实际情况配置
yujinzhao123(是我的github账号)
githubtest(在github上创建的项目名)
1.0(是库版本号)

按自己情况参照去替换,配置方式见下图

这里写图片描述

这时候已经引用完成 ,去Libraries看是否有咱们的库了

这里写图片描述

大工告成!

如果你按着步骤添加成功,请在留言区给我 Q个1,谢谢

1 0
原创粉丝点击