46

I code mostly in Java and use Maven for all of my projects. I do really love using Maven since it is easy to download the sources and documentations, and, more importantly, I don't need to keep the copy of the external libraries under my project source code folders.

I have started to develop an Android application and I found that the Android plugin for eclipse are terribly good. However, all provided examples are not maven projects so I do not know whether, if I use maven, I would still get all the functionalities from the Android plugin or whether there is any drawback from using Maven.

So the questions are:

  1. Do all features from Android plugin for eclipse still work?
  2. Is it going to be more difficult than using the normal build (I believe it is Ant but not certain)
  3. Any other drawbacks, e.g. the file size of the final application (Maven tends to bundle a lot of things together) or the difficulties of getting the latest libraries on maven repository (which is probably differnt for Android).

Please do not point to this maven support for android projects?

I would like an answer from experience developers. I already know that it is possible to use maven for an Android app. All I need to know is whether I should use it.

9
  • Do you need Maven? In other words, what functionality do you need? Maven only bundles the dependencies you define and the transitive dependencies, not sure what you concern regarding size is. Jan 8, 2012 at 15:32
  • 2
    I would like to use Apache Common libraries and Spring, for example, but I don't want to put the jar files in to my source code folder if not neccessary. Obviuosly, Spring depends on lots of things even if you don't need them you still include them when you use maven without knowing.
    – gigadot
    Jan 8, 2012 at 15:36
  • Maven includes only the dependencies you define, and their transitive dependencies (etc.) They're dependencies because they're required. You can tune your dependencies by explicitly declaring only the spring modules you use. Jan 8, 2012 at 15:39
  • 2
    @DaveNewton Yes, I do understand fairly well how to use maven. For this question, I do not want to discuss what I can do with maven. I would like to know if i should use maven with anndroid project.
    – gigadot
    Jan 8, 2012 at 15:48
  • Well, there seems to be some confusion as to what Maven includes, when, and why. If you're not able to control dependencies, then I'd say no, don't use it. Jan 8, 2012 at 15:50

6 Answers 6

35

My teams current task is to develop an Android app. Since it is a small app and also some kind of prototype we decided to evaluate Maven and the Android Eclipse plugin.

In short: After two developers spent three days, we were not able to gain the Android Eclipse plugin functionalities in our Maven project.

  • The R class was not updated according to our resources
  • We were not able to start the application directly from within Eclipse in the emulator and/or an attached device

Because of these issues which impeded our development sincerely we decided to develop the app without Maven. But if any of you knows how to fix these issues I would love to hear a solution!

2
12

If you want fast running tests you are nearly forced to use maven. As robolectric is the way to go then. And they said Roboletric is probably easier to set up via maven under Eclipse (they are using IDEA).

That said, did you read this post or that? And what error message exactly did you get?

Typical things I made wrong:

  1. use maven >= 3.0.3 ! And avoid that embedded thing in eclipse. (This was necessary only for robolectric, if I remember correctly)
  2. use ~/.m2/settings.xml as described on the robolectric page to set up the android path
  3. specify your android sdk also properly in the local.properties and under Preferences -> Android -> SDK location
  4. Further read this and that or just try the mavenized robolectric example itself, which worked for me. Import it as existing maven project.
  5. Install the necessary sdk (in my case 2.2_r3) via maven-android-sdk-deployer and

    export ANDROID_HOME=/path/to/android/sdk
    mvn install -P 2.2
    
  6. And did I mention this strange tool: m2e-android - not sure why one needs so many stuff with Eclipse ... here you can install it via software updates http://rgladwell.github.com/m2e-android/updates/master/m2e-android/

Hopefully I remembered all steps correctly. Good luck!

Update:

Switching back to normal Android stuff without maven under Eclipse as the IDE makes strange stuff: http://groups.google.com/group/robolectric/browse_thread/thread/ac814076c40d9df1

But the nice thing of this Maven adventure is that I can now easily test and debug my projects via NetBeans :)

1
  • 1
    "this post" is showing 404 error, can you please summarize it here?
    – Avinash R
    Feb 20, 2013 at 10:54
2

As we all know Android Devolopment migrated to Android Studio from Eclipse.

The Android Studio build system consists of an Android plugin for Gradle. Gradle is an advanced build toolkit that manages dependencies and allows you to define custom build logic.

The build system is independent from Android Studio, so you can invoke it from Android Studio or from the command line.

The Android Studio build system supports remote Maven dependencies. As you know, Maven is a popular software project management tool that helps organize project dependencies using repositories.

You can build your Android apps from the command line on your machine from Android Studio,thus by avoiding the mess of plugins as there in Eclipse.

Check out this tutorial for Building Android Apps with Maven.

Refer here for more about Gradle build

2

I recommend avoiding Maven for professional development on Android. Here's why:

  1. Google is investing time into keeping Android Studio integrated with Gradle. So maven is extra work right off the bat.
  2. If you have to use Maven (e.g. to manage dependent libraries), then Gradle can use the Maven plugin. See https://docs.gradle.org/current/userguide/maven_plugin.html
  3. By making maven your primary build tool you'll be downloading a massive amount of dependencies that you don't need and you're not sure where they come from. This goes against the notion that for your Android app, you ideally want just your code, and the android platform. In other words you're involving a lot of libraries/code you don't need.

In short, using maven as your Android build tool adds much more work than is necessary and creates a management nightmare (IMO).

Try this to illustrate:

  1. Heat a pan on a stove.
  2. Hold up a raw egg. Say "This is your android application."
  3. Crack the egg into the pan.
  4. Say "This is your android application on maven-with-rats-nest-dependency-tree-and-unknown-code-downloads-that-you-don't-need-anyway."
  5. Wait for the egg to burn to a crisp.
  6. Say, "This is your android application when the maven build packaged a useless or bad library with your Android application."
3
  • The question is several years old so things have changed a lot. At the time there was no Android Studio, it's just eclipse plugin. Even though the question was specifically about maven, I don't mind using any other dependency management tools if it works seamlessly with the IDE. Finally, I don't quite agree with your third point. You will certainly need to have everything you need in your android project (which is not always in the platform) in order to build it regardless of whether the build tools are used or not so using maven will not go against the notion. It is actually quite opposite.
    – gigadot
    Apr 13, 2016 at 0:52
  • i know this is an old answer, but i think rats-nest-dependency-tree problem will be there with gradle as well. May 21, 2021 at 19:16
  • I'm glad people find this post relevant even today! I think it's a design problem. I don't think the problem will ever go away until you have different people making decisions about Android Studio. I know that's controversial to say, but my goodness. Look at how groovy was added to the build system. It was the same type of mess. The managers approving changes on the build system change things because "they seems right at the time" but give little consideration to the downstream confusion they create. If they don't have time to properly explain things then they shouldn't be making changes. Oct 28, 2021 at 22:06
0

I have been able to use maven for android application development using Android Development Tools for Eclipse (Kepler) and Android for Maven Eclipse 1.0.1 (m2e-android). Follow these instructions http://rgladwell.github.io/m2e-android/. After you have created your new project with the android quickstart archetype modify your pom.xml. Add the android platform version. Eclipse (m2e) will report an error on the pom.xml on the android-maven-plugin declaration, to fix this issue follow alexander's response in Error in maven pom xml file: Building Android project. Then update the maven project using eclipse and that should be it.

0

From my own experience in Intellij. I used Maven as a build automation tool for my android development process. I started learn it with "Android Application Development with Maven" from Packtpub.

Not the answer you're looking for? Browse other questions tagged or ask your own question.