Android learning route (3) run your Android app, route android
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<uses-sdk>
Element. It usesandroid:minSdkVersion
Andandroid:targetSdkVersion
Attribute declares the compatibility of your application on different Android versions. In your first project, it should be like the following:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> ...</manifest>
You should keep settingandroid:targetSdkVersion
For 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
Activity
Class, 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 defaultActivity
Class, 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 ApplicationThen clickOK.
Eclipse will install the application on the connected device 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 addedPATH
Environment 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
<sdk>/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 addedPATH
Environment variable, and then execute:adb install bin/MyFirstApp-debug.apk
- FindMyFirstActivityAnd open it.
Android learning route
If java is done, it will be easier for android to learn.
Android BASICS (debugging in the Android development environment, Android Application structure, interface components and interface programming, and four main components)
Android intermediate (file IO and SQLite, graphics, images and animations, audio and video recording for playback, sensor programming, and GPS applications)
Android advanced (Network Programming and Web Service, OpenGL-ES 3D development, integration of Google services, using NDK development, java and c mutual calls)
Having a solid Java Foundation, learning the specific learning path of Android and learning videos and books of Android?
See if you want this? Other android documents can be downloaded from websites such as csdn.