我为什么要包括依赖的Gradle作为`@ aar` [英] Why should I include a gradle dependency as `@aar`

查看:2692
本文介绍了我为什么要包括依赖的Gradle作为`@ aar`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要(或不应该)我包括依赖的Gradle作为 @aar

有什么好处/缺点如果有的话?

正如你可以看到我添加@aar到图书馆低于支持它。但一切似乎...

在这样做,以及工作

  {相关性
    编译文件树(导演:'库',包括:['的* .jar'])
    编译com.android.support:appcompat-v7:22.1.1
    编译com.google.android.gms:播放服务,地图:7.3 +。
    编译com.google.guava:番石榴:18.0'
    编译com.octo.android.robospice:robospice簧的Andr​​oid版本:1.4.14
    编译组织codehaus.jackson:杰克逊映射器-ASL:1.9.13
    编译com.mcxiaoke.volley:库AAR:1.0.0@aar
    编译de.psdev.licensesdialog:licensesdialog:1.7.0@aar
}


解决方案

图书馆可以以多种格式上传,你们中的大多数将使用时间的.jar .aar

当您不指定 @ 后缀,你会下载其中的库的默认格式(由它的作者定义,如果没有则的.jar )及其所有依赖一起。

 编译com.android.support:appcompat-v7:22.1.1

在指定 @ 后缀您执行下载的格式指定的库(这可能会或可能不存在)。这是有用的例如当笔者忘了指定该库是 .aar 和Maven(或gradle这个,不知道)会将其作为的.jar 默认情况下。当 @ 后缀指定该库的依赖不再下载,所以你必须手动保证。

 编译com.android.support:appcompat-v7:22.1.1@aar
编译com.android.support:support-v4:22.1.1@jar

要确保库的完整依赖关系树,而 @ 后缀指定你必须把它写在下面的方式下载:

 编译('com.android.support:appcompat-v7:22.1.1@aar'){
    传递=真
}

Why should (or shouldnt) I include a gradle dependency as @aar,

What are the benefits/drawbacks if any?

As you can see I added @aar to the libraries below that supported it. But everything seemed to work before doing that as well...

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.google.android.gms:play-services-maps:7.3.+'
    compile 'com.google.guava:guava:18.0'
    compile 'com.octo.android.robospice:robospice-spring-android:1.4.14'
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0@aar'
    compile 'de.psdev.licensesdialog:licensesdialog:1.7.0@aar'
}

解决方案

Libraries can be uploaded in multiple formats, most of the time you'll be using .jar or .aar.

When you don't specify the @ suffix, you'll be downloading the library in it's default format (defined by its author, if not then .jar) along with all its dependencies.

compile 'com.android.support:appcompat-v7:22.1.1'

When you specify the @ suffix you enforce downloading the library in the format you specify (which may or may not exist). This is useful e.g. when author forgot to specify that the library is an .aar and maven (or gradle, not sure) treats it as .jar by default. When the @ suffix is specified the dependencies of this library are no longer downloaded so you have to ensure that manually.

compile 'com.android.support:appcompat-v7:22.1.1@aar'
compile 'com.android.support:support-v4:22.1.1@jar'

To ensure the full dependency tree of the library is downloaded while the @ suffix is specified you have to write it in the following way:

compile ('com.android.support:appcompat-v7:22.1.1@aar') {
    transitive = true
}

这篇关于我为什么要包括依赖的Gradle作为`@ aar`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆