Multi Module Android project in Eclipse

Recently there has been some discussion on the Maven Android Developer list about getting multi module projects working in Eclipse and IntelliJIDEA. I use IntelliJ IDEA every day and it works very well for me even though there are some improvements needed. Eclipse on the other hand is something I know my way around well enough, but just never warmed up to it. But I knew that I had the Maven Android Plugin Samples multi module project MorseFlash working at some stage. And it seemed like I am the only one. So I promised to document how I have it set up….

Since I did not even have a new Eclipse version installed on my current dev machine I installed Eclipse Helios, M2Eclipsethe Android Development Tools (ADT) and the M2Eclipse Android Integration as documented elsewhere and configured the path to Android SDK. I then pulled down the Maven Android Plugin Samples project from my github fork (in case I need to do any modifications) and started creating Java projects.

I created four(!) separate projects:

  1. one for the parent project (that pulls it all together, pom packaging), theoretically this should automatically create submodules (projects) and allow for different project setup for each. Unfortunately that is not the case.
  2. one for the library code project that is a pure Java (jar packaging) with unit tests running on the JVM
  3. one for the Android application code (with apk packaging)
  4. and one for the Android instrumentation testing code base (also apk packaging)

For each of those projects I enabled Maven dependency management and updated the configuration. If you need to find out more about M2Eclipse usage there is an excellent free book about M2Eclipse worth checking out.

The two Android projects also got the Android tools enabled automatically. If that fails right click on the project in the project explorer and click Android Tools – Fix Project Properties. After these steps you expanded project list should look like this:

With this setup you can run the whole project from the parent with the Maven tools in one click, just like it would happen on your continuous integration server. On the other hand the smaller scope projects allow you to run or debug the Android application

as well as the instrumentation tests on the emulator.

The only thing I had to change as compared to the project in the main release is that I had to add a res folder in the instrumentation project. Apparently the ADT needs that.

The library project is a plain Eclipse Java project and allows you to do all the things like running and debugging tests on the JVM (rather than on the emulator or device).

Enjoy reproducing the setup with your project and let me know if you run into any problems.

10 comments » Write a comment

  1. Excellent, just like the setup I am trying to get to work in the last few hours… I should work less and read blogs more 🙂


  2. I am trying to integrate apk signing using the info at
    To avoid any mistakes I have used your morseflash project. When I enable the signing profile, the tests fail with the following errors:
    Tests run: 6, Failures: 0, Errors: 5, Skipped: 0, Time elapsed: 0.333 sec <<< FAILURE!
    testSOS( Time elapsed: 0.19 sec <<< ERROR!
    java.lang.SecurityException: class ""'s signer information does not match signer information of other classes in the same package

    Thanks for your help.

  3. Pingback: Multi Module Android project in Eclipse « Simples Assim

  4. Hi manfred,

    I am getting a failure when trying to run the android junit tests. I click on morseflash-intrumentation and click Run As -> Android Junit Tests. This is after running the morseflash-app so the emulator is already running. I get in the eclipse console:

    Android Launch!
    adb is running normally.
    Could not find morseflash-instrumentation.apk

    How do you build the apk from eclipse as I can generate it when running maven from the command line. Just want to know the steps to running the morseflash-instrumentation module. Thanks in advance.

  5. hmm, I deleted the project then reimported and now it is working.

    Great post by the way!

  6. So after getting the morseflash working I imported my project that is working perfectly on the command line but when I have it in eclipse I follow the same steps and Run the app and I get a failure: “Failed to get project output folder!”. Any idea what this might be or what isn’t set?

  7. Not sure.. maybe see if you have a gen folder.. sometimes it needs that I found.. just to be there..

  8. The gen folder did exist under each submodule so that didn’t help =(.

  9. I no longer get the output folder issue, not sure how that cleared itself up. I’m now getting the “Conversion to Dalvik format failed with error 1”. I found posts that doing a clean clears this up which it did but then it comes right back. Any of you have run into this?

Leave a Reply

Required fields are marked *.