Android Maven Directory Structure

I have successfully installed & configured the M2E Maven plugin for Eclipse, along with Android SDK and ADT.

I want to create Android Projects from inside Maven, and so I found this article which gives instructions on installing the Android-Maven Plugin, and using a pre-existing Android-Maven archetype for initializing a project.

  • Remove large padding after hamburger (menu) icon in Android Toolbar?
  • how to limit seekbar
  • How to perform minification and obfuscation with the JACK compiler?
  • How to display popup on tapping overlay in android?
  • How to open a website when a Button is clicked in Android application?
  • Secure Asset/Media Folder through Auth Controller ? Laravel 5.2
  • I followed the instructions to a “T” and got the project “mavenified” beautifully.

    The only problem is, I’m used to (and really like!) the following typical Maven directory structure:


    However, this archetype doesn’t seem to contain a src/test/* directory, only a src/main/* tree. How do I get the test “subtree” in their?

    I guess I have two options:

    • Find a different Android-Maven archetype that contains it; or
    • Manually add the test/resources and test/java source folders myself

    I wouldn’t even know where to begin looking for the first option, and, quite frankly, I’m scared to try the second! I’ve heard that changing an archetype’s directory structure can really mess up the build.

    What would SO suggest? Is there anything obvious that I’m missing here? Thanks in advance!

    Related posts:

    android: smoothScrollToPosition() not working correctly
    How to make rotating menu
    Java - Comparing classes?
    Android ViewPager's onPageScrollStateChanged never gets called
    SecurityException: Parcel.readException coming from google analytics code
    Which Adapter to Use - BaseAdapter or ArrayAdapter?
  • Converting an Android application from a free/paid model to in-app paid unlocking
  • onLocationChanged is not called automatically
  • Android: Want to set custom fonts for whole application not runtime
  • The project references RTL attributes, but does not explicitly enable or disable RTL support
  • Removing All Child Views from View
  • How to start/ launch application at boot time Android
  • One Solution collect form web for “Android Maven Directory Structure”

    Check out the Notes section from their Getting Started page here:


    1. Do not put tests in src/test/java that you want to be run by the Android Maven Plugin. If you put your tests there, Maven runs them as normal JUnit tests in the JVM, with the JAR files that are accessible on the classpath, which includes the android.jar. Because the android.jar only contains empty methods that throw exceptions, you get exceptions of the form java.lang.RuntimeException: Stub!. Instead, the tests need to go in src/main/java, where they will not be run by Maven as tests during compilation, but will be included in the apk and deployed and run on the device (where the android.jar has method implementations instead of stubs).
    2. If you have JUnit tests that don’t call any Android APIs (directly or transitively), put them in src/test/java so JUnit runs them locally and more quickly than if run on the device.
    3. Make sure the Android Maven goal is set to jar-no-fork instead of test-jar-no-fork. Do this even for projects that only contain tests.

    The most suitable “test” subtree IMO is src/test/java, as stated in the second point, as long as you JUnit tests are purely POJO test which doesn’t involve any Android API call, you will be fine.

    I use src/test/java for all Robolectric junit test with instrumented test in separate Android test project, all managed by maven, everything works fine for me.

    Checkout the Sample MorseFlash project here, which include src/test/java as a example.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.