Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transitive AAR dependencies in Maven

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.

It is contained in the local m2repository of the Android SDK (extras/android/m2repository). The libraries in this repository are packaged as type aar.

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:

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]

It's correct that there is no support-v4:jar in this local repository, since API version 20 there is support-v4:aar instead.

Is there a way to make maven look for the aar instead of the jar?

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>

But it's not really nice, transitive dependencies resolved as aar would be much nicer.

like image 672
monacotoni Avatar asked Aug 15 '15 08:08

monacotoni


1 Answers

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>
like image 126
monacotoni Avatar answered Nov 13 '22 13:11

monacotoni