tribbloid tribbloid - 4 months ago 26
Android Question

Maven refuse to download aar packaged dependency from remote repository

I want to use this android dependency in my java program:

http://jcenter.bintray.com/com/o3dr/android/dronekit-android/2.9.0/


so I added all the plugins & repositories into my maven pom file:

<repositories>
<repository>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
<!--<snapshots>-->
<!--<enabled>false</enabled>-->
<!--</snapshots>-->
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<!--<snapshots>-->
<!--<enabled>false</enabled>-->
<!--</snapshots>-->
<id>central</id>
<name>bintray-plugins</name>
<url>http://jcenter.bintray.com</url>
</pluginRepository>
</pluginRepositories>

<build>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>4.1.0</version>

<extensions>true</extensions>
<configuration>
<sign>
<debug>false</debug>
</sign>
</configuration>
</plugin>
...


Then I add the dependency into the same file:

<dependency>
<groupId>com.o3dr.android</groupId>
<artifactId>dronekit-android</artifactId>
<version>2.9.0</version>
<type>aar</type>
</dependency>


But nothing happens, maven ignore it as if it doesn't exist, if I import its main package in a scala file and build it with
mvn clear install -U
, I get this error:


[ERROR] /home/peng/git-drone/dronespike/src/main/scala/Main.scala:1: object o3dr is not a member of package com

[ERROR] import com.o3dr.android._

[ERROR] ^


Question: What should I do to fix this problem?

Answer

Use Android packaging, e.g. <packaging>apk</packaging>.

If Maven couldn't download the artifact, it would complain much sooner in the build lifecycle. The problem is that artifact is downloaded, but not used. aar is not a standard Maven artifact, so Maven doesn't know what to do with it. Using it requires a third party plugin with extensions, hence usage of android-maven-plugin. Reading its documentation, it has some requirements to work properly. Specifically you didn't use android packaging as mentioned here:

usage of a supported packaging: apk, aar or apklib

Indeed, looking at the plugin source code it checks for android packaging before adding anything from aar to classpath.

Comments