Setting up your Development environment
To get up and running quickly, follow the instructions from the Android developers site to set up your software development environment. If you don’t have an Android phone, don’t worry, the SDK contains an Android emulator.
I definitely recommend using the Android development tool plug-in for Eclipse. For someone like me who makes lots of common mistakes, such as missing imports of libraries and not putting the right parameters into a method, Eclipse is great because it easily spots common errors and offers quick fixes. There are many versions of Eclipse and it can be confusing which one you need to download. I use Eclipse Galileo Java EE version.
The Android developers site is a good reference to go to if you would like to read about how the Android system works and the application fundamentals. It is also a good idea to familiarize yourself with creating user interfaces in xml and code and to know a bit about the layout manager before you begin developing your first app.
The website also shows you how to do your first Hello world program whilst introducing you to the Android way of doing things and explaining important concepts such as views, the xml files in the res folder, the different drawable folders, the R.java file and the Android Manifest xml file.
There are lots of example apps to help you grasp the various functionality of Android and show you how to obtain the sample code. I found it a bit of a big jump to go from the hello world example to sample apps, so I explored the web and found this very good tutorial which introduces important Android concepts whilst showing you how to build a Twitter app.
Most frustrating problems when you first start
1. R.layout.main cannot be resolved
An important thing to be aware of when developing Android Apps in Eclipse is that when you create a new project or import an existing one, Eclipse spends a little time automatically creating the R.java file. This R java file is what links your Java code to your xml files and resources. An error will appear in your project until this is finished. This Java file can get you into trouble if you try and fix the errors in your project before the R java file is finished automatically generating. This process takes a bit of time and the larger the app, the longer it takes.
If you’re referencing an xml layout file in code such as the main.xml file in the hello world program, you will get the “R.layout.main cannot be resolved error” until the R java file is automatically created. The error will persist if there are problems with the file being automatically built.
- Make sure ‘Build automatically’ is selected. To do this go to the project menu >> Build Automatically.
- Wait for the R.java to be created.
- If that doesn’t work, delete import android.R if that appeared. You don’t need this and Eclipse automatically adds this sometimes and recommends it as a quick fix. Remember to save the file always as the changes won’t get rid of the errors until you save.
- If that also doesn’t work, try cleaning the project. To do this go to the project menu >> clean, then ‘clean all projects’. This simply causes Eclipse to delete the R.java file and then re-generate the file.
2. Running the application when an XML file is open
When this happens you will get an error message similar to this.
Error in an XML file: aborting build.
res\layout\main.xml:0: error: Resource entry main is already defined.
res\layout\main.out.xml:0: Originally defined here.
error: Error parsing XML: no element found
error: Resource entry main is already defined.
res\layout\main.out.xml:0: Originally defined here.
Error: Error parsing XML: no element found
If you notice, a new xml file appears when you do this. It has .out.xml in the name. For my example, I ran the application when I had the main.xml file open. This causes a new main.out.xml file to be created, which then stops your program from compiling. If you then select the main activity Java file after this you will find Eclipse won’t let you, until you fix the errors in your project.
Delete the new xml file that has appeared which has got .out.xml in the name. This is the file which is screwing up the project. You will then need to clean the project. To do this go to the project menu >> clean, then ‘clean all projects’. This simply causes Eclipse to delete the R.java file and then re-generate the file.
3. A mystery error you can’t get rid of
Many times I managed to get this mystery error. I looked through every java and xml without finding any specific mistakes but yet a red x appeared on the project name in the package explorer of Eclipse.
- To clear this go to the project menu >> clean, then ‘clean all projects’. This solution solves most problems like this I’ve found. If in doubt just clean the project.
- However, if this problem still persists after cleaning there may be a subtle problem which Eclipse doesn’t pick up. Android can be fussy about the names of your xml files. It won’t let your program compile if you have any unusual characters or even capital letters in the names of your xml files. Capital letters are fine with java classes though.
- If that doesn’t work, check that your app is compatible with the Android version you are targeting as this will produce one of those mystery errors as well.
Some Useful Links to Learn Android
A good program I found to help get my head around using xml to develop the user interface and play around with the various view components available is DroidDraw program. You can move around different components, change their properties and play with the different layouts. It then automatically generates the xml which you can copy and paste into Eclipse. It’s not very advanced and quickly becomes useless when you need to nest different layout managers into each other, however, it is a very useful tool to familiarize yourself with the different view components, the layout manager and see how properties such as fill_parent and wrap_content work.
The best way I found to learn how to use layout managers and all the different views in xml is just playing around within Eclipse. Here are some examples of what you can do with the different layouts. It’s really important to get a good grasp of how these work because they will save you a lot of time when supporting multiple screen sizes if you use them effectively.
Specific Topics Links
Learning Android on ARM Architecture: if you are starting from scratch, you may find the Solution Center for Android useful.
Learning Bluetooth: If you are creating an app which needs to communicate with an external device over Bluetooth I found this useful tutorial.
Learning the sensors: Here is a tutorial to show you how to access the accelerometer’s readings and handle when the phone moves.
Learning 2D graphics: This example shows you how to simply and quickly create 2D graphics.
Learning location-based services: If you are looking to use the location-based service on your phone, here’s a tutorial on how to do it.
Learning Google Maps integration: If you need help integrating Google Maps and also obtaining your MD5 footprint to get Google Maps to work, here is a useful tutorial.
Learning Web service calls: An example of how to use Ksoap2-android library for calling web services.
My Thoughts on Android
It is a really interesting time to be getting into app development. The phones that are coming out nowadays are getting faster, with more memory and with more sensors to play with than ever, creating a very exciting environment to develop in.
Android is a great platform to be developing on and is supported by a lot of forums on the internet. Although there isn’t currently much on the internet to bridge the gap between your first ‘hello world’ programs to some more advanced programs, there are loads of forums and tutorials on a wide range of specific topics. You just need to invest the time in getting your head around using all the different views and knowing which layout manager to use for each situation. Once you have, you’ll find yourself developing some quite fancy apps effortlessly. Android is Java–based. Because of this you’ll find that there a lot of existing Java libraries have been tweaked and made available for the Android platform which can make app development even easier.
You will learn to love the Android way of doings things even though it takes a bit of time initially to understand some of the concepts. It lends itself very nicely to quickly developing the functionality of an app but being able to fiddle around with the aesthetics very easily in xml without even touching your Java code.
Android has served me well. Although I am relatively new to Android development, I found myself in not much time at all creating apps using the GPS sensors, Accelerometer sensors, multi-touch, Google Maps, 2D graphics, animation effects, Bluetooth and even calling secure web services. With all the support on the internet and libraries available for Android, it’s simple to make what you want to happen, happen!
To really get your head around how the Android operating system works and to learn how to develop complex apps, I found the book “Hello Android”. It covers a lot of different areas such as UI design, location base services, using the sensors, Google Maps, calling webservices, 2D and 3D graphics. This was definitely the most helpful resource.
Philip Day, Engineering Placement Student, Applied Systems Engineering Team, ARM. Although he is primarily an Electronic Engineer Student, he is enthusiastic about learning to develop software on mobile platforms. He has worked on multiple Android apps internally and externally of ARM and is now learning how to develop for other mobile platforms.
5 Comments On This Entry
Please log in above to add a comment or register for an account
Search My Blog
on May 08 2013 06:15 PM
New Platform Bring-Up with ARM® Development Studio 5 (DS-5™)
on Apr 30 2013 09:55 AM
如何利用全志安卓4.0 HDMI Dongle进行ARM DS-5 Streamline性能分析
on Apr 26 2013 10:50 AM
DS-5 Streamline Performance Analyzer on Allwinner Android 4.0 HDMI Dongle
on Apr 25 2013 04:58 PM
Spotlight on the Linux Software Ecosystem - openSUSE
on Apr 22 2013 08:10 PM