android studio 包依赖
2016-05-04 16:49
477 查看
Android studio的Gradle非常的强大,其中的依赖管理就是非常好用,依赖只要一条命令。尝试了一下,有不正确的希望指点下
在module的build.gradle中配置
依赖的方式有多种
1.依赖libs中的.jar包
compile file('libs/Mobcommons.jar')
2.依赖本地的Library
compile project (":library的名字")
3.依赖本地aar
compile (name:'xxxxx',ext:'aar')
4.网络依赖(本质是对maven仓库中内容依赖)
compile 'com.google.gson:gson:2.2.2'
其名字的组成为(组id+文件id+版本),由maven中定义
<groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.2.2</version> 如果引用的aar文件就需要在后面加上@aar
compilefileTree(dir:'d:\\localrepository',include:['*.jar'])
可能的有的需要加上
同时,如果你引入了一个aar但是有些包你是不需要的,可以通过exclude来去掉其中的包,类似于:
dependencies {
compile('org.test:3.1') {
//去掉依赖
exclude module: 'test1'
exclude group: 'org.test'
exclude group: 'org.test2', module: 'mytest'
}
}
除了编译的方式,还有其他的其中方式。(下面的provided 挺有用,依赖多个module的时候,可以方便管理)
Compile
compile是对所有的build type以及favlors都会参与编译并且打包到最终的apk文件中。
Provided
Provided是对所有的build type以及favlors只在编译时使用,类似eclipse中的external-libs,只参与编译,不打包到最终apk。
APK
只会打包到apk文件中,而不参与编译,所以不能再代码中直接调用jar中的类或方法,否则在编译时会报错
Test compile
Test compile 仅仅是针对单元测试代码的编译编译以及最终打包测试apk时有效,而对正常的debug或者release apk包不起作用。
Debug compile
Debug compile 仅仅针对debug模式的编译和最终的debug apk打包。
Release compile
Release compile 仅仅针对Release 模式的编译和最终的Release apk打包
在module的build.gradle中配置
dependencies { compile 'com.facebook.fresco:fresco:0.9.0+' compile files('libs/MobCommons.jar') }
依赖的方式有多种
1.依赖libs中的.jar包
compile file('libs/Mobcommons.jar')
2.依赖本地的Library
compile project (":library的名字")
3.依赖本地aar
compile (name:'xxxxx',ext:'aar')
4.网络依赖(本质是对maven仓库中内容依赖)
compile 'com.google.gson:gson:2.2.2'
其名字的组成为(组id+文件id+版本),由maven中定义
<groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.2.2</version> 如果引用的aar文件就需要在后面加上@aar
5.依赖本地文件夹中多个jar
compilefileTree(dir:'d:\\localrepository',include:['*.jar'])
可能的有的需要加上
repositories{ flatDir{ dirs 'libs' } }
同时,如果你引入了一个aar但是有些包你是不需要的,可以通过exclude来去掉其中的包,类似于:
dependencies {
compile('org.test:3.1') {
//去掉依赖
exclude module: 'test1'
exclude group: 'org.test'
exclude group: 'org.test2', module: 'mytest'
}
}
除了编译的方式,还有其他的其中方式。(下面的provided 挺有用,依赖多个module的时候,可以方便管理)
Compile
compile是对所有的build type以及favlors都会参与编译并且打包到最终的apk文件中。
Provided
Provided是对所有的build type以及favlors只在编译时使用,类似eclipse中的external-libs,只参与编译,不打包到最终apk。
APK
只会打包到apk文件中,而不参与编译,所以不能再代码中直接调用jar中的类或方法,否则在编译时会报错
Test compile
Test compile 仅仅是针对单元测试代码的编译编译以及最终打包测试apk时有效,而对正常的debug或者release apk包不起作用。
Debug compile
Debug compile 仅仅针对debug模式的编译和最终的debug apk打包。
Release compile
Release compile 仅仅针对Release 模式的编译和最终的Release apk打包
相关文章推荐
- SourceProvider.getJniDirectories
- 执行失败的任务 ': processDebugManifest'
- Android Studio使用教程(六):Gradle多渠道打包
- Android客户端程序Gradle如何打包
- Android Studio注释模板介绍
- Android Studio使用教程(四):Gradle基础
- Android Studio使用教程(五):Gradle命令详解和导入第三方包
- Win7安装gradle
- mac gradle 安装
- 关于Android Studio 和 Gradle的那些事儿
- Gradle这个黑盒子
- 收藏各种技术源码
- maven用户试用gradle
- 用Gradle 构建你的android程序
- 用Gradle 构建你的android程序-依赖管理篇
- Gradle 构建 android 应用常见问题解决指南
- Adnroid Studio Gradle 多渠道打包
- Gradle,构建工具的未来?
- Android Studio 使用 Gradle 打包 Jar-IT蓝豹
- Install Android Studio in Ubuntu 16.04 LTS