Yesterday, I began showing you how to create your own Android applications using Java, the Eclipse IDE, and the Android SDK. That was the first article of a series of articles I will be sharing with you over the next few days that will teach you everything you need to know to write your own Android apps, deploy them to actual Android devices such as cellphones and tablets, how to get your Android apps into Google Play so that others can enjoy them too, and even how to make money from your apps by placing advertisements in your apps. Today, we will pick up where we left off by creating our first Eclipse Workspace and Android project. But, before we can jump into writing any code, we will need to configure Eclipse to work with the Android SDK and AVD we setup yesterday. So, let’s begin!
If you read yesterday’s article, you will remember that I recommended that you create a shortcut on your desktop that points to your Eclipse application. Go ahead and launch Eclipse by executing that shortcut. When Eclipse opens for the first time, you will be prompted to select a workspace location. A workspace is simply a folder on your filesystem that allows you to create multiple projects and access all of the projects within a workspace at the same time. For now, we will only be concerned with one project. But, the time might come where you will have several Android apps and want to copy & paste code you’ve already written in another project. By having all of your projects in a single workspace, you can quickly and easily open the project that contains the code you need without having to traverse the filesystem. You can pick any location on your filesystem to act as your workspace. But, it is recommended that you create a new empty folder that will be specifically for your Android workspace. As an example, I have created the folders C:\Workspaces\Eclipse\Java\Android\ and selected that as my workspace.
After you have created your workspace, you will be presented with the Eclipse welcome screen. Go ahead and close this screen by clicking the X button on the welcome screen tab. If you ever want to get back to the welcome screen, you can do so by clicking Help > Welcome. Once you have closed the Eclipse welcome screen, you will now be at what is called the Workbench. I’m not going to explain everything about the Workbench as there are already plenty of good resources that do a good job of that. Instead, I am only going to focus on what matters in terms of getting our Android application working. With that said, we will need to configure Eclipse to work with the Android SDK and AVD we created yesterday.
To do that, click on Window on the menu bar and click on Preferences. If you are using Mac, you can find the Preferences option under the Eclipse menu item. This will open the Eclipse Preferences window. Next, click to select “Android” on the left. On the right, you will see a field labeled “SDK Location”. Click the “Browse…” button next to that field and navigate to the location where you installed the Android SDK. If you stuck with the defaults during the installation, your SDK Location should look something like “C:\Program Files (x86)\Android\android-sdk”. Once you have selected your SDK location, you should see the APIs you setup using the SDK Manager yesterday. As mentioned yesterday, I added APIs 16 & 17. I also added the Google APIs for 16 & 17 as well. So, this is what my Android setup looks like:
After you have setup your SDK location and see your APIs in the list, click the “Apply” button, then the “OK” button to close the Eclipse Preferences window. At this point, you are ready to create your first Android project. But, before we jump into that, I’d like to point out that you can access the Android SDK Manager and the AVD Manager from the Window menu bar. This is much more convenient than having to click Start > All Programs > Android SDK Tools > SDK Manager or AVD Manager every time you need to make a change during development.
Alrighty. Let’s create our first Android project. To do that, click File on the menu bar and go to New > Other. This will open the new wizard window. Scroll down in that window and expand “Android”. There you will see an option called “Android Application Project”. Select that option and click the “Next” button.
On the next screen, you will need to enter the name of your Android application along with the name of your project and a package name. The Application Name is what will display in the Play Store and is also what will display in the “Manage Applications” settings page on your device. The Project Name is only used by Eclipse and must be unique to the Eclipse workspace. If you want, the Project Name can be the same as the Application Name. The Package Name is a namespace (series of folders separated by a period) that must be a unique identifier for your application. It is typically not shown to users, but it must stay the same for the lifetime of your application; it is how multiple versions of the same application are considered the same app. This is typically the reverse domain name of your organization plus one or more application identifiers, and it must be a valid Java package name. For more information on packages, visit the Wikipedia Java Package page at http://en.wikipedia.org/wiki/Java_package.
For my application, I have decided to create a tool that will allow me to test UDP servers from my cellphone. I have lots of servers scattered across the country and would like an easy way to test that each server is online and accessible. I have created a simple UDP listener that I have installed and launched on all of my servers and now I will be writing a UDP client that I can use to test each server. So, for my Application Name, I have decided to enter “UDP Tester”. I used the same name for the Project Name too. To keep in line with the other Android apps I have written, I used “com.prodigy.mobile.android.udptester” as my Package Name. Next, I had to decide how many versions of the Android OS I want to support. For my app, I decided I don’t want to support anything older than Android 2.2 (Froyo). I also decided that I want to target Android 4.1 (Jelly Bean) devices. Here are the final settings I used for creating my UDP client app.
With those settings selected, click the “Next” button. On the next screen, make sure “Create activity” is checked. You can also change the other settings if you want, but I would recommend leaving them as-is and click the “Next” button.
If you left “Create custom launcher icon” checked on the last screen, you should now see a screen that helps you setup the icon that users will see in their list of apps on their device. This icon will also be used later on in the app. If you have an icon or clipart you would like to use, you can click the “Browse…” button to select it. Since I do not have an icon currently created and don’t feel like spending the time to create one now, I have decided to create an icon from text instead. To do that, click the “Text” button next to Foreground. Enter some text and mess around with the settings until you find something you like. Here is an example of what I threw together with just a few clicks. It isn’t pretty, but I think it is good enough for what I’m doing. Keep in mind, you can always change your icon later.
After you have created your icon, click the “Next” button. On the next screen, you will see a list of activity templates to choose from. An activity is nothing more than a screen in your app. When you generate activities, multiple files are generated as stubs which you will have to fill in to suit your app’s needs. Depending on what your application will do, you might want to select one of the other activities in the list. Since I am only targeting cellphones right now and don’t need a lot of extra bells and whistles, I have decided to select “BlankActivity”. With your activity template selected, click the “Next” button to move on.
On the last screen of the Android application wizard, you will need to enter the name of the activity you are having generated for you. You will also need to enter a name for your activity’s layout. If you want, you can also select something for the Navigation Type. But, since my app will only consist of a single screen, I will not be needing navigation. So, I click the “Finish” button to complete the new Android Application Project wizard.
When you click the Finish button, Eclipse will generate your new Android application and will auto-generate everything you specified during the new application wizard. For example, if you expand the “res” folder and look inside any of the “drawable-” folders, you will see the icon you created during the wizard. If you look in the “layout” folder also under “res” (short for “resources”), you will also see the layout you selected during the wizard. You will also see that this layout has been opened in an editor view that looks something like this:
Layouts are stored in XML format. So, to customize your layout, you can choose to use the graphical editors by clicking the “Graphical Layout” tab or by manually editing the XML by clicking on the XML tab of the editor view as shown here:
To get an understanding of how layouts work and how to create your own, there is a great article over at mobile tuts (http://mobile.tutsplus.com/tutorials/android/android-layout/) that you should check out. There you will learn the basics of interface layouts using Eclipse and the Android SDK. After you have checked out that article, go ahead and spend some time creating the layout for your first screen. Tomorrow, I will show you what the final layout looks like for my application and we will start writing some code to give some functionality to our app.
Create Your Own Android Apps for Fun or Profit
Part 1: Downloading and Installing Java, Eclipse, and the Android SDK
Part 2: Configuring Eclipse and Creating Your First Android App
Part 3: Creating a Layout and Adding Some Code
Part 4: Testing Your App with the Android Emulator
Part 5: Monetizing Your Android App with Google AdMob
Part 6: Running Your Android App on Cellphones and Tablets
Part 7: Publishing Your Android App to the Google Play Store
PayPal will open in a new tab.