What You Will Notice About Your Android Project Structure

One of the things that you will notice about Eclipse is how it does a lot of autogeneration. Package Explorer generates some interesting default folders, as shown on the left side of Figure 12-4.

images

Figure 12-4. After you start up a new Android project, you will see a new file directory in Package Explorer.

You should know that these are not the only types of folders that one can have on an Android project. I guarantee you that you will want to make new ones. The following list briefly describes what these folders and files are for:

  • src: This is the source folder. You will quickly notice that whatever you choose as the package name will be in the file. This contains the Java code that drives an application.
  • gen: This contains Java files generated by ADT. The gen folder contains items generated from the res directory. Generally, it is recommended not to mess with this manually, as it might not compile by itself.
  • android.jar: As you can tell, this matches your build target. It is an item in Eclipse presented through ADT.
  • assets: This folder is by default empty, but it is made to store raw asset files. Raw assets (for example, a SQLite database) could be required to get your application to work.
  • res: This stands for resources, and there are a lot of important files here. There are many subdirectories, and most of them are in XML files, including the following:
    • anim/ for animations
    • color/ for a list of colors
    • drawable/ for bitmap files (I will explain the hdpi, mdpi, and ldpi files later)
    • layout/ for a user interface layout
    • menu/ for application menus
    • raw/ for arbitrary files in their raw form
    • values/ for simple values, including resource arrays, colors, dimensions, strings, and styles
  • AndroidManifest.xml: This is the first file that an Android application will seek out. It is always located in the directory structure so it is easy to find. Here are some of the things that it contains:
    • References to the Java code that you will write for your application so the code can be both found and run.
    • Definitions of permissions for application security and for talking with other Android applications.
    • Definitions of the components of the Android application, including when they can be launched.
    • Declaration of the minimum level of Android operating system version support.
  • default.properties: This is a file used with both Eclipse and ADT, and it contains the project settings. Like the gen file, it should not be tampered with manually.
  • proguard.cfg: This is automatically generated in the root directory of the project. According to the Android Developers site, the ProGuard tool “shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names.”

Let’s look at what is in the files. At any given time, we can edit what is in the folders in three ways:

  • Double-clicking the file
  • Right-clicking the file and clicking Open
  • Selecting the file and clicking F3

This will open up the file in the editor, and you can make changes accordingly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.199.181