標籤:android android應用 android開發 android emulator android studio
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]運行你的應用程式