添加一个符号为ext的库:'aar'或@aar不会导入传递依赖项

问题描述:

我已将白色标记为应用程序,将应用程序转换为库,并且我有一个配置文件传递给库更改颜色,添加新的加载动画,更改一些文本等。库具有上面列出的所有依赖关系。当我将库导入新应用程序时,由于新应用程序只是库的一种变体,因此它将不会编译,除非我也导入这些依赖项。添加一个符号为ext的库:'aar'或@aar不会导入传递依赖项

我添加使用自定义库:

compile(group: 'com.lib.libcore', name: 'libcore', version: '1.0.35', ext: 'aar', classifier: '')

build.grdle,但它仍然迫使我包括所有从库的依赖关系。

我想知道是否有人知道为什么我需要在我的应用程序中包含来自自定义库的所有依赖项。

所以我有这些依赖关系:

compile 'com.android.support:multidex:1.0.1' 
compile 'com.android.support:appcompat-v7:25.3.1' 
compile 'com.android.support:support-v4:25.3.1' 
compile 'com.android.support:design:25.3.1' 
compile 'com.squareup.okhttp3:logging-interceptor:3.5.0' 
compile ('com.google.firebase:firebase-core:11.4.2') 
compile ('com.google.firebase:firebase-messaging:11.4.2') 
compile ('com.google.firebase:firebase-crash:11.4.2') 
compile ('com.google.firebase:firebase-invites:11.4.2') 
compile 'com.google.android.gms:play-services-location:11.4.2' 
compile 'com.google.android.gms:play-services-gcm:11.4.2' 
compile 'com.google.android.gms:play-services-maps:11.4.2' 
compile 'com.google.android.gms:play-services-auth:11.4.2' 
compile 'com.google.android.gms:play-services-places:11.4.2' 

当我使用gradle这个导入库,我需要在应用程序文件的gradle所有这些依赖关系为好。有没有人知道我可以从应用程序gradle中删除它,而不会失败?

+1

你在说什么图书馆? – Raghunandan

+0

@Raghunandan基本上我用白色标记了一个应用程序,将我的应用程序转换为一个库,并且我有一个配置文件传递给库以更改颜色,添加一个新的加载动画,更改一些文本等。库包含所有上面列出的那些依赖关系。当我将库导入新应用程序时,由于新应用程序只是库的一种变体,因此它将不会编译,除非我也导入这些依赖项。我试图找出如何不必两次导入依赖关系。 – Mikerizzo

这是因为您正在使用的符号ext: 'aar'

compile(group: 'com.lib.libcore', name: 'libcore', version: '1.0.35', ext: 'aar', classifier: '') 

这是同样的:

compile('com.lib.libcore:libcore:[email protected]') 

您可以检查official doc:

An artifact only notation creates a module dependency which downloads only the artifact file with the specified extension. Existing module descriptors are ignored.

这意味着你想只下载AAR神器,并没有依赖关系。

只需删除依赖项中的符号ext: 'aar'@aar即可。

+0

我现在遇到了解决错误的失败,当我尝试同步gradle时 – Mikerizzo

+0

什么是确切的错误信息?由于您使用的是Firebase库v.11.4.2,因此您必须使用添加maven google回购协议。 –

+0

错误:(136,13)无法解析:com。库。 libcore:libcore:1.0。35 – Mikerizzo

如果你想在你的项目中使用自定义库,你必须将其添加为依赖于你的的build.gradle(模块:APP)

+0

我在build.grdle中使用compile(group:'com.lib.libcore',名称:'libcore',版本:'1.0.35',ext:'aar',classifier:'')添加了自定义库,但它仍然迫使我包括来自库的所有依赖关系 – Mikerizzo

+0

我认为你应该添加库中的所有依赖关系来使用它 – danish