Starting Android Development Part 2: Project Structure

In Part One of Starting Android Development, we discussed setting up your project in Eclipse.  Now it’s time to explain exactly what’s going on and how Android development works.  This information will help you keep things in perspective as you program, and it will help you when it comes to debugging time.

Let’s take a look at the Eclipse screen after you’ve set up a given project:

Picture 6

For the purposes of this explanation, let’s look at the directories in the left pane of the Eclipse screen.  Under the name of the project you’ve just created, you should see several subfolders.  Let’s explain what they do:

  • src: This holds the source code for your project.
    • com.droidweb.conversion: This is the package holding your source code.  Several packages can make up a single project.  This is especially true when you include others’ packages to provide some type of functionality for your program.  For example, in a conversion application I wrote (ConvertAll+), I imported a package to handle different currencies.
      • convert.java: Inside the package are individual .java files.  This is where the goodies (the source code itself) are.
  • gen: This is a folder for automatically generated stuff Android uses to help your program operate properly.  There’s nothing in here that you need to mess with.  It will automatically update itself as necessary.  Sometimes when you import projects and they return errors, the solution is to delete this folder and let Eclipse regenerate it for you . . . but more about that later.
    • com.droidweb.conversion: This is the package holding automatically generated code corresponding to the package of the same name in the /src/ folder.
      • R.java: R.java is an automatically created and maintained file that keeps up with the resources your project utilizes.  In a lot of your Android programming, you’re going to use static variables that really translate into numerical (usual hex) values.  R.java makes the translation between these variables and their numerical values.
  • Android 1.5 (or appropriate Android source version): This contains the actual Android source code on top of which you’re going to build your applications.  As such, I’m not really going to discuss this much.
  • assets:  Why, this is what you set your — oh wait — wrong thing. . . . Usually you won’t mess with this folder, but if you have raw files to be read by your application, then they can be put here; but it’s probably better that it goes in the /res/raw folder.  More about that later.
  • res: res stands for resources.  Here is where you put your resources (images, files, etc).
    • drawable: This is where the images you’re going to use go.  Android supports a variety of image files, including .jpg, .gif (static), png, etc.
    • layout: This is where the .xml files describing your program layouts go.  I’ll spend a post on those later.
    • values: This is where .xml files defining values can be stored.  An example is a network topography program I worked on.  In the custom view drawing routine, I predefined the colors of good / bad links in a .xml file in the /srv/values folder.
  • AndroidManifest.xml: This is the file that will be the source of the most headaches for you (well, starting out it will be . . .).  This is where your project is described in a form that Android devices can understand.  Application permissions, activity descriptions, and more are found here.  This file itself will be the topic of a future post onto itself — yes, it’s that important.

Next time we’ll discuss program flow in a typical Android program.