转载请注明出处:http://blog.csdn.net/dawanganban/article/details/9823623

Running Your App

PREVIOUSNEXT

THIS LESSONTEACHES YOU TO

1.    Run on a Real Device

2.    Run on the Emulator

YOU SHOULD ALSOREAD

·       Using Hardware Devices

·       Managing Virtual Devices

·       Managing Projects

If you followed the previous
lesson
 to create an Android project, it includesa default set of "Hello World" source files that allow you toimmediately run the app.

How you run your app depends on twothings: whether you have a real Android-powered device and whether you're usingEclipse. This lesson shows you how to install and run your app on a real deviceand on the Android emulator,
and in both cases with either Eclipse or thecommand line tools.

Before you run your app, you should beaware of a few directories and files in the Android project:

AndroidManifest.xml

The manifest
file
 describes the fundamentalcharacteristics of the app and defines each of its components. You'll learnabout various declarations in this file as you read more training classes.

One of the most important elements yourmanifest should include is the <uses-sdk> element.
This declares your app'scompatibility with different Android versions using the android:minSdkVersion andandroid:targetSdkVersion attributes.
For your first app, itshould look like this:

<manifest
xmlns:android="http://schemas.android.com/apk/res/android" ...>

    <uses-sdk android:minSdkVersion="8"android:targetSdkVersion="17"/>

    ...

</manifest>

You should always set the android:targetSdkVersion as
high as possible and test your app onthe corresponding platform version. For more information, read Supporting
Different PlatformVersions
.

src/

Directory for your app's main sourcefiles. By default, it includes an Activity class
that runs when your app islaunched using the app icon.

res/

Contains several sub-directories for app
resources
. Hereare just a few:

drawable-hdpi/

Directory for drawable objects (such asbitmaps) that are designed for high-density (hdpi) screens. Other drawabledirectories contain assets designed for other screen densities.

layout/

Directory for files that define yourapp's user interface.

values/

Directory for other various XML filesthat contain a collection of resources, such as string and color definitions.

When you build and run the defaultAndroid app, the default Activity class
starts and loads a layout filethat says "Hello World." The result is nothing exciting, but it'simportant that you understand how to run your app before you start developing.

Run on a RealDevice


If you have a real Android-powereddevice, here's how you can install and run your app:

1.     Plug in your device to your developmentmachine with a USB cable. If you're developing on Windows, you might need toinstall the appropriate USB driver for your device. For
help installingdrivers, see the OEM USB Drivers document.

2.     Enable USBdebugging on your device.

o   On most devices running Android 3.2 or older, you canfind the option under Settings > Applications > Development.

o   On Android 4.0 and newer, it's in Settings> Developer options.

Note: On Android 4.2 and newer, Developeroptions is
hidden by default. To make it available, go toSettings >About phone and tap Build number seven
times. Return to the previousscreen to findDeveloper options.

To run the app from Eclipse:

1.     Open one of your project's files andclick Run  from
the toolbar.

2.     In the Run as window that appears, select AndroidApplication and
click OK.

Eclipse installs the app on yourconnected device and starts it.

Or to run your app from a command line:

1.     Change directories to the root of yourAndroid project and execute:

ant debug

2.     Make sure the Android SDK platform-tools/ directory
is included in your PATH environment variable, then execute:

adb install bin/MyFirstApp-debug.apk

3.     On your device, locate MyFirstActivity and open it.

That's how you build and run yourAndroid app on a device! To start developing, continue to the next
lesson
.

Run on theEmulator


Whether you're using Eclipse or thecommand line, to run your app on the emulator you need to first create anAndroid
Virtual Device
 (AVD). An AVD is a device configurationfor the Android emulator that allows you to model different devices.

Figure 1. The AVD Manager showing a few virtualdevices.

To create an AVD:

1.     Launch the Android Virtual DeviceManager:

a.     In Eclipse, click Android Virtual DeviceManager from the toolbar.

b.    From the command line, changedirectories to<sdk>/tools/ and execute:

android avd

2.     In the AndroidVirtual Device Manager panel, click New.

3.     Fill in the details for the AVD. Give ita name, a platform target, an SD card size, and a skin (HVGA is default).

4.     Click CreateAVD.

5.     Select the new AVD from the AndroidVirtual Device Manager and click Start.

6.     After the emulator boots up, unlock theemulator screen.

To run the app from Eclipse:

1.     Open one of your project's files andclick Run  from
the toolbar.

2.     In the Run as window that appears, select AndroidApplication and
click OK.

Eclipse installs the app on your AVD andstarts it.

Or to run your app from the commandline:

1.     Change directories to the root of yourAndroid project and execute:

ant debug

2.     Make sure the Android SDK platform-tools/ directory
is included in your PATH environment variable, then execute:

adb install bin/MyFirstApp-debug.apk

3.     On the emulator, locate MyFirstActivity and open it.

That's how you build and run yourAndroid app on the emulator! To start developing, continue to the next
lesson
.

运行你的应用程序

这节课教你

1.    在真实设备上运行

2.    在模拟器上运行

你也应该阅读

·       使用硬件设备

·       管理虚拟设备

·       管理项目

如果你是按照上一课创建一个Android项目,该项目包括设一个默认的“Hello
World” 的源文件,我们可以立即运行。

你如何运行你的应用程序依赖于两件事情:你是否有一个真正的Andr​​oid设备和Eclipse。这一课将告诉您使用Eclipse或命令行工具Android项目在真实的设备和Android模拟器中如何安装和运行。

在你运行你的应用程序之前,注意在Android项目的几个目录和文件:

AndroidManifest.xml

清单文件描述了应用程序的基本特征,并定义每个组件。在后续的课程中会说明这个文件中的各种声明。

清单文件中最重要的元素之一是<uses-sdk>元素。 使用android:minSdkVersionandroid:targetSdkVersion属性声明您的应用程序对不同的Android版​​本的兼容性。 对于你的第一个应用程序,声明文件如下:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" ... >
    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
    ...
</manifest>

你应该设置您的应用程序在相应的平台版本尽可能高的android:targetSdkVersion。 欲了解更多信息,请阅读支持不同的平台版本 。

src/

您的应用程序的主源文件目录。 默认情况下,它包含了一个Activity类通过应用程序图标启动你的程序运行。

res/

包含几个应用程序资源的子目录 。 列举其中的几个子目录:

drawable-hdpi/

绘制资源(如位图),是专为高分辨率(hdpi)屏幕。 其他的绘制资源目录存放其他屏幕分辨率资源。

layout/

定义你的应用程序的用户界面的目录文件。

values/

其他各种XML文件,其中包含资源文件,如字符串和颜色定义文件。

当你建立并运行Android默认应用程序时,默认的Activity类启动并加载布局文件中的“Hello
World”。 其结果并不吃惊,但你要了解如何运行你的应用程序,然后开始开发。

在真正的设备上运行


如果你有一个真正的Andr​​oid设备,这里将说明如何在该设备中安装和运行您的应用程序:

1.     使用USB线将设备插入到你的开发机器。 如果在Windows系统上开发,你可能需要为您的设备安装相应的USB驱动程序。 安装驱动程序的帮助,请参阅OEM的USB驱动程序文件。

2.     您的设备上启用USB调试 。

o   在大多数设备上运行Android 3.2或以上,你可以找到下的选项设置>应用程序>开发 。

o   在Android 4.0和更高版本,它是在“设置”>“开发人员选项 。

注意:在Android 4.2和更高版本中, 开发人员选项默认是隐藏的。 为了使其可用,进入设置>关于手机和点击 Build
number
 七次。 返回到前一个画面,找到开发人员选项 。

从Eclipse中运行的应用程序:

1.     打开一个项目的文件,单击“ 运行 ”  从工具栏。

2.     在出现的窗口中运行 ,选择Android的应用程序,并单击“确定”。

Eclipse的安装连接的设备上的应用程序,并启动它。

或运行您的应用程序的命令行:

1.     更改你的Andr​​oid项目的根目录,然后执行:

ant debug

2.     请确保Android SDK的platform-tools/目录已经包含在你的PATH环境变量,然后执行:

          adb install bin/MyFirstApp-debug.apk

3.     在设备上,找到MyFirstActivity并打开它。

这就是你如何在设备上构建并运行Android应用程序! 继续下一课 。

在模拟器上运行


无论是在Eclipse或命令行中,在模拟器上运行你的应用,你需要首先创建一个Android虚拟设备 (AVD)。 一个AVD是一个为Android模拟器,它可以让你模拟不同设备配置的设备。

图1示出了几个虚拟设备AVD管理。

要创建一个AVD:

1.     运行Android虚拟设备管理:

a.     在Eclipse中,从工具栏单击“Android虚拟设备管理  。

b.    在命令行,更改目录到<sdk>/tools/执行:

             android avd 

2.     在Android虚拟设备管理器 “面板中,单击” 新建 “。

3.     填写AVD的细节。 给它一个名字,选择一个版本平台,设置SD卡大小和皮肤(HVGA是默认值)。

4.     单击 Create AVD

5.     从Android虚拟设备管理器“,单击” 开始 “选择新的AVD。

6.     模拟器启动后将模拟器的屏幕解锁。

从Eclipse中运行的应用程序:

1.     打开一个项目的文件,单击“ 运行 ”  从工具栏。

2.     在出现的窗口中运行 ,选择Android的应用程序,并单击“确定”。

Eclipse的AVD上安装的应用程序,并启动它。

或者运行你的应用程序的命令行:

1.     更改你的Andr​​oid项目的根目录,然后执行:

 ant debug

2.     请确保Android SDK的platform-tools/目录已经包含在你的PATH环境变量,然后执行:

  adb install bin/MyFirstApp-debug.apk 

3.     解锁模拟器,找到MyFirstActivity“并打开它。

这是在模拟器如何建立和运行Andr​​oid应用程序!继续下一课 。

Android官方教程翻译(2)——运行第一个程序的更多相关文章

  1. Android官方教程翻译(4)——启动另一个Activity

    Starting Another Activity 启动另一个Activity PREVIOUSNEXT THIS LESSON TEACHES YOU TO 这节课教你 1.   Respond t ...

  2. Android官方教程翻译(3)——创建一个简单的用户界面

    转载请注明出处:http://blog.csdn.net/dawanganban/article/details/9839523 Building a Simple User Interface 创建 ...

  3. Android官方教程翻译(1)——创建第一个Android应用

    转载请注明出处:http://blog.csdn.net/dawanganban/article/details/9822431 Building Your First App GETSTARTED ...

  4. Android官方教程翻译(6)——添加ActionBar

    The action bar allows you to add buttons for the most important action items relating to the app's c ...

  5. Android官方教程翻译(5)——设置ActionBar

    Setting Up the Action Bar 设置Action Bar PREVIOUSNEXT THIS LESSONTEACHES YOU TO 这节课教你 1.    Support An ...

  6. Java入门——编写并运行第一个程序

    Java入门——编写并运行第一个程序 摘要:本文主要介绍如何使用Java语言编写并通过DOS运行简单的程序. 编写简单的程序 在D盘新建一个文本文档,输入如下代码: class Hello { pub ...

  7. 运行第一个程序!hello world!

    第一个程序:1 //打印 hello world 2 3 #include <stdio.h> 4 int main() 5 { 6 printf("hello world!\n ...

  8. Android初级教程理论知识(第一章快速入门)

    一.综合介绍. Android项目的目录结构 Activity:应用被打开时显示的界面 src:项目代码 R.java:项目中所有资源文件的资源id Android.jar:Android的jar包, ...

  9. c# MongoDB Driver 官方教程翻译

    先贴官方文档地址:http://mongodb.github.io/mongo-csharp-driver/2.5/getting_started/quick_tour/ 安装部分很简单,nuget搜 ...

随机推荐

  1. 对Linux下常用头文件总结

    asm.current.h    定义全局项current ,其指向结构体struct  task_struct linux/sched.h    定义结构体task_struct ,只要包含此头文件 ...

  2. (转)Windows2008优化IIS7.5支持10万个同时请求的配置方法

    通过对IIS7的配置进行优化,调整IIS7应用池的队列长度,请求数限制,TCPIP连接数等方面,从而使WEB服务器的性能得以提升,保证WEB访问的访问流畅. 在运行中cmd后,输入:C:\Window ...

  3. SQL日期时间函数

    一.Sql Server中的日期与时间函数 1. 当前系统日期.时间  select getdate() 2. dateadd 在向指定日期加上一段时间的基础上,返回新的 datetime 值  例如 ...

  4. Gora快速入门 分类: C_OHTERS 2015-01-30 09:55 465人阅读 评论(0) 收藏

    概述 Gora是apache的一个开源项目. The Apache Gora open source framework provides an in-memory data model and pe ...

  5. 在windows下远程访问linux服务器

    在网络性能.安全性.可管理性上,Linux有着其他系统无法比拟的强大优势,而服务器对这些方面要求特别高,因此Linux常常被用来做服务器使用.而当我们需要维护linux服务器的时候,就需要远程访问li ...

  6. [Angular] NgRx/effect, why to use it?

    See the current implementaion of code, we have a smart component, and inside the smart component we ...

  7. 微信管理系统基于Flask+Vue+Celery+SQLAlchemy+Redis等实现

    https://zhuanlan.zhihu.com/p/28102858 现在绝大多数同学都在使用微信,不过微信有很多限制,比如: 微信聊天记录只保存在本地,换个手机那些内容就找不到了 微信扫码加群 ...

  8. Extended paging tables to map guest physical memory addresses from virtual memory page tables to host physical memory addresses in a virtual machine system

    A processor including a virtualization system of the processor with a memory virtualization support ...

  9. Android学习Scroller(三)——控件平移划过屏幕 (Scroller简单使用)

    MainActivity例如以下: package cc.cn; import android.os.Bundle; import android.view.View; import android. ...

  10. centos 软件安装的三种方式

    Linux下面安装软件的常见方法: 1.yum 替你下载软件 替你安装 替你解决依赖关系 点外卖 缺少的东西 外卖解决 1).方便 简单2)没有办法深入修改 yum install -y tree 2 ...