Android learning route (3) run your Android Application
If you have created your Android project according to the previous lesson, it contains the default "Hello World" source file, allowing your project to run immediately.
How do you run your application? Two things: Whether you have a real Android device and whether you are using Eclipse. This course shows you how to use Eclipse and command line tools to install your application on a real machine and a simulator.
Before running your application, you must understand these directory files in the Android project:
AndroidManifest.xml
-
This manifest file describes the basic features of an application and its components. After learning more training courses, you will find that you can use multiple methods to define them in this document.
The Element. It usesandroid:minSdkVersionAndandroid:targetSdkVersionAttribute declares the compatibility of your application on different Android versions. In your first project, it should be like the following:
...
You should keep settingandroid:targetSdkVersionFor the latest version, and test on the corresponding version. For more information, see Supporting Different Platform Versions.
src/
-
The Directory of your application code. By default, it contains
ActivityClass, which is run when your application is started through the icon.
res/
-
Contains subdirectories of some application resources. There is only one part here:
drawable-hdpi/
-
Directory for storing image resources on high-resolution screens. Other directories contain resources designed for other resolution screens.
layout/
-
The directory that stores the application user interface.
values/
-
Directory for storing multiple other XML files. These files contain a set of resources, such as string and color.
When you build and run the default Android Application, the defaultActivityClass, and load the layout file with "Hello World. Although this result is not very exciting, this example is very important for you to understand how to run an Android Application before development.
Run applications on a real machine
If you have an Android device, the following shows how to install and run applications on your device.
- Connect your device to the developed machine through USB. If you develop a driver in Windows, you may need to install a proper driver for your device. For how to install the driver, see the oem usb Drivers documentation.
- Enable USB debugging on your device.
- In most Android 3.2 or older versions, you can useSettings> Application> DevelopmentTo find the corresponding options.
- On Android 4.0 or an updated deviceSettings> developer options.
Tip:On Android 4.0 or an updated device,Developer optionsIt is hidden by default. If you want to see it, you need to enterSettings> about mobile phoneAnd clickVersion NumberUnder 7. Then return to the previous interface and you will be able to seeDeveloper options.
Run applications through Eclipse
- Open a file in your project, and clickRun.
- InRunInterface, selectAndroid Application <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Authorization + oaMKPHA + authorization/LV382ouf3D/MHu0NDAtMb0tq/TptPDo7o8L3A + authorization/tcS4 + cS/authorization = "brush: java;"> ant debug
- Guarantee
platform-tools/Already addedPATHEnvironment variable, and then execute:adb install bin/MyFirstApp-debug.apk
- Find on your deviceMyFirstActivityAnd open it. Run on Simulator
Whether you are using Eclipse or the command line interface, to run your application on the simulator, you must first create an Android Virtual Device (AVD ). An AVD allows the Android simulator to simulate the configurations of different devices.
Figure 1. The AVD Manager showing a few virtual devices.
Create an AVD:
- Start the Android virtual device to manage it:
- In Eclipse, click Android virtual device management on the toolbar.
- In the command line, change the directory
/tools/ Directory, and then execute:android avd
- On the Android virtual device management page, clickNew.
- Enter AVD details. Including its name, target version, SD card size, skin, etc.
- ClickCreate AVD.
- Select a new AVD and clickStart.
- Unlock the simulator after it is started.
Run the application through Eclipse.
- Open a file in your project, and clickRun.
- InRunInterface, selectAndroid ApplicationThen clickOK.
Eclipse will install the application on the connected simulator and start the application.
Or start the application through the command line:
- In the command line, change the directory to the project root directory and then execute:
ant debug
- Guarantee
platform-tools/Already addedPATHEnvironment variable, and then execute:adb install bin/MyFirstApp-debug.apk
- FindMyFirstActivityAnd open it.