The Ultimate 10 step setup: Eclipse (STS) + Android + Maven
After a lot of struggling and frustration getting Android SDK, Maven and Eclipse working together I have decided to create the ultimate tutorial. I have not found a single page online describing how all the pieces should work together. I have only found bits and pieces of information at various sites. So this should be a post merging it all together. Read on if you want to know how I got it working. My goal is to create a post containing everything from installation requirements to getting the first project up and running.
1. Initial setup
The first step in this process is of course downloading the IDE. I am currently using SpringSource STS version 2.5.2.SR1. SpringSource is an IDE based on Eclipse adapted for the SpringFramework (download here). I am sure the newest version of Eclipse should work fine as well. You must also check that Maven is installed, I am using version 2.2.1. I am working on an Ubuntu machine so some steps may differ if you are using Mac or Windows.
2. Downloading the Android SDK
The second step is to download and unpack the Android SDK. It can be found here. Unpack it and remember where you put it. You will need the path later on when you install the Android ADT plugin in SpringSource/Eclipse, and when you are going to set the path of where it is located.
3. Setting the PATH variable
You must also update the PATH variable telling it where the Android SDK is located. I added these strings to my .bashrc file. If you are not using Ubuntu or Linux you will have to use your platforms way of setting the PATH. (Search for it in google).
export ANDROID_HOME=<path to Android SDK> PATH=$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/platforms:$PATH
4. Installing the Android Development Tools (ADT) for SpringSource/Eclipse
The fourth step is to install the ADT plugin in Eclipse. Open eclipse and follow the steps provided in this link. It should be pretty straightforward. Remember to tell the ADT plugin where your Android SDK is stored.
5. m2eclipse plugin for SpringSource/Eclipse
The fifth step is to install the m2eclipse plugin in eclipse. This is a plugin that binds Maven 2 and Eclipse together. If you are using SpringSource STS you already have m2eclipse, but if you’re using eclipse you have to install the plugin. Click Help < Install new software and add this repository.
http://m2eclipse.sonatype.org/sites/m2e
Then select the Maven Integration for Eclipse option. Then proceed the installation. Read more about this plugin here.
6. Installing m2eclipse-android-integration in SpringSource/Eclipse
The sixth step is installing a plugin that binds android and maven together, m2eclipse-android-integration. This plugin is not included in SpringSource nor Eclipse so you have to install it manually. Click Help < Install new software and add this repository.
https://svn.codespot.com/a/eclipselabs.org/m2eclipse-android-integration/updates/m2eclipse-android-integration/
Save it and select Maven Integration For Android Development Tools, proceed with the installation. Read more about this plugin here.
7. Creating an Emulator and downloading the SDK platform
The seventh step in this tutorial is creating an emulator (like the iPhone simulator) where you will be running and testing your applications. Click Window < Android SDK and AVD Manager. A new window will now appear. Select virtual devices in the left menu, then click the new button. You can now specify and create your own emulator. The most important step here is the target you choose, ie. the selected Android version you want to use on your emulator. I am currently using 2.2 or API level 8. But if you are developing for newer devices I recommend you to choose a higher API level. While you have the Android SDK and AVD Manager open you should also download your selected platform. Click Available packages < Then expand the Android Repository < Check the platform(s) you want < Click install selected. The platforms will then be installed. To make things easy you can check the whole Android repository, this will of course use more harddrive space on your computer, but will of course give you the opportunity to develop against all the different API levels.
8. Create your project with a Maven archetype
We are now ready to create the Maven project you will be working on. Open eclipse or STS. Select New < Other < Maven project < Use default Workspace and select next < We are going to use an archetype to simply create your project but we have to add the one we are using first < Select add archetype and fill in this information.
- In Archetype Group Id enter “de.akquinet.android.archetypes”
- In Archetype Artifact Id” enter “android-quickstart”
- In Archetype Version enter “1.0.5″
9. What the POM should look like
If you open your POM.xml now, you will see that the project will be built as an .apk package, wich is an Android specific package. You will also notice the Android dependency, and the Android Maven plugin.
10. Running your project in SpringSource/Eclipse
The application you now have should be runnable, try right-clicking the project and select run as android application. Hopefully you will now see a black screen and Hello <your artifact id> in your emulator.
Troubleshooting
No Android SDK Found
If you get this error read this post.
The R problem
“The R problem” is probably the most widespread issue Android developers will stumble upon. The most common reason why you will get this error in your activity is because you have this import line.
import android.R
If you have this line, remove it. You should also check that the gen folder is generated in your project. Read more about this issue here.
Conversion to dalvik format failed: ….
If you get this error open up eclipse.ini or STS.ini and change -Xms and -Xmx to these values:
-Xms512m
-Xmx1024m
Conclusion
I hope this guide may have helped you getting Eclipse/STS, Maven 2 and Android working like it should. Feel free to leave a comment below for an open and good discussion.
This is fantastic, thanks!
You should check this out…
Below you’ll see the link to some sites that you should visit…
What you typed was actually very reasonable. But, what about this? what if you added a little information? I am not saying your content isn’t good, but suppose you added a post title to possibly get folk’s attention? I mean ScratchMyTail.com » Blog Archive » The Ultimate 10 step setup: Eclipse (STS) + Android + Maven is a little plain. You ought to look at Yahoo’s front page and see how they create post titles to get people to open the links. You might add a video or a related pic or two to get people excited about what you’ve got to say. In my opinion, it might bring your posts a little bit more interesting.
really informative blog thanks for sharing and keep posting.http://www.listadeemail.org