Build and start the android development environment-too detailed, step by step to teach you

Source: Internet
Author: User
Font Color Description: Black indicates understood content, and red indicates unsolved problems or knowledge points.

Directory

1. Install JDK... 1

1. Download JDK... 1

2. Install JDK... 1

3. Set environment variables... 3

Ii. Install eclipse. 5

1. Download eclipse... 5

2. Install eclipse... 5

3. Install SDK .. 5

1. Download SDK .. 5

2. Install the SDK... 5

3. SDK configuration... 8

4. Configure ADT .. 11

5. Create a simulator (AVD)... 13

6. helloworld program... 16

1. Create Android Project 16

2. Create an AVD device... 18

3. Compile and run the program... 19

4. debug the program... 20

7. Import an existing project... 23

Import non-android project method:... 23

Import Android project method:... 23

8. Install the APK software... 23

1. Install APK on the simulator... 23

2. Uninstall the APK software on the simulator... 25

3. Install APK on the real machine

4. Uninstall the APK software on the real machine

1. Install JDK

1. Download JDK

Open the website http://java.sun.com, click on the right side of the "Java SE", the figure 1-1 appears, click "JDK download" that is (https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewFilteredProducts-SingleVariationTypeFilter downloads download jdk-6u23-windows-i586.exe.

Figure 1-1 Java SE Download Page

2. Install JDK

Double-click jdk-6u21-windows-i586.exe to obtain the 1-2 interface.

Figure 1-2 Java SDK settings page

Click "Next" and change and confirm the installation path (D: \ Java \ jdk1.6.0 _ 21 \). Note that if you change the path, add Java \ jdk1.6.0 _ 21 \, to prevent the installation file from mixing with the D Drive file), click "Next ".

Figure 1-3 installation interface of the Java target folder

Change the path, click next, and then "complete ".

3. Set Environment Variables

XP: "My Computer", right-click attribute, "advanced", "environment variable", system variable (win7: "My Computer", right-click attribute, "Advanced System settings", "advanced", and "environment variable", and system variable ).

Set the following three attributes and their values:

Java_home: D: \ Program Files \ Java \ jdk1.6.0 _ 21

Point to the JDK installation path, where you should be able to find the bin, Lib, and other directories. You can select any disk directory for the JDK installation path, but it is recommended that the directory level be lighter.

Path: % java_home % \ bin; % java_home % \ JRE \ bin

Point to the JDK bin directory, which stores various compilation and execution commands so that the system can identify Java commands in any path, in addition, you do not need to enter the path of a large string when compiling and running the program on the console. Otherwise, you must first move the class file to the % java_home % \ bin directory every time the Java program runs, open dos and change the path to this path to execute the class file.

After JDK is installed, the directory contains two virtual machines (JRE and JRE under JDK). Therefore, the bin folder under the two virtual machines must be included.

If "jdk1.6.0 _ 21 \ bin" is not added to the path, the following figure appears:

Figure 1-4 javac Problems

Classpath:.; % java_home % \ Lib \ DT. jar;

Point to the class file search path during Java program compilation and runtime, and tell the JVM where the class to be used or executed is stored, so that the JVM can load the class file for the purpose of importing *, ".; "indicates to first find the class file in the current directory, DT. jar is used to run the Environment Library and provides support for Java swing display. You can use WinRAR to open it. The jar and zip formats are the same, but the extensions are different. Tools. jar is used to provide non-core libraries and utilities. Lib provides development tool files.

Open "start" à "run", enter "cmd", and enter the DOS system interface. Enter "javac". If the installation is successful, the system displays a series of javac command parameters and usage.

Note: ";" cannot be added after java_home. Note that the path name is JDK rather than JRE, and the variable name is case insensitive.

Supplement: DT. jar, Rt. jar, and tools. Jar

DT. jar and tools. jar are the two most basic java packages. They contain the most important Lang packages in Java to various advanced functions such as Visual swing packages, which are essential to Java.

Jar package

Category

Remarks

Tools. Jar

Tool library. The sun. Tools. java. * and sun. Tools. javac. * classes are required for compilation and running .*

Java XXX. java is equivalent to Java-classpath = % java_home %/lib/tools. jar xx. xxx. main XXX. java and javac encapsulate the preceding commands, so they are not added to classpath. The application server is used to compile JSP files. The application server loads the files by itself and does not need to set the files by itself.

Rt. Jar

Java basic library

By default, it is in the loading path of the root classloader and does not need to be added to classpath. Similarly, most jar files in JRE/lib are in this path. Check Method: delete RT in classpath. jar, use the Java-verbose command to detect.

DT. Jar

The class library of the runtime environment, mainly the swing package

It is best to add it when using swing. The eclipse Development Environment defaults to JRE, so you need to set it.

Reference resources:

3 jar package role: http://blog.csdn.net/hlw881008/article/details/5505251

Eclipse to see the role of 3 packages: http://blog.csdn.net/dy_paradise/article/details/3909212

The role of JDK folders: http://blog.csdn.net/qcontriver/archive/2010/03/09/5360975.aspx

Ii. Install eclipse1 and download eclipse

Open the official website www.eclipse.org, click downloads, select the Windows 32 bit eclipse classic 3.6.1 download, that is, http://www.eclipse.org/downloads/download.php? File =/Eclipse/downloads/drops/R-3.6.1-201009090800/eclipse-SDK-3.6.1-win32.zip. Download to D :\.

2. Install eclipse

Decompress the downloaded zipzip package, and create a desktop shortcut for the eclipse.exe graph (right-click the chart and select "send" to "à" desktop shortcut ") for ease of startup.

Note: The SDK is like a Java JDK, And the ADT is just an Eclipse plug-in, so there is no strict requirement on the installation sequence of the two.

3. Install sdk1 and download the SDK

Open website.

2. SDK Installation

Run the folder D: \ Android \ android-sdk_r08-windows \ Android-SDK-windows in the SDK manager.exe, the figure 3-1 appears, select the file to install, and then "Install ", long long wait time.

Figure 3-1 SDK installation page

If the message "failed to fetch URL…" is displayed ..." In the "android SDK and AVD manager" window, select "Settings" on the left and select "Force https ://... "option, click" Save & apply ", and re-run the SDK setup.exe

It took me a long time to download some outdated files. Click available packages to select a later SDK version.

Figure 3-2 available packages

Figure 3-3 installed packages

Note: In order to reduce the user's long wait time, package the downloaded Directory into a compressed file so that you can directly decompress the package without installing the SDK. See the android-sdk-windows.rar compressed package in the Software Directory.

After the installation is complete, the file list is as follows: some of the files may be redundant:

Add-ons: some extension libraries, such as Google APIs add-on

Docs: API documentation, etc.

Platforms: platform components of different versions

Samples: some instance programs

Tools: Various auxiliary tools

Usb_driver: Some USB drivers in Windows

Temp: stores temporary files during the Platform Component download process

3. SDK Configuration

Add the path to the folder where tools is located (my path is D: \ Program Files \ Android-SDK-Windows \ tools;) to the environment variable of path, the method is the same as setting environment variables.

Note: At this time, you must complete the android SDK installation before it can be successful. The specific operations are as follows:

1) SDK location points to the android directory

For the android option in window à preferences, the content filled in by SDK location should be the installation path of the android SDK (here is D: \ Android-SDK-windows.

Supplement: If you directly decompress the android-sdk-windows.rar package in the mongosdkinstallation process, you must configure the SDK to complete SDK installation.

Figure 3-4 Android SDK path Configuration

If you do not set the SDK Location Value, the figure 3-5 error is displayed.

Figure 3-5 SDK path not added Error

2) Update the SDK in eclipse

"Window", "android SDK and AVD manager", "installed packages", "update all", and "accept all", and "Install accepted", see Figure 3-6. The installation takes about 45 minutes. In the displayed "ADB restart" dialog box, click "yes" and close the dialog box except eclipse. At this time, the ADT is successfully installed.

"Failed to fetch URL http://dl-ssl.google.com/android/repository/repository.xml" appears after" Install accepted"

I searched a lot of information by using the following methods:

1) "setting" on the left of "android SDK and AVD manager", and select "Force https ://..." This option;

2) deselect ask before restarting adb4 and save the settings. The SDK download tool does not have "Save and apply". After modifying the settings, the tool automatically downloads repository at the specified address. XML (there are a lot of useless posts about Save and apply, such as adding environment variables and pressing enter to save. I was unable to use the r06 download tool after I changed the configuration of r05 for the first time .)

3) if the connection is successful, it indicates OK. The next step is to download and install

Problem: there is no "setting" option on the left side, but practice has proved that this problem is not serious.

Select the required package:

A. If you only need to try Android 2.0 emulator (simulator), you can install it by selecting "SDK platform Android 2.0. API 5, revision 1.

B. If you want to develop applications and game applications on This SDK, you need to accept and abide by all the permitted content (accept all)

Figure 3-6 SDK Update page

If the SDK is not updated, the error "an SDK target must be specified" will appear when you create an android project, 3-7.

Figure 3-7 an SDK target must be specified Interface

4. Configure ADT

Open eclipse, help-> install new software open Figure 4-1 dialog box

Figure 4-1 ADT download URL settings

Write volume all in location, change the key parts of the red box to the same, and click Next> on two different pages, select "I accept the terms of License Agreement" and "finish", and then wait for about 20 minutes for the system to install
Software. Note that "Security Warning" may appear at this time. It mainly means that the ADT contains unsigned content and is not valid or authentic. It does not matter if you want to continue the installation, click "OK", and eclipse will prompt you to restart to make the ADT take effect. Click "restart now.

Figure 4-2 ADT Installation

5. Create a simulator (AVD)

For Windows à Android SDK and AVD manager à Virtual Devices à New, follow the steps shown in Figure 5-1 and click Create AVD.

Note: If you click virtual devices in the left-side pane, and then click New on the right side, but the target drop-down list does not have any options, click available packages in the left-side pane, and select selected on the right, next, follow the prompts.

Figure 5-1 create a new Simulator

Explanation: target is the available platform of the simulator; SD card is the memory card of the mobile phone; skin is the screen size displayed by the simulator. The specific parameters are as follows:

WVGA: 800*480

Qvga: 320*240

VGA: 640*480

Hvga: 480*320

Wqvga400: 240*400

Wqvga432: 240*432

Wvga800: 800*480

Wvga854: 854*480

Alternatively, you can select resolution to set the simulator screen size. Value in hardware (special device required by AVD): the value of the specified LCD density (resolution) is automatically set by the selected skin.

Figure 5-2 run the simulator

Select SDK android2.2 and click Start à launch. The simulator in Figure 3-3 is displayed.

Figure 5-3 Start the simulator

Figure 5-4 Unknown Virtual Device

Android simulator error, emulator: Error: Unknown Virtual Device Name

Cause: the default position of my document is changed because the file path to be created is incorrectly referenced.

Method 1: Set "F: \ Users \ <username> \. copy the file under android to c: \ Users \ <username> \. android "below can solve this problem, but such a solution has an obvious drawback, that is, if you create another AVD, you have to re-copy it.

Method 2: "My Computer", right-click attribute, "advanced", "environment variable", "system variable", and "new", and the variable name is "android_sdk_home" (note, this variable name cannot be changed. It can only be this name !), Then change the variable value to the ". android "folder location, for example:" F: \ androidemulator ". Here I put it in the android SDK package with the value" D: \ Program Files \ Android-SDK-windows"

6. helloworld program 1. Create an android Project

"File" à "new" à "other" à "android" à "android Project". The page shown in Figure 3-1 is displayed, enter the project name, application name, package name, and create activity content as needed, and select build target.

Where:

Project name: The name of a project, which corresponds to a folder.

Build target: select the SDK version used by the application.

Application name: the name of the program, which usually appears in the title bar of the application.

Pakcage name: This name can be used at will theoretically, but pakcage has certain naming rules, that is, the first item indicates the organizational type, such as COM, org, and edu; the second object refers to the name of the organization, such as Sun. I use my own name. The third object can be defined based on my own category.

Creak activity: activity is a running entity of an andriod program. It is a bit similar to the main function in C language. The difference is that the android program can have multiple entities similar to the main function.

Min SDK version: This item is generally one-to-one correspondence with build target and does not need to be specified.

Figure 6-1 new Android Project

2. Create an AVD Device

See section 5. It does not matter if no AVD device is created, right-click the project and choose "Run as"> "Run deployments"> "Android Application"> "android" (enter the name of the project to be run) à "target" (set the device to mannul to prevent confusion when multiple devices are deployed) à "run ". In the displayed dialog box, select launch a new Android virtual device, select the SDK, and click OK.

3. Compile and run the program

Open the hello. Java file. Its content is 6-2:

Figure 6-2 content of the hello. Java File

Figure 6-3 Java build path settings

Project à properties. In the dialog box shown in Figure 6-3, check Android 2.2, click OK, run à run (CTRL + F11) à Yes à select SDK, and click Start à launch à OK, wait 2 minutes until the figure 6-4 result page appears, indicating that the operation is successful.

Note: Right-click the Java file to be run, and select "Run as"> "Run deployments"> "Android Application"> "android" (enter the name of the project to be run) à "target" (set the device to mannul to prevent confusion when multiple devices are deployed) à "run.

Figure 6-4 running result page

Reference Source: http://blog.csdn.net/zhq56030207/archive/2010/08/31/5852130.aspx

4. debug the program through ddms:

(1) switch the working interface of the eclipse development tool to the ddms label. See Figure 6-5 and figure 6-6.

Figure 6-5 open view layout display

Figure 6-6 view layout selection box

(2) On the "ddms" interface, select the "devices" tab and view its menu functions: debug process (debugging process), update threads (update thread), and update heap (update heap), cause GC (causing garbage collection), stop process (stop thread), screen capture (screen), reset ADB (restart Android debug Bridge) menu options.

Debug the program through "logcat" of ddms

(1) "logcat" uses static methods of the "andrdoi. util. log" class to locate errors and print system log messages.

Commonly used methods of andrdoi. util. Log include the following five:

Log. V (string tag, string MSG); verbose

Log. D (string tag, string MSG); debug

Log. I (string tag, string MSG); Info

Log. W (string tag, string MSG); warn

Log. E (string tag, string MSG); error, applicable to program debugging through breakpoint

Log. V and log. D information should only exist in the development process. The final version can only contain three types of log information: log. I, log. W, and log. E.

(2) Click the "run" --> "debug" menu command to enter the debugging mode.

(3) switch to the "ddms" interface and click the "logcat" tab to view the log information we just printed in the program. Different colors are used to indicate different levels of information for easy tracking.

(4) debugging method

1) set the breakpoint and run it in one step: double-click the mark column of a row.

2) declare a conditional breakpoint and trigger complete: the breakpoint is triggered when the expression value changes. Double-click the breakpoint and right-click the breakpoint. Select "breakpoint properties" and check "enable" and "Conditional". Write the expression variables in the box. when the conditions are met, the program will be suspended; you can also use code help when entering a conditional expression. In the context menu, press Ctrl + Shift + I or right-click the variable and select inspect. The result is displayed.

Figure 6-7 setting debugging page

7. How to import an existing project into a non-android project:

"File" à "import" à "general" à "existing project into workspace" à "Next" à "select root directory" à "Browse ", select the location of the project to be imported.

NOTE: If there is no Android package, you need to reset "build path ".

Import Android project method:

"File", "new", "project", "android", "android Project", "Next", and "contents", and "project name" (with another name) à "Create project from existing source" à "location" à "Browse" (select the folder where the android project is located and go. as of the folder where the XML file is located) à "build target" (select the simulator platform version) à "finish ".

8. Install APK software 1. Install APK software on the simulator

First, enter the folder where the android SDK is located. Because it takes several minutes to start the simulator, we first use the command (emulator-AVD youravdname) to start the simulator (Note: emulator.exe under the double-hit toolsfolder cannot start ); copy the files under plantform-tools to the tools under the android SDK folder (if there are repeated overwriting, you can also add the environment variables of plantform-tools), and then open "run ", enter cmd, click "OK", enter "ADB install", and pull the APK to be executed to CMD and press Enter. Then, the figure 8-1 appears, success!

Figure 8-1 command prompt Interface

Note: files under plantform-tools must be copied to tools or the path of plantform-tools must be added to the PATH environment variable, because the ADB command is in plantform-tools but not in tools, therefore, if you do not perform this operation, the 8-2 error will occur.

Figure 8-2 'adb' is not an internal or external command INTERFACE

If the APK file name contains Chinese characters, the figure 8-3 error will occur. You only need to change Chinese to English and numbers.

Figure 8-3 "segmentation fault" error page

Figure 8-4 APK installation result page

After the installation is successful, the icon in the red box appears on the simulator panel, and you can click it to run.

2. Uninstall the APK software on the simulator.

"Setting (setting icon in 8-4)" à "Applications" à "manage applications" à "waterwave" à "Uninstall" (uninstall) à "OK" (OK ). The "waterwave" icon on the panel disappears.

Figure 8-5 APK uninstalled successfully

3. Install APK on the real machine

First, select "Unknown Source"> "return"> "development"> "USB debugging" for "Settings"> "application"> ".

Method 1

Download and install the 91 mobile assistant for Android. Connect the mobile phone to the computer with USB and enable 91 assistant 8-6.

Figure 8-6 91 mobile assistant start page

"Manual connection" à "USB connection" à "?" The installation file appears in Figure 8-7. Click Install.

Figure 8-7 APK installation page

Alternatively, you can directly double-click. APK to install it on your mobile phone.

Method 2

Download the hiapk Installer (APK installer) from http://www.hiapk.com/bbs/thread-40316-1-1.html and double-click it to install it (only on your computer. This software will automatically associate your APK program. You only need to double-click the APK program to automatically install it on your mobile phone.

Figure 8-8 successful hiapk installer Installation

Fa 3

Install Astro (File Manager): Place astro.apk to the SD of the mobile phone, and then click the APK file in the SD card of the mobile phone file manager. Then the Astro icon will appear on the panel. When installing the software, copy the. APK file to the SD card to install and uninstall the software on the APK installer on your mobile phone.

Fa 4

Download a mobile phone built-in APK Installer (http://www.liqucn.com/k/77002.shtml, then copy the. APK file to the SD card, mobile phone operation installation can be.

Supplement: File Manager features: File Viewing, file management, file search, program uninstallation and backup, process management, and SD card status.

APK Installer: simplifies the APK File Installation Process and enables you to install the APK software on your computer.

Note: When the mobile phone is connected to the computer, you need to download the drive or APK Installer (commonly used bean clip, 91 Assistant). Otherwise, the mobile phone's memory card is connected to the computer, but the mobile phone is not connected.

4. Uninstall the APK software on the real machine

The uninstall method is the same as that on the simulator. For more information, see uninstall the APK software on the simulator.

 

 

References:

 

Download tutorial and development materials:

Android 15 this classic tutorial and more than 150 source code Android app development year-end summary-average daily income of 160 RMB has become a must for Android experts to master 28 main items and 10 suggestions to become a Java master needs 25 learning objectives achieved-classic 24 classic arm tutorial and learning development materials download 18 classic PHP tutorial and development materials download 14 classic inspirational tutorials by famous teachers22 download the classic oral English tutorial

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.