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. Pingback: Multi Module Android project in Eclipse « Simples Assim

Leave a Reply

Required fields are marked *.