After upgrading to Eclipse 4.4 (Luna) I faced with java.lang.NoClassDefFoundError
exception for classes contained in Maven dependencies while trying to run my Android application using "Run As"->"Android Application". plugin installed. I tried to enable export of Maven container ("Properties"->"Java Build Path"->"Order and Export"->tick "Maven Dependencies") but it doesn't help because all dependencies were included to build, including dependencies in provided
and test
scopes.
While Maven Android Plugin is allowing to do full cycle development from compilation to deployment and run application using single command mvn clean install android:deploy android:run
, Eclipse ADT does incremental compiling and packaging, which is significantly faster.
To allow Eclipse ADT use Maven dependencies for compiling and running Android application, trick with libs
project directory was used. Just add to pom.xml
copying of runtime dependencies to libs
directory using Maven Dependency Plugin:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/libs</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
...
</build>
[...]
</project>
Don't forget to enable exporting of copied dependencies by ticking "Properties"->"Java Build Path"->"Order and Export"->"Android Private Libraries":
To keep libraries in actual state, add libs
to Maven Clean Plugin configuration:
<project>
[...]
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.6.1</version>
<configuration>
<filesets>
<fileset>
<directory>libs</directory>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
[...]
</project>
Now just do mvn clean install
and all runtime dependencies will be accessible by ADT. Surely it's rather hack than solution, and it sucks, but it works at least. :)
Comments