天天看點

Android官方入門文檔[2]運作你的應用程式Android官方入門文檔[2]運作你的應用程式

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或指令行工具。

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

If you have a device running Android, here's how to install and run your app.

如果您有運作Android的裝置,這裡是如何安裝和運作你的應用程式。

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次。傳回到上一畫面找到開發者的選擇。

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安裝連接配接的裝置上的應用程式,并啟動它。

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應用程式!開始開發,繼續下一課。

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模拟器,可以讓你到一個特定的裝置型号的裝置的配置。

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中的版本不同,是以下面的說明可能不适用。

Android官方入門文檔[2]運作你的應用程式Android官方入門文檔[2]運作你的應用程式

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管理器。

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.

它可能需要幾分鐘的模拟器來加載自身。您可能需要解鎖螢幕。當你這樣做,我的第一個應用程式出現在仿真器螢幕上。

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應用程式!開始開發,繼續下一課。

繼續閱讀