首页 > 代码库 > Android官方入门文档[2]运行你的应用程序

Android官方入门文档[2]运行你的应用程序

Android官方入门文档[2]运行你的应用程序

 

Running Your App
运行你的应用程序

 

This lesson teaches you to
1.Run on a Real Device
2.Run on the Emulator

You should also read
?Using Hardware Devices
?Managing AVDs with AVD Manager
?Managing Projects

这节课教你
1.运行在真实设备
2.运行在模拟器

你也应该阅读
?使用硬件设备
?管理自动真空淀积系统与AVD管理
?管理项目

 

If you followed the previous lesson to create an Android project, it includes a default set of "Hello World" source files that allow you to immediately run the app.
如果按照以前的教训,以创建一个Android项目,它包括了“Hello World”的源文件,使您可以立即运行的应用程序默认设置。

How you run your app depends on two things: whether you have a real device running Android and whether you‘re using Android Studio. This lesson shows you how to install and run your app on a real device and on the Android emulator, and in both cases with either Android Studio or the command line tools.
您如何运行你的应用程序取决于两件事情:你是否有运行Android以及是否正在使用Android Studio中的真实设备。本课向您展示如何安装和在真实的设备和Android模拟器上运行你的应用程序,并在这两种情况下,无论是与Android Studio或命令行工具。

 

Run on a Real Device
在真实设备上运行

 

-------------------------------------------------- ------------------------------
If you have a device running Android, here‘s how to install and run your app.
如果您有运行Android的设备,这里是如何安装和运行你的应用程序。

 

Set up your device
设置设备

 

1. Plug in your device to your development machine with a USB cable. If you‘re developing on Windows, you might need to install the appropriate USB driver for your device. For help installing drivers, see the OEM USB Drivers document.
1.插入您的设备开发机器使用USB电缆。如果您正在开发Windows上,您可能需要安装相应的USB驱动程序为您的设备。为了帮助安装驱动程序,请参阅OEM USB驱动程序文件。

2. Enable USB debugging on your device. ?On most devices running Android 3.2 or older, you can find the option under Settings > Applications > Development.
? On Android 4.0 and newer, it‘s in Settings > Developer options.
Note: On Android 4.2 and newer, Developer options is hidden by default. To make it available, go to Settings > About phone and tap Build number seven times. Return to the previous screen to find Developer options.
2.启用USB调试设备上。 ?On运行Android3.2或以上的大多数设备,你可以找到在设置>应用程序>开发的选项。
?在Android4.0及更高版本,它在设置>开发者选项。
注意:在Android4.2及更高版本,开发者选项默认是隐藏的。使其可用,进入设置>关于手机和开发内部版本号7次。返回到上一画面找到开发者的选择。

 

Run the app from Android Studio
运行Android Studio中的应用

 

1.Select one of your project‘s files and click Run  from the toolbar.
1.选择项目的文件之一,然后点击运行从工具栏。

2.In the Choose Device window that appears, select the Choose a running device radio button, select your device, and click OK .
2.在出现,选择选择运行设备单选按钮,选择您的设备,然后点击确定选择设备的窗口。

Android Studio installs the app on your connected device and starts it.
Android Studio安装连接的设备上的应用程序,并启动它。

 

Run the app from a command line
从命令行应用程序

 

1.Change directories to the root of your Android project and execute: ant debug
1.更改目录到你的Android项目和执行的根源: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
2.确保在Android SDK平台工具/目录包含在PATH环境变量,然后执行:adb install bin/MyFirstApp-debug.apk

3.On your device, locate MyFirstApp and open it.
3.在你的设备上,找到MyFirstApp并打开它。

That‘s how you build and run your Android app on a device! To start developing, continue to the next lesson.
这就是你如何建立和设备上运行Android应用程序!开始开发,继续下一课。

 

Run on the Emulator
在模拟器上运行

 

-------------------------------------------------- ------------------------------

Whether you‘re using Android Studio or the command line, to run your app on the emulator you need to first create an Android Virtual Device (AVD). An AVD is a device configuration for the Android emulator that allows you to model a specific device.

无论你使用的是Android Studio或在命令行中,要在模拟器上运行你的应用程序,你需要首先创建一个Android虚拟设备(AVD)。一个AVD是Android模拟器,可以让你到一个特定的设备型号的设备的配置。

 

Create an AVD

创建AVD


 
1.Launch the Android Virtual Device Manager: ?In Android Studio, select Tools > Android > AVD Manager, or click the AVD Manager icon  in the toolbar.
?Or, from the command line, change directories to <sdk>/tools/ and execute: android avd
Note: The AVD Manager that appears when launched from the command line is different from the version in Android Studio, so the following instructions may not apply.
1.启动Android虚拟设备管理器:?InAndroid Studio,选择Tools>Android > AVD管理器,或单击工具栏上的AVD管理器图标。
?或者,在命令行,将目录更改为<SDK>/工具/并执行:Android的AVD
注:在命令行启动时,将出现AVD管理器是从Android Studio中的版本不同,所以下面的说明可能不适用。
 技术分享
Figure 1. The AVD Manager main screen shows your current virtual devices.
图1. AVD管理器主屏幕上显示您当前的虚拟设备。

2.On the AVD Manager main screen (figure 1), click Create Virtual Device.
2.在AVD管理器主界面(图1),单击创建虚拟设备。

3.In the Select Hardware window, select a device configuration, such as Nexus 6, then click Next.
3.在选择硬件窗口中,选择一个设备配置,如Nexus的6,然后单击下一步。

4.Select the desired system version for the AVD and click Next.
4.选择所需的系统版本为AVD,然后单击下一步。

5.Verify the configuration settings, then click Finish.
5.验证配置设置,然后单击完成。

For more information about using AVDs, see Managing AVDs with AVD Manager.
有关使用自动真空淀积系统的更多信息,请参阅管理自动真空淀积系统与AVD管理器。

 

Run the app from Android Studio
运行Android Studio中的应用

 

1.In Android Studio, select your project and click Run  from the toolbar.
1.在Android Studio中,选择你的项目,点击运行从工具栏。

2.In the Choose Device window, click the Launch emulator radio button.
2.在选择设备窗口中,单击启动模拟器单选按钮。

3.From the Android virtual device pull-down menu, select the emulator you created, and click OK.
3.从Android 虚拟设备下拉菜单中,选择您创建的仿真器,然后单击确定。

 

It can take a few minutes for the emulator to load itself. You may have to unlock the screen. When you do, My First App appears on the emulator screen.
它可能需要几分钟的模拟器来加载自身。您可能需要解锁屏幕。当你这样做,我的第一个应用程序出现在仿真器屏幕上。


Run your app from the command line
在命令行中运行你的应用程序

 

1.Change directories to the root of your Android project and execute: ant debug
1.更改目录到你的Android项目和执行的根源: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
2.确保在Android SDK平台工具/目录包含在PATH环境变量,然后执行:adb install bin/MyFirstApp-debug.apk

3.On the emulator, locate MyFirstApp and open it.
3.在模拟器上,找到MyFirstApp并打开它。

That‘s how you build and run your Android app on the emulator! To start developing, continue to the next lesson.
这就是你如何建立并在模拟器上运行Android应用程序!开始开发,继续下一课。

本文翻译自:https://developer.android.com/training/basics/firstapp/running-app.html

Android官方入门文档[2]运行你的应用程序