16

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?

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
tribbloid
  • 4,026
  • 14
  • 64
  • 103
  • I think you should take a look at the .m2 directory of your central(jcenter) repository and check if this artifact actually exist on the correct path i.e. {.m2}/com/o3dr/android/dronekit-android/2.9.0/. If it does not exist there, you would need to add it – ritesh.garg Jun 19 '16 at 14:05

4 Answers4

8

Depending on the requirement from your maven version, based on what I faced before, you might have the need to add the configuration for release and snapshot. In my case, I was just able to get the lib once I specified these parameters:

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

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

without it, the dependency was not downloaded.

Banns
  • 576
  • 4
  • 12
  • Doesn't work and yield the same error, the dependency is still not included. – tribbloid Jun 19 '16 at 18:44
  • I have published my pom.xml onto github: https://github.com/tribbloid/dronespike/blob/master/pom.xml. Still, thanks a lot for your help! – tribbloid Jun 19 '16 at 19:03
8

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.

Anton Koscejev
  • 4,603
  • 1
  • 21
  • 26
  • Btw, doing this might trigger this warning from the plugin: Transitive dependencies should really be provided by Maven dependency management. We suggest you to ask the above providers to package their component properly. Things may break at compile and/or runtime due to multiple copies of incompatible libraries. – Anton Koscejev Jul 01 '16 at 09:18
  • Thanks a lot, I can confirmed that the aar file download from the bintray repo is valid and can be opened directly, could you be more specific? Namely, what needs to be set in the android-maven-plugin to read the aar? – tribbloid Jul 05 '16 at 02:46
  • Also, if you go to https://dl.bintray.com/3d-robotics/maven/com/o3dr/android/dronekit-android/2.9.0/ you will find that there is no apk packaging. And its not defined in dronekit sourcecode either – tribbloid Jul 05 '16 at 22:37
  • @tribbloid, this is a limitation of this plugin. In its extension (a "tighter" non-goal integration with Maven) it tries to identify android projects and only add `aar` contents to those. This is why adding `aar` dependency to other projects has no effect on Maven lifecycle - it'll be just info available to other plugins, such as distribution plugins. Unfortunately, it identifies android projects by checking packaging. In a project that uses `aar` you need to use one of the mentioned packaging. If you can't, you'll probably have to fork the plugin and use your own version and/or submit issue. – Anton Koscejev Jul 06 '16 at 08:20
  • I see, so only projects with aar output can use aar as classpath, those with jar/war/etc can not. And your quote from the documentation is a constraint on output rather than dependency. This is indeed a missing feature. I'll try to figure out if its easy to fix. – tribbloid Jul 07 '16 at 02:29
  • And this should be the canonical answer. Case concluded – tribbloid Jul 07 '16 at 02:29
3

Looking at the bintray repository from where the dependency is available, and check the repository settings via its Set me up option, your repositories coordinates are not correct, they should instead be:

<repositories>
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>bintray-3d-robotics-maven</id>
        <name>bintray</name>
        <url>http://dl.bintray.com/3d-robotics/maven</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>bintray-3d-robotics-maven</id>
        <name>bintray-plugins</name>
        <url>http://dl.bintray.com/3d-robotics/maven</url>
    </pluginRepository>
</pluginRepositories>

And indeed the effective target file is available via the URL:

https://dl.bintray.com/3d-robotics/maven/com/o3dr/android/dronekit-android/2.9.0/

Which respects the repository URL plus its Maven coordinates (groupId, artifactId, version).


Also note: do not reuse the repository id central, unless for specific reason, otherwise you would override the central (default) repository of your Maven build and all of your dependencies (and plugins) would only be fetched by the newely declared one.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • Still not working :-<. see https://codeship.com/projects/89488/builds/16226448 and https://github.com/tribbloid/dronespike/blob/master/pom.xml for compiling result – tribbloid Jul 05 '16 at 01:26
  • what if you try from command line the following command: `mvn dependency:get -Dartifact=com.o3dr.android:dronekit-android:2.9.0:aar -DrepositoryUrl=http://dl.bintry.com/3d-robotics/maven`? – A_Di-Matteo Jul 05 '16 at 09:14
  • The result looks good: BUILD SUCCESS Total time: 5.563 s This means the aar classpath resolving of the plugin is to be blame for right? – tribbloid Jul 05 '16 at 22:11
  • This means the dependency was downloaded correctly from that respiratory, now it should be in your maven local cache, hence the issue is not in the repository configuration indeed. – A_Di-Matteo Jul 06 '16 at 04:58
  • Indeed its in there and I can unzip it to see all the class file, now I have 2 answers indicating that the repository configuration is good and maven plugin has something missing. – tribbloid Jul 07 '16 at 02:17
0

sbt-android can handle this configuration.

build.sbt

androidBuildJar 
name := "yourproject" 
organization := "yourorganization" 
platformTarget := "android-24"
libraryDependencies +="com.o3dr.android" % "dronekit-android" % "2.9.0"

project/plugins.sbt

addSbtPlugin("org.scala-android" % "sbt-android" % "1.6.7")

Add publishing and resolver rules as necessary.

pfn
  • 1,820
  • 12
  • 11