The Android project structure

The root directory of your Android project contains various files and subdirectories. Or, should I say, the root folder of your Android project contains various files and subfolders. Ha ha. We'll use the words "folder" and "directory" interchangeably throughout this book, just as Android Studio also seems to do (actually, there is a difference, as discussed at http://stackoverflow.com/questions/29454427/new-directory-vs-new-folder-in-android-studio).

As shown in the Android hierarchy, in the following sample Cardboard project, the root directory contains an app/ subdirectory, which, in turn, contains the following subdirectories:

  • app/manifests/: This contains the AndroidManifest.xml manifest file that specifies the components of the application, including activities (UI), device permissions, and other configurations
  • app/java/: This contains subfolders with your application Java files that implement the application's MainActivity and other classes
  • app/res/: This contains subfolders with resources, including the layout XML definition files, values definitions (strings.xml, styles.xml, and so on), icons, and other resource files
    The Android project structure

It's not a coincidence that these directories correspond to the boxes in the topmost row of the preceding Gradle build process diagram; they supply the source files that are run through the Java compiler.

Also, there are Gradle scripts under the root directory, which do not need to be edited directly since the Android Studio IDE provides convenient dialog boxes to manage the settings. In some cases, you might find it to be easier to modify these files directly.

Notice that in the upper-left corner of the hierarchy pane is a tab select menu. In the preceding screenshot, it is set to Android, which just shows the Android-specific files. There are other views that might also be useful, such as Project, which lists all the files and subdirectories under your project root directory, as shown in the following screenshot, for the same app. The Project hierarchy shows the files as they are structured on the actual filesystem. The other hierarchies artificially restructure your project to make it easier to work with.

The Android project structure

Tip

From time to time, you'll need to switch between the Android view and Project view.

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

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