Android Learning Route (iii) run your Android app

Source: Internet
Author: User

If you created your Android project in the previous lesson, it contains the default "Hello World" source file, which allows your project to run immediately.

How you run your app with two things: whether you have a real Android device and whether you're using Eclipse. This course shows you how to use Eclipse and command-line tools to install your app on the real machine and on the emulator.

Before you run your app, you have to look at these catalog files in your Android project:

AndroidManifest.xml
This manifest file describes the basic features of the application and its components. When you learn more training courses, you will find that you can define them in a variety of ways.

element of one of the most important elements in this manifest file <uses-sdk> . It android:minSdkVersion declares the android:targetSdkVersion compatibility of your app on different Android versions through and attributes. In your first project, it should look like this:

<manifest xmlns:android="Http://schemas.android.com/apk/res/android" ... >    <USES-SDK android:minsdkversion="8" android:targetsdkversion="very" />    ...</manifest>

You should stick android:targetSdkVersion to the version as high as possible and test it on the appropriate version. For more information, see Supporting Different Platform Versions.

src/
The
directory of your app's code. By default, it contains Activity classes that run when your app is started by icon.
res/
drawable-hdpi/
layout/
The directory where the application user interface is stored.
values/
A directory of other XML files that contain a collection of resources, such as String,color.

When you build and run the default Android app, the default Activity class starts and loads a layout file written with "Hello World". Although there is nothing exciting about this outcome, this example is important for you to know how to run an Android app before you develop it.

Running an app on a real machine

If you have an Android device, the following shows how to install and run the app on your device.

  1. Connect your device to the developed machine via USB. If you are developing under a Windows system, you may need to install the appropriate driver for your device. How to install the driver can produce the OEM USB drivers documentation.
  2. Enable USB debugging on your device.
      • on most Android 3.2 or older versions of the machine, You can find the options by settings > Apps > Development .
      • Settings > Developer Options .

        hint:   on Android 4.0 or newer devices, developer Options   is hidden by default. If you want to see it, you need to go to settings > About phone and then click Version number 7 consecutively. Then go back to the previous interface to see the developer Options .

Run your app through eclipse

    1. Open a file in your project and click Run on the toolbar.
    2. In the Run as interface that appears, select Android application and click OK.

Eclipse will install the app on the connected device and launch the app.

Or launch the app from the command line:

  1. In the command line, change the directory to the root of the project and then execute:
    Ant Debug
  2. Ensure that platform-tools/ it has been added to the PATH environment variable and then execute:
    ADB install bin/myfirstapp-debug.apk
  3. Find the myfirstactivity on your device and open it.
Running on the emulator

Whether you are using Eclipse or the command line, to run your app on the emulator, you must first create an Android Virtual Device (AVD). An AVD is a configuration that allows the Android emulator to mimic different devices.

Figure 1. The AVD Manager showing a few virtual devices.

Create an AVD:

  1. Start the Android virtual appliance to manage it:
    1. In Eclipse, click on the Android virtual device on the toolbar to manage it.
    2. On the command line, change the directory to the <sdk>/tools/ directory, and then do the following:
      Android AVD
  2. Click Newon the Android virtual device to manage its interface.
  3. Fill in the AVD details. Includes its name, target version, SD card size, skin, etc.
  4. Click Create AVD.
  5. Select the new AVD, and then click Start.
  6. After the simulator is started, unlock the emulator.

Run your app through eclipse.

    1. Open a file in your project and click Run on the toolbar.
    2. In the Run as interface that appears, select Android application and click OK.

Eclipse will install the app on the connected emulator and launch the app.

Or launch the app from the command line:

  1. Change the directory to the root of the project at the command line and execute:
    ant Debug 
  2. guaranteed platform-tools/   has been added to path environment variable, then execute:
    adb Install bin/myfirstapp-debug.apk 
  3. Locate myfirstactivity on the emulator, and then open it.


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.