Build the Android development environment with Eclipse and create the first Android project (Eclipse+android SDK) _android

Source: Internet
Author: User

First, build the Android development environment

Preparation: Download Eclipse, JDK, Android SDK, ADT Plugin

1. Install and configure the Java Development environment:

① installs the prepared Eclipse and JDK on this machine (preferably installed in a full English path) and configures environment variables for JDK, where the JDK's variable value is the root directory of the JDK installation path, as my: D:\Program files\java\jdk1.7.0_02;

② Open a command prompt (cmd), enter the Java-version command, and show the following diagram stating that the Java environment variable is already configured.

2, install ADT Plug-ins:

① Open the installed Eclipse, select "Help" on the menu bar-> Click Select "Install new software ..." In the pop-up Drop-down box.

② in the newly opened dialog we can simply enter in the "Work with": https://dl-ssl.google.com/android/eclipse/Install ADT plug-in online, but as Google's servers are built abroad, So the installation will be slow in this way, and there may be a character difference in the situation, so do not recommend online installation.

③ I recommend that you install it directly by downloading a good ADT plug-in package (this can be done in an offline environment). The specific steps are: In the newly opened dialog box, click the "Add" button-> in the Open dialog box click the "Archive" button to select the previous download has been saved in the local hard disk ADT plug-in compression package, as the above "Name" can be arbitrarily taken, this is just a code only, no practical role.

④ When you click the "OK" button in the previous step, we find that two lines of check boxes appear in the middle margin. Click the Select All button to select all the check boxes, and then "Next" after this step, "Accept" is required to select "Accept" until the end of click "Finish", So the ADT plugin is installed. The time required for the whole process depends on the performance of the machine. Once the ADT plugin is installed, an Android icon appears in the Eclipse toolbar, as shown in the following illustration:

3, install the SDK:

① installs the downloaded Android SDK on this computer (preferably in a full English path) and configures the environment variables for the Android SDK. The environment variable value for the Android SDK is the directory path for the Platform-tools folder and the tools file clip under the SDK installation directory, as my respective: E:\My studying\android\android-sdk\ Platform-tools, E:\My studying\android\android-sdk\tools, in variable values, two paths are separated by commas.

② Open a command prompt (cmd), enter the android-h and ADB commands, and display the following illustration to show that the Android SDK environment variables are already configured.

③ Open the Android SDK installation directory, double-click SDK Manager-> to select the SDK version you want to install in the open window, where "Status" indicates whether the SDK package is installed, as I chose "Android2.2 (API 8)" (I have already installed before, so "Status" for "Installed")-> click on "Install packages ..." button, in the pop-up window it is best to choose "Accept all" to install all the packages you just selected-> The last point "Install" button will begin to install, the whole process will be slow, which requires your patience.

In addition, we can open the SDK Manager and install it by clicking the icon shown in the toolbar on Eclipse, which is no more tiring than the SDK installation method above.

④ finally Select "Windows" on the Eclipes main menu-> Select "Preferrnces";

⑤ in the dialog box, select the "Android"-> on the right side of the "Browse ..." button to choose the SDK's installation path root-> click on the bottom "OK" button, so that the SDK will load successfully on eclipse.

4. Create Android Simulator (AVD):

① Open eclipse-> the "Android Virsual Device Manager" window by clicking the icon indicated in the following illustration on the Eclipse toolbar;

② in the "Android Virsual Device Manager" window click the "New" button-> in the pop-up window "Name" can be arbitrarily, "Target" refers to the system version of the simulator, "SD card" "size" refers to the size of the cell phone memory card , as long as you do not upload too many applications on the simulator, generally give a twenty or thirty MB is enough; "Skin" refers to the resolution size of the screen, where "Built in" is a common mobile phone standard screen resolution size, and "Resolution" is a custom screen resolution size, the specific approach, Can be selected according to their own circumstances. -> all set up and click "Create AVD", when an emulator is created. If necessary, we can create multiple emulators to use when testing.

Attached: Android simulator model and its corresponding resolution size:

So far, the Android development environment has been built successfully on eclipse, so let's look at how to create the first Android project.

Second, a new Android project

① open Eclipse, click "File" in the menu bar to move the mouse cursor to the "New"-> in the pop-up list box, click this option if you see the "Android applicaion Project" option directly, or select the bottom Other ... ", in the pop-up window, expand the" Android "item, select" Android applicaion Project ", then" next ";

In fact, there is another way to directly point to the icon in the Eclipse toolbar as indicated in the following illustration:

② in the New pop-up window to fill out the relevant information, all the way "next" until the Click "Finish", so that the first Android program is created, this is you will find eclipse left a new Android project you created.

Iii. Compiling the Android project

Select items as shown in the following figure-> right click, select "Run as"-> click "Android Application" in the pop-up list box, and you will find that the simulator starts automatically, and when the simulator is fully booted, you can see the result of the project's compilation. Do you see anything that looks familiar? Actually, that's what you do when you create this project, and start your Android trip.

If any of the above mentioned, welcome to the Brick!

Android Create new projects and develop projects

Creating a new project is easy, as long as you have the Eclipse plugin installed and your Eclipse software version is 3.2 or 3.3, you can start developing.
First, take a look at the advanced level of steps to create the Hello World program:
1, create a new project, "Android Project," via the File-> new-> Project menu
2, fill in the new project various parameters.
3, edit the automatically generated code template.
For that matter, we complete each step by following the detailed instructions below.
1. Create a new Android project
Start Eclipse, select the File-> New-> Project menu, and if you install the Android Eclipse plugin, you will see the "Android Project" option in the pop-up dialog box.
Select "Android Project" and click the Next button.
2, fill in the details of the project parameters
The following dialog box requires you to enter parameters related to the project:
The meaning of each parameter is described in detail in this table:
Project name: The name of the folder that contains this project.
Package Name: Package name, follow the Java specification, it is important to use the package name to distinguish different classes, the example uses is "Com.google.android", you should according to your plan a different path name.
Activity name: This is the main class name for the project, and this class will be a subclass of the Android activity class. An activity class is a simple boot path
Sequence and control program of the class. It can create an interface as needed, but not necessarily.
Application Name: An easy to read title on your application.
The "Use default location" option in the "Select Bar" allows you to select an existing item.
3, edit the automatically generated code.
When the project is created, the helloandroid you just created will be the following code.

The public class Helloandroid extends activity{/** called the "when the" is the "the" is the
 
"the". * *
@Override public
void OnCreate (Bundle icicle) {
super.oncreate (icicle);
Setcontentview (R.layout.main);
}
 

Let's start by modifying it [build interface] When a project is set up, the most direct effect is to display some text on the screen, the following is the completed code, and we will explain it step by line.

The public class Helloandroid extends activity {/** called the ' when ' is the ' The activity ' is the ' the '
./
 
@Override
Pub LIC void OnCreate (Bundle icicle) {
super.oncreate (icicle);
TextView TV = new TextView (this);
Tv.settext ("Hello, Android");
Setcontentview (TV);
}
 
}

       Note You will also need to add import Android.widget.TextView at the beginning of the code. In the Android program, the user interface is organized by the called views class.
       A view can be simply understood as an object that can be drawn, like a selection button, an animation, or a text label (in this program), The view subclass of this display text label is called TextView.
       How to construct a textview:texiview TV = new TextView (this); The TextView construction parameter is a context instance of the Android program, and the context can control system calls that provide such as resource resolution, access to the database, and so on. The activity class inherits from the context class, because our helloandroid is a subclass of the activity, so it is also a class, so we can use "this" in the TextView construct. When we finish constructing textview, we need to tell what it shows: Tv.settext ("Hello, Android"); This step is simple, when we finish these steps, we finally have to show the TextView on the screen. Setcontentview (TV); The Setcontentview () method of the activity indicates which view the system will use as an activity interface, and if an activity class does not execute this method, there will be no interface and display screen. In this program, we want to display the text, so we pass in the TextView that has been created.

       Good, the program code has been written, the following look at the effect of the operation. Run code: Hello, Android using the Eclipse plugin on Android can easily run your program, choose Run-> Open run Dialog. You will see the following dialog box next, highlight the "Android Application" tab, and then press the icon in the upper left corner (just like a piece of paper tape a little star), or just double-click the "Android Application" tab and you'll see a new running project, Named "New_configuration". Take a name that can be ideographic, such as "Hello, Android," and then select your item via the browser button (if you have many items in eclipse, make sure you choose the project to run), The plugin then automatically searches the activity classes in your project and adds all the found to the Drop-down list in the Activity tab. We only have "Hello, Android" for a project, so it will be the default choice. Click on the "Apply" button, you are done, you only need to click the "Run" button, and then the Android emulator will be launched, your application will be displayed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.