问题描述
我正在使用android-maven-plugin的Maven项目构建Android应用程序。在这个项目中,我正在使用新的beta数据绑定库。
I'm building an Android app from a Maven project that is using the android-maven-plugin. In this project I'm using the new beta data-binding library.
它包含在Android SDK的本地m2repository中(extras / android / m2repository)。此存储库中的库打包为aar类型。
It is contained in the local m2repository of the Android SDK (extras/android/m2repository). The libraries in this repository are packaged as type aar.
我可以在我的pom中添加依赖项,如下所示:
I can add the dependency in my pom like this:
<dependency>
<groupId>com.android.databinding</groupId>
<artifactId>library</artifactId>
<version>1.0-rc1</version>
<type>aar</type>
</dependency>
这似乎有效,但构建失败了:
This seems to work, but the build fails with this:
无法在项目演示中执行目标:无法解决项目com.simpligility.android:demo:apk:1.0.0的依赖关系:未能找到com.android.support:support-v4:jar:21.0 .3 in file:/// Users / eppleton / Java Libraries / android-sdk-macosx / extras / android / m2repository缓存在本地存储库中,直到android-local-extras的更新间隔已经过去才会重新尝试解析或更新被强制 - > [帮助1]
Failed to execute goal on project demo: Could not resolve dependencies for project com.simpligility.android:demo:apk:1.0.0: Failure to find com.android.support:support-v4:jar:21.0.3 in file:///Users/eppleton/Java Libraries/android-sdk-macosx/extras/android/m2repository was cached in the local repository, resolution will not be reattempted until the update interval of android-local-extras has elapsed or updates are forced -> [Help 1]
这个本地存储库中没有support-v4:jar是正确的,因为API版本20有支持-v4 :反而aar。
It's correct that there is no support-v4:jar in this local repository, since API version 20 there is support-v4:aar instead.
有没有办法让maven找到aar而不是jar?
Is there a way to make maven look for the aar instead of the jar?
Ps:对于我自己的本地构建,我有几个解决方法(例如重新打包为jar),但我更喜欢更通用的解决方案,因为我想在maven原型中共享配置,我不想r征求用户做大量的手工工作。现在这是我的最佳解决方案:
P.s.: For my own local builds I have several workarounds (e.g. repackaging as jar), but I would prefer a more generic solution, since I want to share the configuration in a maven archetype, and I don't want to require users to do a lot of manual work. Right now this is the best solution I have:
<dependency>
<groupId>com.android.support</groupId>
<artifactId>support-v4</artifactId>
<version>21.0.3</version>
<scope>system</scope>
<systemPath>${android.sdk.path}/extras/android/support/v4/android-support-v4.jar</systemPath>
</dependency>
但它并不是很好,传递依赖性已经解决,因为aar会更好。
But it's not really nice, transitive dependencies resolved as aar would be much nicer.
推荐答案
好的,找到了解决方案。我可以排除依赖关系,并将其直接添加为'aar'类型:
OK, found a solution. I can exclude the dependency, and add it again directly as type 'aar':
<dependency>
<groupId>com.android.support</groupId>
<artifactId>support-v4</artifactId>
<version>21.0.3</version>
<type>aar</type>
</dependency>
<dependency>
<groupId>com.android.databinding</groupId>
<artifactId>library</artifactId>
<version>1.0-rc1</version>
<type>aar</type>
<exclusions>
<exclusion>
<groupId>com.android.support</groupId>
<artifactId>support-v4</artifactId>
</exclusion>
</exclusions>
</dependency>
这篇关于Maven中的传递AAR依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!