Chinaunix首页 | 论坛 | 博客
  • 博客访问: 97947
  • 博文数量: 21
  • 博客积分: 451
  • 博客等级: 一等列兵
  • 技术积分: 215
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-03 20:46
个人简介

记录技术旅程

文章分类

全部博文(21)

文章存档

2014年(3)

2011年(18)

我的朋友

分类: LINUX

2011-03-18 11:10:46

There are two ways to build your application using the Ant build script: one for testing/debugging your application — debug mode — and one for building your final package for release — release mode. Regardless of which way you build your application, it must be signed before it can install on an emulator or device—with a debug key when building in debug mode and with your own private key when building in release mode.

Whether you're building in debug mode or release mode, you need to use the Ant tool to compile and build your project. This will create the .apk file that you can install on an emulator or device. When you build in debug mode, the .apk file is automatically signed by the SDK tools with a debug key, so it's instantly ready for installation onto an emulator or attached development device. You cannot distribute an application that is signed with a debug key. When you build in release mode, the .apk file is unsigned, so you must manually sign it with your own private key, using Keytool and Jarsigner.

Building in debug mode

For immediate application testing and debugging, you can build your application in debug mode and immediately install it on an emulator. In debug mode, the build tools automatically sign your application with a debug key and optimize the package with zipalign.

To build in debug mode:

  1. Open a command-line and navigate to the root of your project directory.
  2. Use Ant to compile your project in debug mode:
    ant debug

    This creates your debug .apk file inside the project bin/ directory, named -debug.apk. The file is already signed with the debug key and has been aligned with zipalign.

Each time you change a source file or resource, you must run Ant again in order to package up the latest version of the application.

To install and run your application on an emulator, see the following section about Running on the Emulator.

Running on the emulator

Before you can run your application on the Android Emulator, you must create an AVD.

To run your application:

  1. Open the SDK and AVD Manager and launch a virtual device

    From your SDK's tools/ directory, execute the android tool with no arguments:

    android

    In the Virtual Devices view, select an AVD and click Start.

  2. Install your application

    From your SDK's platform-tools/ directory, install the .apk on the emulator:

    adb install <path_to_your_bin>.apk

    Your .apk file (signed with either a release or debug key) is in your project bin/ directory after you build your application.

    If there is more than one emulator running, you must specify the emulator upon which to install the application, by its serial number, with the -s option. For example:

    adb -s emulator-5554 install path/to/your/app.apk

    To see a list of available device serial numbers, execute adb devices.

If you don't see your application on the emulator, try closing the emulator and launching the virtual device again from the SDK and AVD Manager. Sometimes when you install an application for the first time, it won't show up in the application launcher or be accessible by other applications. This is because the package manager usually examines manifests completely only on emulator startup.

阅读(1555) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~