Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use Maven for an Android App? [closed]

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.

like image 489
gigadot Avatar asked Jan 08 '12 15:01

gigadot


People also ask

Can you use Maven for Android?

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.

Why Maven is used in Android?

Maven will do the rest for you when you build (download to local cache if not already existing, fetch dependencies, javadoc etc). Even if you were to copy your project to another PC without the JAR's, delete the JAR's etc, if Maven is present it will re-download them automatically when you build.

What is the purpose of using Maven?

Maven's primary goal is to allow a developer to comprehend the complete state of a development effort in the shortest period of time. In order to attain this goal, Maven deals with several areas of concern: Making the build process easy. Providing a uniform build system.

Can I use Maven for Android Studio?

Building Android applications with MavenYou only have to install Maven, write a correct pom. xml file and issue the commands to Maven to build, install and run your application. The following will build your Android application via Maven.


4 Answers

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!

like image 95
Michael Avatar answered Oct 12 '22 17:10

Michael


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 :)

like image 38
Karussell Avatar answered Oct 12 '22 16:10

Karussell


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

like image 2
Subin Chalil Avatar answered Oct 12 '22 15:10

Subin Chalil


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."
like image 2
Coder Roadie Avatar answered Oct 12 '22 17:10

Coder Roadie