Gradle依赖分类

1.依赖外部的本地二进制包(Localpackages)

添加本地jar

将jar包拖到libs目录下

添加依赖方法:

dependencies {

compile files('libs/foo.jar')

}

android {

...

}

添加本地aar(若内部库不想公开就作为添加本地库,否则可以上传到远端仓库)

将aar包拖到libs目录下

添加依赖方法:

android{

repositories {

flatDir {

dirs 'libs'

}

}

}

dependencies {

compile(name:'abc',ext:'aar')

}

2.依赖远端仓库(Remote artifacts)

添加依赖方法:

dependencies {

compile 'com.google.guava:guava:11.0.2'

}

仓库目录组成:packageName. artifactsId. version

远程仓库本地缓存目录:.gradle/caches/modules-2/files-2.1 + 仓库目录 / (.pom/.jar/.aar文件)

3.依赖库工程

添加依赖方法:

在build.gradle中添加

dependencies{

compile project(':food')

}

在settings.gradle中添加

include ':food'

project(':food').projectDir = new File('../food/library')

普通工程与库工程的区别

1.库工程:产出一个.aar包(其中整合了jar文件,原声的.so文件和资源文件 ex.manifest,res,assets)与jar的区别在于 jar不能包含资源文件

构建普通工程与库工程时使用不同的gradle插件

gradle配置文件中配置插件:

applyplugin:'com.android.library'

2.普通工程:产出一个apk

gradle配置文件中配置插件:

applyplugin:'com.android.application'

compile fileTree(dir: 'xxx', include: ['.jar', ".xxx"]):将某个目录下所有符合扩展名的文件作为依赖;

compile 'com.xx.xx:ProjectName:Version':配置Maven` 库作为依赖;在 Maven 库中心 可以搜索自己想用的库进行依赖;

compile project(':AnotherModule'):配置另一个 Module 作为本 Module 的依赖,被依赖的 Module 必须被导入到当前工程中;

compile files('xxx.jar'):配置某个 jar 包作为依赖。

git操作流程图


Gradle依赖分类_第1张图片

命令总结

Git常用基本命令

git init                                                        新建git代码库

git clonessh://zhangxi13@meituan         克隆代码库

git diff                                                       显示暂存区和工作区的差异

git branch 分支名称                                 新建一个分支,但停留在当前分支

git checkout 分支名称                             切换到指定分支

git checkout -b 分支名称                         新建指定分支并切换到指定分支

git log                                                      查看提交日志

git status                                                 显示有变更的文件及变更状态

git add                                                     添加文件到暂存区

git commit -m                                          提交暂存区到仓库

git amend                                                使用一次新的commit替代上一次提交

git push origin branchName                    上传本地分支的修改到远程仓库

git pull --rebase                                       拉取远程仓库代码到本地

git reset commitId                                   重置缓存区的改变与指定的commit保持一致,工作区不变

git stash                                                  暂存当前进行的工作

git stash pop                                           从git栈中读取对工作区的临时保存,恢复工作区内容

2.Gradle常用命令

./gradlew -v                                             版本号

./gradlew clean                                       清除app目录下的build文件夹

./gradlew build                                        检查依赖并编译打包

./gradlew assembleDebug                      编译并打Debug包

./gradlew assembleRelease                   编译并打Release包

./gradlew assemble渠道名                      只打指定渠道的Debug和Release包

你可能感兴趣的:(Gradle依赖分类)