使用github作为远程仓库repository,封装功能模块。之后,通过gradle dependency方式集成,方便调用。
1.github repository
登录github->new repository,作为maven仓库,得到远程地址,如:https://github.com/FreeLeo/AAR.git
2.安装git工具
下载地址:https://git-scm.com/downloads
选择一个文件夹,作为本地的repository,与github关联
使用【Git Bash Here】关联
git init
git add .
git clone https://github.com/FreeLeo/AAR.git
3.library
使用Android studio,建立Moudle.
build.gradle 中修改如下部分:
apply plugin: 'com.android.library' apply plugin: 'maven'
uploadArchives { repositories.mavenDeployer { def mavenRepositoryPath = file(getProperty('aar.Utils')) repository(url: "file://${mavenRepositoryPath.absolutePath}") pom.project { groupId "com.android.open.utils" artifactId "Utils" version 1.0 } }
Project Properties gradle.properties修改
aar.Utils=D:\\aar\\AAR
4.编译生成aar
使用命令:gradlew uploadArchives
若编译成功,会在配置的本地repository中生成。
5.git上传到github
将未缓存的改动添加到已缓存的活动;
提交
上传
之后到github确认是否上传成功。
6.远程依赖
6.1 复制git当前界面地址,并修改,添加到根目录build.gradle中,位置如下:
如https://github.com/FreeLeo/AAR 修改为https://raw.githubusercontent.com/FreeLeo/AAR/master
allprojects { repositories { jcenter() maven { url "https://raw.githubusercontent.com/FreeLeo/AAR/master"} } }
6.2 在需要引用的module的build.gradle dependencies中添加:
compile 'com.android.open.utils:Utils:1.0'