android studio 包依赖

Android studio的Gradle非常的强大,其中的依赖管理就是非常好用,依赖只要一条命令。尝试了一下,有不正确的希望指点下

在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打包


  •   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值