Login

Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.

ARM Community: Getting Started with Android Development - ARM Community

Jump to content

Getting Started with Android Development

This blog is aimed at getting you started quickly in the world of Android development. I've included links to some golden tutorials and programs I found useful.. I've also included solutions to the annoying time-wasting problems I encountered when first starting out. I hope they will be helpful and will save you from the frustration I went through.

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.

Attached Image

The solution
  • 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


Attached Image

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.

Attached Image

The Solution:
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.

Attached Image

Solution:
  • 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.
All company and product names appearing in the ARM Blogs are trademarks and/or registered trademarks of ARM Limited per ARM’s official trademark list. All other product or service names mentioned herein are the trademarks of their respective owners.

5 Comments On This Entry

Please log in above to add a comment or register for an account

Page 1 of 1

farasite 

06 April 2011 - 09:42 AM
"If you don’t have an Android phone, don’t worry" Most of the times the emulator is useless and sloow. Of course I use real Android devices not a stupid good for nothing emulator.
0

Philip Day 

06 April 2011 - 06:30 PM
This is my experience.

The emulator is slow to load however if you leave it running in the background, you can keep running and debugging code in Eclispe without having to restart the emulator each time. It is a great tool for testing what your app will look like on multiple screen sizes and simply learning to develop on android without the need to buy a phone. However without trying your app on a real phone, you won't be able to get an accurate sense of the app's performance. According to emulator documentation, there are other limitations:

No support for placing or receiving actual phone calls, but you can simulate phone calls (placed and received) through the emulator console.

No support for USB connections

No support for camera/video capture (input).

No support for device-attached headphones

No support for determining connected state

No support for determining battery charge level and AC charging state

No support for determining SD card insert/eject

No support for Bluetooth

The emulator is a useful tool to learn on and test multiple screen sizes but it can only take you so far. I would definitely recommend trying it on a real device as well.

Hope that helps

Phil

Emulator Doc link: http://developer.and...s/emulator.html
0

farasite 

26 April 2011 - 06:45 AM
Talking about software development for Android: given that the tablets are fast approaching laptop speeds is there an ARM on ARM cc compiler? The next great Android application should be able to be developed on Android without the need for a PC. My tablet is way more powerful than my first PC at a fraction of the cost and size.
0

abel 

18 December 2012 - 02:25 AM
Could ARMCC in DS-5 pro be used to compile the native code of Android NDK? If could, then how to do? We try to use ARMCC to compile NEON intrincis in the native code of Android NDK, but found none guideline or articles, any sugessions? thanks a lot...
0

Katie Morgan 

18 December 2012 - 06:31 PM
Sharing Scott's reply to @abel's question as answered on another blog: http://blogs.arm.com...s-5-pro-is-out/

scott, on 18 December 2012 - 06:05 AM, said:

Unfortunately, building general native Android code with armcc is not supported* so there aren't any instructions available, but if you have a standalone object file built with armcc you can link it with other native code. gcc can also compile NEON intrincics.

[*] One reason is that the Android C library, Bionic, does not supply all of the functions that the AEABI requires.
0
Page 1 of 1