Home > Articles > Mobile Application Development & Programming

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

Adding Android SDK Support to Eclipse

The Android SDK plugs into Eclipse a little easier than it does with NetBeans because only one install is required (and no separate plug-in like NBAndroid is needed). In the previous hour is a tutorial on installing the Android Development Kit and the Eclipse plug-in, so you may want to refer to Hour 2 if you haven’t yet installed these packages. Assuming you have them installed, Eclipse is ready to go. In that case, the title of this section is a misnomer because the Android SDK does not need to be added—it’s already good to go. Let’s take a look.

Creating a New Android Project in Eclipse

If you finished installing the files in the previous hour, verify the install in Eclipse by opening the Window menu, shown in Figure 3.13. You should see Android SDK Manager and AVD Manager to verify that Eclipse recognizes the new Android packages.

Figure 3-13

Figure 3.13. The Window menu in Eclipse shows the Android SDK tools.

Now, open the File menu and choose New, Project. You should see a new Android group, as shown in Figure 3.14. Choose Android Project from the options shown and click Next.

Figure 3-14

Figure 3.14. Creating a new Android project in Eclipse using the New Project dialog.

The New Android Project dialog appears next, as shown in Figure 3.15. Enter a name for the project and choose either the default location or enter a new location for the project files.

Figure 3-15

Figure 3.15. Entering the new project details.

The next dialog, shown in Figure 3.16, allows you to choose the Android SDK target (because multiple Android SDK versions may be installed to support various OS release levels). In the example shown, Android 4.0.3 was automatically checked. If you have more than one SDK installed, you may choose from among them.

Figure 3-16

Figure 3.16. Verifying the Build Target for the new project.

The next dialog that comes up in the New Android Project Wizard, shown in Figure 3.17, will look familiar because you dealt with this information earlier in the NetBeans project: the Package Name and Activity. These will make a little more sense in the next hour when you see the names in the source code. For now, you may change the values as needed. Because this is only a configuration tutorial and you aren’t writing any real Android code just yet, the values are not that important. But, as was the case with NetBeans, you must enter at least two words separated by a period into the Package Name field.

Figure 3-17

Figure 3.17. Entering the Application Info fields.

There are a lot of files created for a new project. Take a look at Figure 3.18, which shows the newly created project. In Package Explorer (on the left side of the IDE) you will see a folder called src, and then my.project (the package name), which contains the source code file called MySampleAndroidDemoActivity.java. This is similar to the files in the NetBeans project.

Figure 3-18

Figure 3.18. The new Android project has been created.

Choosing an Android Build Target

To build and run an Android project in Eclipse, open up the Window menu and choose Preferences. This brings up a dialog called Preferences, shown in Figure 3.19. In the list of preference groups, choose Android to show the Android preferences. Use the Browse button to choose the Android SDK location. This may be in C:\Program Files\Android, or it may be in My Documents, or elsewhere—it depends on where you chose to install the SDK according to the steps. Next, choose the target from the list (Android 4.0.3 in this case).

Figure 3-19

Figure 3.19. Setting the Android SDK location and choosing the Android build target.

  • + Share This
  • 🔖 Save To Your Account