Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

3.4 Creating a New Project

To begin programming with Android in Eclipse, select File > New > Project... to display the New Project dialog. Expand the Android node, select Android Project and click Next > to display the New Android Project dialog (Fig. 3.4). You can also do this with the New (new.jpg) toolbar buttons’s drop-down list. After you create your first project, the Android Project option will appear in the File > New menu and in the New (new.jpg) button’s drop-down list.

Fig. 3.4

Fig. 3.4 New Android Project dialog.

A project is a group of related files, such as the code files and any images that make up an app. Using the New Android Project dialog, you can create a project from scratch or you can use existing source code—such as the code examples from this book.

In this dialog, specify the following information:

  1. In the Project name: field, enter Welcome. This will be the name of the project’s root node in Eclipse’s Package Explorer tab.
  2. In the Contents section, ensure that Create new project in workspace is selected to create a new project from scratch. The Create project from existing source option allows you to create a new project and incorporate existing Java source-code files.
  3. In the Build Target section, select the Android version you wish to use. For most of this book’s examples, we use version 2.3.3; however, it’s recommended that you select the minimum version that your app requires so that it can run on the widest variety of devices.

In the Properties section of the dialog, specify the following information:

  1. In the Application name: field, enter Welcome. We typically give our applications the same name as their projects, but this is not required. This name appears in a bar at the top of the app, if that bar is not explicitly hidden by the app.
  2. Android uses conventional Java package-naming conventions and requires a minimum of two parts in the package name (e.g., com.deitel). In the Package name: field, enter com.deitel.welcome. We use our domain deitel.com in reverse followed by the app’s name. All the classes and interfaces that are created as part of your app will be placed in this Java package. Android and the Android Market use the package name as the app’s unique identifier.
  3. In the Create Activity: field, enter Welcome. This will become the name of a class that controls the app’s execution. Starting in the next chapter, we’ll modify this class to implement an app’s functionality.
  4. In the Min SDK Version: field, enter the minimum API level that’s required to run your app. This allows your app to execute on devices at that API level and higher. In this book, we typically use the API level 10, which corresponds to Android 2.3.3, or API level 11, which corresponds to Android 3.0. To run your app on Android 2.2 and higher, select API level 8. In this case, you must ensure that your app does not use features that are specific to more recent versions of Android. Figure 3.5 shows the Android SDK versions and API levels. Other versions of the SDK are now deprecated and should not be used. The following webpage shows the current percentage of Android devices running each platform version:
    developer.android.com/resources/dashboard/platform-versions.html

    Fig. 3.5 Android SDK versions and API levels. (developer.android.com/sdk/index.html)

    Android SDK version

    API level

    3.0

    11

    2.3.3

    10

    2.2

    8

    2.1

    7

    1.6

    4

    1.5

    3

  5. Click Finish to create the project. [Note: You might see project errors while Eclipse loads the Android SDK.]

Package Explorer Window

Once you create (or open) a project, the Package Explorer window at the left of the IDE provides access to all of the project’s files. Figure 3.6 shows the project contents for the Welcome app. The Welcome node represents the project. You can have many projects open in the IDE at once—each will have its own top-level node.

Fig. 3.6

Fig. 3.6 Package Explorer window.

Within a project’s node the project’s contents are organized into various files and folders, including:

  • src—A folder containing the project’s Java source files.
  • gen—A folder containing the Java files generated by the IDE.
  • Android 2.3.3—A folder containing the Android framework version you selected when you created the app.
  • res—A folder containing the resource files associated with your app, such as GUI layouts and images used in your app.

We discuss the other files and folders as necessary throughout the book.

  • + Share This
  • 🔖 Save To Your Account