Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include maven dependencies in eclipse "Run As -> Android Application" build

I develop an Android App using eclipse, the Android Development Tools (ADT) plugin and the maven-android-plugin.

Building and installing the application on the commandline (mvn install / adb install) works fine - especially it includes all dependencies specified in the pom.xml.

Deploying the application to Android via eclipse (Run as -> Android Application) does not automatically put the dependencies in the apk file - although specified in the pom.xml. I haven to explicit declare them in the eclipse project Build Path -> Libraries dialog.

Is there a way to make eclipse include the dependencies defined in the pom.xml without definig them twice in the project Build-Path -> Libraries?

EDIT: To clarify - the eclipse project includes a "Maven Dependencies" entry with all dependencies specified in the pom.xml. But these dependencies will not be included in the apk during install via "Run As -> Android Application". To include them, each one has to be extra added in the "Java Build Path -> Libraries" dialog. That's the pain!

like image 216
FrVaBe Avatar asked Feb 07 '11 16:02

FrVaBe


People also ask

How to add Maven dependencies to eclipse?

You can see that Eclipse has added Maven dependencies to java build path. Now, it is time to build this project using maven capability of eclipse. Right Click on consumerBanking project to open context menu. Select Run as option. Then maven package option.

What is Maven build in Eclipse IDE?

The Eclipse IDE provides support for the Maven build. This support is developed in the M2Eclipse project. It provides an editor for modifying the pom file and downloads dependencies if required. It also manages the classpath of the projects in the IDE.

How to manage dependencies in a multi-module Maven project?

In a multi-module Maven project, the dependency in the parent POM will be inherited by all sub projects. You can use dependencyManagement to consolidate and centralize the management of the dependencies' versions. Open your POM in the editor. Press Alt+Insert to open the Generate context menu.

How to build consumerbanking project using Maven in Eclipse?

Now, it is time to build this project using maven capability of eclipse. Right Click on consumerBanking project to open context menu. Select Run as option. Then maven package option. Maven will start building the project. You can see the output in Eclipse Console as follows −


1 Answers

I enabled the "Maven Dependencies"-checkmark at "Order and Export" within projects "Java Build Path" configuration and that seems to include all maven dependencies.

These dependencies (compile scope) are put into target/android-classes (and there are a lot of them, most commonly snapshots of internal projects, about 10). I had some other difficulties but that probably is related to the m2eclipse android integration plugin (at least on windows 7).

To get my properly set up maven project running I had to:

either import as maven project or...

clean previously created eclipse files (mvn eclipse:clean, mvn eclipse:eclipse), then enable maven dependecy resolution for that project, adept Java Build Path (gen -> target/android-classes, src -> target/classes, default output folder -> android-classes) and export Maven Dependencies (enable checkmark).

One thing i stumbled upon was this "Could not find *.apk!" error when running or debugging the android application. I could fix that by using a 32bit jdk for the used execution environment.

like image 55
rebouny Avatar answered Sep 24 '22 00:09

rebouny