How to import Android AAR dependencies using Maven in Eclipse?
Asked Answered
S

3

5

Note : I am using Maven 3.2.2, Eclipse Luna

This is the dependency in my pom.xml that uses Android AAR archive

<dependency>
    <groupId>com.github.gabrielemariotti.cards</groupId>
    <artifactId>library</artifactId>
    <version>1.7.3</version>
    <type>aar</type>
</dependency>

I can see the classes installed in target/classes folder.

But when I try to use the classes in the AAR, Eclipse is showing class cannot be resolved. I have no problem using classes added by JAR dependencies in pom.xml

Any help would be greatly appreciated.

Shred answered 11/7, 2014 at 16:34 Comment(4)
Have you edited the pom.xml file outside Eclipse? If yes, have you already tried with a Project -> Clean... ?Allieallied
Yes I have tried Project -> CleanShred
Just to have some more clues: 1. are you using M2E? 2. Can you see the AAR in Package Explorer -> Properties -> Java Build Path -> Libraries -> Maven Dependencies? 3. When you say "Eclipse is showing class cannot be resolved" you mean that the auto-completion doesn't show your class?Allieallied
@Allieallied Yes, I am using M2E, the AAR does not appear in the Maven Dependecies, yes, I mean that eclipse auto-completion does not show the class to import. I also checked out the my maven local repository at ~/.m2. It has the AAR installed in ~/.m2/repository/com/github/gabrielemariotti/cards/library/1.7.3Shred
L
6

At this present moment in time the m2e-android plug-in cannot support AAR files because the ADT development team have not added AAR support to the Eclipse ADT plug-in.

This is an outstanding issue:

https://github.com/rgladwell/m2e-android/issues/177

Liken answered 12/7, 2014 at 9:46 Comment(5)
Thanks for the info. This is a good plug-in. Hoping that support for AAR could be added ASAP. =)Shred
They were suppose to add this years ago... so I guess they wont :(Waadt
Who do you mean by "they"?Liken
Man are they ever going to fix this?Temblor
I'm also facing the same problem.. Trying to use AAR in Eclipse. Since I'm familiar with the @RicardoGladwell answer in the link above I didn't expect it to work in Eclipse.. However I aslo see that the project is not build by Maven (using mvn clean install). I see errors like "cannot find symbol". I thought that mvn would work since Maven Android Plugin officially support aar. simpligility.github.io/android-maven-plugin/aar.htmlKleist
C
0

After doing some online research, it seems there is no easy and straightforward way to do this. AAR is not a standard format and not supported by Eclipse. It will take a hack in order to get this to work. Here are three options with various levels of experience:

  • The Android SDK comes with the source to standard Android libraries in $ANDROID_HOME/extras/android/support. (Alternatively, if you can grab the source of whatever third-party library you’re using, that should work as well.) Import that library into your workspace as a separate project and set its properties to identify it as an Android library. Then, in the Android section of your project’s properties, add a library reference. This won’t take any effect outside of Eclipse (e.g. it won’t affect a Maven command-line build), but it will allow Eclipse to resolve references to that library. I’ve done that successfully for some v7 support libraries.
  • An AAR is essentially a zip file containing a classes.jar and a bunch of Android-specific resources, all of whic appear to be in a format that Eclipse can work with. If you’ve built agains that library at least once, grab it from your M2 cache (~/.m2/repository). Unpack the AAR into a directory of your choice (you will need to keep it around for as long as you are planning to build against that library). Add the classes.jar to your project’s classpath. This should let Eclipse resolve any Java references, but not Android-specific references (such as styles).
  • Combining the two approaches above, you can also try importing the unzipped AAR as a project and adding that to your project. This should allow Eclipse to resolve not only Java references but also Android-specific ones. You will need to experiment a bit with that one, as the project will have no Java sources but instead a JAR which needs to be included in the build path.
Clementius answered 15/6, 2021 at 17:57 Comment(0)
G
-1

You can try my Maven plugin https://bitbucket.org/komo81/eclipse-aar-maven-plugin.

Plugin generates Eclipse projects for Android AAR dependencies to easy import in Eclipse. It works together with https://github.com/simpligility/android-maven-plugin, which unpacks Android AAR dependencies into /target/unpacked-libs directory. This plugin takes these unpacked dependencies and modifies them to easy import in Eclipse for ADT plugin. So plugin makes following changes during 'generate' goal execution:

  • copies AAR project directories from input directory to output directory
  • moves /classes.jar to /libs/project_name.jar
  • moves /jni directory to /libs
  • creates .project, .classpath, .settings/org.eclipse.jdt.core.prefs and project.properties files
  • creates /gen directory
  • add references to root project.properties file

Usage

Add plugin to your pom.xml

<build>
  <plugins>
    <plugin>
      <groupId>org.bitbucket.komo81</groupId>
      <artifactId>eclipse-aar-maven-plugin</artifactId>
      <version>1.0.0</version>
      <executions>
        <execution>
          <goals>
            <goal>clean</goal>
            <goal>generate</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
<pluginRepositories>
    <pluginRepository>
        <id>dropbox</id>
        <url>https://dl.dropboxusercontent.com/u/52711537/maven-repo/</url>
    </pluginRepository>
</pluginRepositories>

Run mvn compile. Import generated projects from /eclipse-aar directory into Eclipse via 'Import -> Existing projects into Workspace'.

Plugin goals documentation

http://komo81.bitbucket.org/eclipse-aar-maven-plugin/plugin-info.html

Germanism answered 24/11, 2015 at 15:19 Comment(5)
Generally, links to a tool or library should be accompanied by usage notes, a specific explanation of how the linked resource is applicable to the problem, or some sample code, or if possible all of the above.Murther
This plugin is outdated: [ERROR] Plugin org.bitbucket.komo81:eclipse-aar-maven-plugin:1.0.0 or one of its dependencies could not be resolved: Could not find artifact org.bitbucket.komo81:eclipse-aar-maven-plugin:jar:1.0.0 in central (jcenter.bintray.com)Concavity
Plugin is not outdated, you have to add section <pluginRepositories> to your pom.xml as described.Germanism
It is not working as the dropbox URL no loger seems to exist. I filed an issue for this. Furhter I have cloned and compiled the plugin myself - had to fix the build for recent JDK. Now, I can use the plugin but it does not seem to work. Here is my resume about android development: github.com/m-m-m/ui-android/wiki/android-sucksGammer
Hello, sorry but this plugin is no longer maintainted.Germanism

© 2022 - 2024 — McMap. All rights reserved.