1.1 SDK Overview
After we add necessary components through the "Android SDK and AVD Manager" tool, we can go to the SDK root directory to see its overview, as shown below:
|
Name |
Description |
|
Add-ons/ |
Contains add-ons to the Android SDK development environment, which let you develop against external libraries that are available on some devices. Mainly some Google APIs |
|
Docs/ |
A full set of documentation in HTML format, including the Developer's Guide, API Reference, and other information. To read the documentation, load the file offline.html in a web browser. |
|
Platforms/ |
Contains a set of Android platform versions that you can develop applications against, each in a separate directory. |
| |
<Platform>/ |
Platform version directory, for example "android-1.6". All platform version directories contain a similar set of files and subdirectory structure. |
| |
|
Data/ |
Storage area for default fonts and resource definitions. |
| |
|
Images/ |
Storage area for default disk images, including the Android system image, the default userdata image, the default ramdisk image, and more. The images are used in emulator sessions. |
| |
|
Skins/ |
A set of emulator skins available for the platform version. Each skin is designed for a specific screen resolution. |
| |
|
Templates/ |
Storage area for file templates used by the SDK development tools. |
| |
|
Tools/ |
Any development tools that are specific to the platform version. |
| |
|
Android. jar |
Java archive file, which contains all the Android SDK classes required to build the application. |
|
Samples/ |
Sample code and apps that are specific to platform version.
Contains the source code of various applications, including ApiDemo, which demonstrates many APIs. This sample application can be used as a good starting point for Android application development. |
|
Tools/ |
Contains all command line tools used to build Android applications. The most common and useful tool isadb
Utility (Android Debug Bridge ). |
|
Usb_driver |
This directory contains the drivers required to connect the development environment to devices that support Android (such as G1 or Android Dev 1. Only Windows developers need these files. |
|
SDK Readme.txt |
A file that explains how to perform the initial setup of your SDK, including how to launch the Android SDK and AVD Manager tool on all platforms |
|
SDK Setup.exe |
Windows SDK only. A shortcut that launches the Android SDK and AVD Manager tool, which you use to add components to your SDK. |
1.2 Hello World
Reference: Hello World tutorial
.
1.2.1 prerequisites
The SDK has been installed and at least one SDK Platform has been installed;
Ø Eclipse and ADT are installed. For Other IDEs, see: Developing in Other IDEs.
;
1.2.2 create an AVD
AVD is short for Android Virtual Devices (Android Virtual Devices. For more information, see Android Virtual Devices
.
Android comes with a simulator, and all our applications can run on it. Of course, if you are engaged in Linux kernel porting and driver development, the simulator may be of little use.
You must create an AVD before starting the simulator. AVD defines system images and device settings. To create an AVD, follow these steps:
Ø in Eclipse, select the menu item Window> Android SDK and AVD Manager;
Ø select "Virtual Devices" in the left-side Navigation Pane and click New. The page for creating an AVD is displayed;
Configure the interface, for example, the following example:
Ø Click Create AVD!
1.2.3 create an Android Project
After creating an AVD, we need to create a new Hello World project:
Select a single File> New> Project in Eclipse;
Select the following "android project" and press next. If "android project" is not displayed, the installation of the ADT fails;
Enter the corresponding information in the "new Android project" Panel, as shown in the following figure. Then click Finish to complete the creation:
1.2.4 description of each field in the new project (omitted)
Ø project name
This is the Eclipse project name-the name of the directory that will contain in the project files.
Ø Application name
This is the human-readable title for your application-the name that will appear on the Android device.
Ø package name
This is the package namespace (following the same rules as for packages in the Java programming language) that you want all your source code to reside under. this also sets the package name under which the stub activity will be generated.
Your package name must be unique guest SS all packages installed on the Android system; for this reason, it's important to use a standard domain-style package for your applications. the example abve uses the "com. example "namespace, which is a namespace reserved for example documentation-when you develop your own applications, you shocould use a namespace that's appropriate to your organization or entity.
Ø create Activity
This is the name for the class stub that will be generated by the plugin. This will be a subclass of Android's activity
Class. an activity is simply a class that can run and do work. it can create a UI if it chooses, but it doesn't need. as the checkbox suggests, this is optional, but an activity is almost always used as the basis for an application.
Ø min SDK version
This value specifies the minimum API level required by your application. For more information, see Android API levels
.
Ø other fields
The checkbox for "use default location" allows you to change the location on disk where the project's files will be generated and stored. "Build target" is the platform target that your application will be compiled against (this shocould be selected automatically, based on your min SDK version ).
1.2.5 build the UI
Refer to the modified source code below and modify the automatically generated helloandroid Class Based on the gourd image watermark.
Package com. example. helloandroid;
Import Android. App. activity;
Import Android. OS. Bundle;
Import android. widget. TextView;
Public class helloandroid extends activity {
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. onCreate (savedInstanceState );
TextView TV = new TextView (this );
TV. setText ("Hello, Android ");
SetContentView (TV );
}
}
TIPS:
The simplest way to add import packages is to press Ctrl-Shift-O (Cmd-Shift-O, on Mac ). It automatically adds the missing package according to the code needs;
1.2.6 run the application
Eclipse plug-ins make it quite easy to run our applications.
Select the menu item Run> Run, and then select "Android Application ".
Depending on the PC configuration, it may take a long time to start Hello World in the simulator. Please wait.