把自己的库发布在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 init
git remote add origin https://github.com/yujinzhao123/testgithub.git
git add .
git commit -m "first commit"
git pull
git push -u origin master
//最好是提交时候加上版本号
git tag 1.0
git push
git 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,谢谢