2015-08-15 248 views
4

我正在使用android-maven-plugin从Maven项目构建Android应用程序。在这个项目中,我使用了新的测试版数据绑定库。Maven中的传递式AAR依赖关系

它包含在Android SDK(extras/android/m2repository)的本地m2repository中。此存储库中的库打包为aar类型。

我可以添加依赖于我的POM这样的:

<dependency> 
     <groupId>com.android.databinding</groupId> 
     <artifactId>library</artifactId> 
     <version>1.0-rc1</version> 
     <type>aar</type> 
    </dependency> 

这似乎是工作,但构建失败,这样的:

无法执行的项目演示的目标:无法解析的依赖for project com.simpligility.android:demo:apk:1.0.0:未能在file:/// Users/eppleton/Java Libraries/android-sdk中找到com.android.support:support-v4:jar:21.0.3 -macosx/extras/android/m2repository已缓存在本地存储库中,直到android-local-extras的更新时间间隔过去或强制更新才会重新解析分辨率 - > [Help 1]

在本地存储库中没有support-v4:jar是正确的,因为API版本20中存在support-v4:aar。

有没有办法让maven找aar而不是jar?我有几个解决方法(例如重新打包为jar),但我更喜欢更通用的解决方案,因为我想在maven原型中共享配置,而且我不想要求用户做大量的手动工作。现在,这是我有最好的解决方案:

<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> 

但它不是很好,传递依赖关系解决作为阿尔会更好。

回答

5

好的,找到了解决办法。我可以排除依赖关系,并直接将其重新添加为类型'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>