首页 文章

Maven中的传递AAR依赖项

提问于
浏览
4

我正在使用android-maven-plugin的Maven项目构建Android应用程序 . 在这个项目中,我正在使用新的beta数据绑定库 .

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

我可以像这样在我的pom中添加依赖项:

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

这似乎有效,但构建失败了:

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

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

有没有办法让maven找到aar而不是jar?

Ps:对于我自己的本地构建,我有几个解决方法(例如重新打包为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>

但它不是很好,传递依赖性解决,因为aar会更好 .

1 回答

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

相关问题