How to import Android AAR dependencies using Maven in Eclipse?

妖精的绣舞 提交于 2019-12-12 11:15:32

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/24702508/how-to-import-android-aar-dependencies-using-maven-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!