使用 Android Device Manager 管理虛擬裝置Managing Virtual Devices with the Android Device Manager

本文說明如何使用 Android Device Manager 來建立和設定可模擬實體 Android 裝置的 Android 虛擬裝置(Avd)。您可以使用這些虛擬裝置來執行和測試應用程式,而不需要依賴實體裝置。This article explains how to use the Android Device Manager to create and configure Android Virtual Devices (AVDs) that emulate physical Android devices. You can use these virtual devices to run and test your app without having to rely on a physical device.

當您確認已啟用硬體加速之後 (如硬體加速以提升模擬器效能中所述),下一個步驟是使用 Android Device Manager (另請參閱 Xamarin Android Device Manager) 建立可用於測試和偵錯應用程式的虛擬裝置。After you have verified that hardware acceleration is enabled (as described in Hardware Acceleration for Emulator Performance), the next step is to use the Android Device Manager (also referred to as the Xamarin Android Device Manager) to create virtual devices that you can use to test and debug your app.

Windows 上的 Android Device ManagerAndroid Device Manager on Windows

本指南會說明如何使用 Android Device Manager 建立、複製、自訂和啟動 Android 虛擬裝置。This article explains how to use the Android Device Manager to create, duplicate, customize, and launch Android virtual devices.

[裝置] 索引標籤中 Android Device Manager 的螢幕擷取畫面Screenshot of the Android Device Manager in the Devices tab

您會使用 Android Device Manager,來建立和設定在 Android Emulator 中執行的 Android 虛擬裝置 (AVD)。You use the Android Device Manager to create and configure Android Virtual Devices (AVDs) that run in the Android Emulator. 每個 AVD 都是可模擬實體 Android 裝置的模擬器組態。Each AVD is an emulator configuration that simulates a physical Android device. 這讓您能夠在模擬不同實體 Android 裝置的各種組態中,執行並測試應用程式。This makes it possible to run and test your app in a variety of configurations that simulate different physical Android devices.

需求Requirements

若要使用 Android Device Manager,您需要下列項目:To use the Android Device Manager, you will need the following items:

  • Visual Studio 2019 Community、Professional 或 Enterprise。Visual Studio 2019 Community, Professional, or Enterprise.

  • 或者需要 Visual Studio 2017 15.8 版或更新版本。OR Visual Studio 2017 version 15.8 or later is required. 支援 Visual Studio Community、Professional 和 Enterprise 版本。Visual Studio Community, Professional, and Enterprise editions are supported.

  • Visual Studio Tools for Xamarin 4.9 版或更新版本。Visual Studio Tools for Xamarin version 4.9 or later.

  • 必須安裝 Android SDK (請參閱設定 Xamarin.Android 的 Android SDK)。The Android SDK must be installed (see Setting up the Android SDK for Xamarin.Android). 確定會將 Android SDK 安裝於其預設位置 (若尚未安裝):C:\Program Files (x86)\Android\android-sdkBe sure to install the Android SDK at its default location if it is not already installed: C:\Program Files (x86)\Android\android-sdk.

  • 必須安裝下列套件 (透過 Android SDK 管理員):The following packages must be installed (via the Android SDK Manager):

    • Android SDK Tools 26.1.1 版或更新版本Android SDK Tools version 26.1.1 or later
    • Android SDK 平台工具 27.0.1 或更新版本Android SDK Platform-Tools 27.0.1 or later
    • Android SDK 建置工具 27.0.3 或更新版本Android SDK Build-Tools 27.0.3 or later
    • Android Emulator 27.2.7 或更新版本。Android Emulator 27.2.7 or later.

    這些套件應該會以 [已安裝] 狀態顯示,如下列螢幕擷取畫面所示:These packages should be displayed with Installed status as seen in the following screenshot:

    安裝 Android SDK ToolsInstalling Android SDK Tools

啟動裝置管理員Launching the Device Manager

按一下 [工具] > [Android] > [Android Device Manager],從 [工具] 功能表啟動 Android Device Manager:Launch the Android Device Manager from the Tools menu by clicking Tools > Android > Android Device Manager:

從 [工具] 功能表啟動 Device ManagerLaunching the Device manager from the Tools menu

如果啟動時出現下列錯誤對話方塊,請參閱疑難排解一節來取得因應措施的指示:If the following error dialog is presented on launch, see the Troubleshooting section for workaround instructions:

Android SDK 執行個體錯誤對話方塊

主畫面Main Screen

當您第一次啟動 Android 裝置管理員時,它所呈現的畫面會顯示所有目前設定的虛擬裝置。When you first launch the Android Device Manager, it presents a screen that displays all currently-configured virtual devices. 針對每部虛擬裝置,都會顯示名稱OS (Android 版本)、處理器記憶體大小及螢幕解析度For each virtual device, the Name, OS (Android Version), Processor, Memory size, and screen Resolution are displayed:

已安裝之裝置及其參數的清單List of installed devices and their parameters

當您選取清單中的裝置時,會在右邊出現 [啟動] 按鈕。When you select a device in the list, the Start button appears on the right. 您可以按一下 [啟動] 按鈕,使用此虛擬裝置來啟動模擬器:You can click the Start button to launch the emulator with this virtual device:

裝置映像的 [啟動] 按鈕Start button for a device image

當模擬器使用所選取的虛擬裝置啟動之後,[啟動] 按鈕就會變成 [停止] 按鈕,讓您可用來暫止模擬器:After the emulator starts with the selected virtual device, the Start button changes to a Stop button that you can use to halt the emulator:

適用於執行中裝置的 [停止] 按鈕Stop button for the running device

新裝置New Device

若要建立新裝置,按一下 [新增] 按鈕 (位於畫面的右上方區域):To create a new device, click the New button (located in the upper right-hand area of the screen):

建立新裝置的 [新增] 按鈕New button for creating a new device

按一下 [新增] 會啟動 [新裝置] 畫面:Clicking New launches the New Device screen:

裝置管理員的 [新裝置] 畫面New Device screen of the Device Manager

若要在 [新裝置] 畫面中設定新裝置,請使用下列步驟:To configure a new device in the New Device screen, use the following steps:

  1. 指定裝置的新名稱。Give the device a new name. 在下列範例中,會將新裝置命名為 Pixel_API_27In the following example, the new device is named Pixel_API_27:

    為新裝置命名Naming the new device

  2. 按一下 [基底裝置] 下拉式功能表來選取要模擬的實體裝置:Select a physical device to emulate by clicking the Base Device pull-down menu:

    選取要模擬的實體裝置Selecting the physical device to emulate

  3. 按一下 [處理器] 下拉式功能表來選取此虛擬裝置的處理器類型。Select a processor type for this virtual device by clicking the Processor pull-down menu. 選取 x86 會提供最佳效能,因為該選項可讓模擬器利用硬體加速功能。Selecting x86 will provide the best performance because it enables the emulator to take advantage of hardware acceleration. x86_64 選項也會使用硬體加速功能,但執行速度比 x86 稍微慢一點 (x86_64 通常用於測試 64 位元應用程式):The x86_64 option will also make use of hardware acceleration, but it runs slightly slower than x86 (x86_64 is normally used for testing 64-bit apps):

    選取處理器類型Selecting the processor type

  4. 按一下 [OS] 下拉式功能表來選取 Android 版本 (API 層級)。Select the Android version (API level) by clicking the OS pull-down menu. 例如,選取 Oreo 8.1 - API 27 以建立適用於 API 層級 27 的虛擬裝置:For example, select Oreo 8.1 - API 27 to create a virtual device for API level 27:

    選取 Android 版本Selecting the Android version

    如果您選取尚未安裝的 Android API 層級,Device Manager 會在畫面底部顯示 [A new device image will be downloaded] (即將下載新的裝置映像) 訊息 – 它會在建立新的虛擬裝置時下載並安裝必要檔案:If you select an Android API level that has not yet been installed, the Device Manager will display A new device will be downloaded message at the bottom of the screen – it will download and install the necessary files as it creates the new virtual device:

    即將下載新的裝置映像

  5. 如果您想要在虛擬裝置中包含 Google Play Services API,請啟用 [Google API] 選項。If you want to include Google Play Services APIs in your virtual device, enable the Google APIs option. 若要包含 Google Play 商店應用程式,請啟用 [Google Play 商店] 選項:To include the Google Play Store app, enable the Google Play Store option:

    選取 Google Play Services 和 Google Play 商店Selecting Google Play Services and Google Play Store

    請注意,Google Play 商店影像僅適用於某些基底裝置類型,例如 Pixel、Pixel 2、Nexus 5 和 Nexus 5X。Note that Google Play Store images are available only for some base device types such as Pixel, Pixel 2, Nexus 5, and Nexus 5X.

  6. 編輯您需要修改的任何屬性。Edit any properties that you need to modify. 若要變更內容,請參閱編輯 Android 虛擬裝置內容To make changes to properties, see Editing Android Virtual Device Properties.

  7. 新增您需要明確設定的任何其他屬性。Add any additional properties that you need to explicitly set. [新裝置] 畫面只會列出最常修改的屬性,但您可以按一下 [新增屬性] 下拉式功能表 (位於底部) 來新增其他屬性:The New Device screen lists only the most commonly-modified properties, but you can click the Add Property pull-down menu (at the bottom) to add additional properties:

    [新增屬性] 下拉式功能表Add Property pull-down menu

    您也可以選取屬性清單頂端的 [自訂...] 來定義自訂屬性。You can also define a custom property by selecting Custom... at the top of the property list.

  8. 按一下 [建立] 按鈕 (右下角) 來建立新裝置:Click the Create button (lower right-hand corner) to create the new device:

    [建立] 按鈕Create button

  9. 您可能會看見 [接受授權] 畫面。You might get a License Acceptance screen. 如果您同意授權條款,按一下 [接受]:Click Accept if you agree to the license terms:

    [接受授權] 畫面License Acceptance screen

  10. Android Device Manager 會將新裝置新增至已安裝的虛擬裝置清單中,並在建立裝置期間顯示 [正在建立] 進度列指示器:The Android Device Manager adds the new device to the list of installed virtual devices while displaying a Creating progress indicator during device creation:

    [正在建立] 進度列指示器Creation progress Indicator

  11. 當建立程序完成時,即會在已安裝的虛擬裝置清單中顯示新裝置,並具有 [啟動] 按鈕,準備好可供啟動:When the creation process is complete, the new device is shown in the list of installed virtual devices with a Start button, ready to launch:

    準備好可供啟動的新建裝置Newly-created device ready to launch

編輯裝置Edit Device

若要編輯現有的虛擬裝置,選取裝置,然後按一下 [編輯] 按鈕 (位於畫面右上角):To edit an existing virtual device, select the device and click the Edit button (located in the upper right-hand corner of the screen):

用於修改裝置的 [編輯] 按鈕Edit button for modifying a device

按一下 [編輯],會啟動適用於所選取虛擬裝置的裝置編輯器:Clicking Edit launches the Device Editor for the selected virtual device:

[裝置編輯器] 畫面Device Editor screen

[裝置編輯器] 畫面會在 [屬性] 欄下方列出虛擬裝置的屬性,其中包含 [值] 欄中每個屬性的對應值。The Device Editor screen lists the properties of the virtual device under the Property column, with the corresponding values of each property in the Value column. 當您選取屬性時,該屬性的詳細描述就會顯示在右邊。When you select a property, a detailed description of that property is displayed on the right.

若要變更屬性,請在 [值] 欄中編輯其值。To change a property, edit its value in the Value column. 例如,在下列螢幕擷取畫面中,正在將 hw.lcd.density 屬性從 480 變更為 240For example, in the following screenshot the hw.lcd.density property is being changed from 480 to 240:

裝置編輯範例Device Editing example

當您進行了必要的組態變更之後,按一下 [儲存] 按鈕。After you have made the necessary configuration changes, click the Save button. 如需變更虛擬裝置內容的詳細資訊,請參閱編輯 Android 虛擬裝置內容For more information about changing virtual device properties, see Editing Android Virtual Device Properties.

其他選項Additional Options

搭配裝置運作的其他選項都可從右上角的 [其他選項] (…) 下拉式功能表中取得:Additional options for working with devices are available from the Additional Options (…) pull-down menu in the upper right-hand corner:

[其他選項] 功能表的位置Location of additional options menu

[其他選項] 功能表包含下列項目:The additional options menu contains the following items:

  • 複製和編輯 – 複製目前選取的裝置,並使用不同的唯一名稱,在 [新裝置] 畫面中開啟它。Duplicate and Edit – Duplicates the currently-selected device and opens it in the New Device screen with a different unique name. 例如,選取 Pixel_API_27 並按一下 [複製和編輯],會將計數器附加到名稱:For example, selecting Pixel_API_27 and clicking Duplicate and Edit appends a counter to the name:

    [複製和編輯] 畫面Duplicate and Edit screen

  • 在檔案總管中顯示 – 在保存適用於虛擬裝置之檔案的資料夾中開啟 [Windows 檔案總管] 視窗。Reveal in Explorer – Opens a Windows Explorer window in the folder that holds the files for the virtual device. 例如,選取 Pixel_API_27 並按一下 [在檔案總管中顯示],會開啟類似下列範例的視窗:For example, selecting Pixel_API_27 and clicking Reveal in Explorer opens a window like the following example:

    按一下 [在檔案總管中顯示] 的結果Results of clicking Reveal in Explorer

  • 重設為原廠設定 – 當裝置正在執行時,將選取的裝置重設為其預設設定,清除對其內部狀態所做的任何使用者變更 (這也會清除目前的快速開機快照集,如果有的話)。Factory Reset – Resets the selected device to its default settings, erasing any user changes made to the internal state of the device while it was running (this also erases the current Quick Boot snapshot, if any). 這項變更不會改變您在建立和編輯期間對虛擬裝置所做的修改。This change does not alter modifications that you make to the virtual device during creation and editing. 隨即會出現一個對話方塊,提醒您此重設是無法復原的。A dialog box will appear with the reminder that this reset cannot be undone. 按一下 [恢復出廠預設值] 以確認重設:Click Factory Reset to confirm the reset:

    恢復出廠預設值對話方塊

  • 刪除 – 永久刪除所選取的虛擬裝置。Delete – Permanently deletes the selected virtual device. 隨即會出現一個對話方塊,提醒您刪除裝置是無法復原的。A dialog box will appear with the reminder that deleting a device cannot be undone. 如果您確定要刪除裝置,按一下 [刪除]。Click Delete if you are certain that you want to delete the device.

    刪除裝置對話方塊

macOS 上的 Android Device ManagerAndroid Device Manager on macOS

本指南會說明如何使用 Android Device Manager 建立、複製、自訂和啟動 Android 虛擬裝置。This article explains how to use the Android Device Manager to create, duplicate, customize, and launch Android virtual devices.

[裝置] 索引標籤中 Android Device Manager 的螢幕擷取畫面Screenshot of the Android Device Manager in the Devices tab

注意

本指南僅適用於 Visual Studio for Mac。This guide applies only to Visual Studio for Mac. Xamarin Studio 與 Android Device Manager 不相容。Xamarin Studio is incompatible with the Android Device Manager.

您會使用 Android Device Manager,來建立和設定在 Android Emulator 中執行的 Android 虛擬裝置 (AVD)。You use the Android Device Manager to create and configure Android Virtual Devices (AVDs) that run in the Android Emulator. 每個 AVD 都是可模擬實體 Android 裝置的模擬器組態。Each AVD is an emulator configuration that simulates a physical Android device. 這讓您能夠在模擬不同實體 Android 裝置的各種組態中,執行並測試應用程式。This makes it possible to run and test your app in a variety of configurations that simulate different physical Android devices.

需求Requirements

若要使用 Android Device Manager,您需要下列項目:To use the Android Device Manager, you will need the following items:

  • Visual Studio for Mac 7.6 或更新版本。Visual Studio for Mac 7.6 or later.

  • 必須安裝 Android SDK (請參閱設定 Xamarin.Android 的 Android SDK)。The Android SDK must be installed (see Setting up the Android SDK for Xamarin.Android).

  • 必須安裝下列套件 (透過 Android SDK 管理員):The following packages must be installed (via the Android SDK Manager):

    • SDK Tools 26.1.1 版 或更新版本SDK tools version 26.1.1 or later
    • Android SDK 平台工具 28.0.1 或更新版本Android SDK Platform-Tools 28.0.1 or later
    • Android SDK 建置工具 26.0.3 或更新版本Android SDK Build-Tools 26.0.3 or later

    這些套件應該會以 [已安裝] 狀態顯示,如下列螢幕擷取畫面所示:These packages should be displayed with Installed status as seen in the following screenshot:

    安裝 Android SDK ToolsInstalling Android SDK Tools

啟動裝置管理員Launching the Device Manager

按一下 [工具] > [Device Manager] 啟動 Android Device Manager:Launch the Android Device Manager by clicking Tools > Device Manager:

從 [工具] 功能表啟動 Device ManagerLaunching the Device manager from the Tools menu

如果啟動時出現下列錯誤對話方塊,請參閱疑難排解一節來取得因應措施的指示:If the following error dialog is presented on launch, see the Troubleshooting section for workaround instructions:

Android SDK 執行個體錯誤對話方塊

主畫面Main Screen

當您第一次啟動 Android 裝置管理員時,它所呈現的畫面會顯示所有目前設定的虛擬裝置。When you first launch the Android Device Manager, it presents a screen that displays all currently-configured virtual devices. 針對每部虛擬裝置,都會顯示名稱OS (Android 版本)、處理器記憶體大小及螢幕解析度For each virtual device, the Name, OS (Android Version), Processor, Memory size, and screen Resolution are displayed:

已安裝之裝置及其參數的清單List of installed devices and their parameters

當您選取清單中的裝置時,會在右邊出現 [播放] 按鈕。When you select a device in the list, the Play button appears on the right. 您可以按一下 [播放] 按鈕,使用此虛擬裝置來啟動模擬器:You can click the Play button to launch the emulator with this virtual device:

裝置映像的 [播放] 按鈕Play button for a device image

當模擬器使用所選取的虛擬裝置啟動之後,[播放] 按鈕就會變成 [停止] 按鈕,讓您可用來暫止模擬器:After the emulator starts with the selected virtual device, the Play button changes to a Stop button that you can use to halt the emulator:

適用於執行中裝置的 [停止] 按鈕Stop button for the running device

當您停止模擬器時,您可能會收到提示,詢問您是否要儲存目前狀態以供下次快速開機使用:When you stop the emulator, you may get a prompt asking if you want to save the current state for the next quick boot:

儲存目前狀態以供快速開機使用對話方塊

儲存目前狀態可在此虛擬裝置再次啟動時加快模擬器的開機速度。Saving the current state will make the emulator boot faster when this virtual device is launched again. 如需快速開機的詳細資訊,請參閱快速開機For more information about Quick Boot, see Quick Boot.

新裝置New Device

若要建立新的裝置,請按一下 [新增裝置] 按鈕 (位於畫面的左上方區域):To create a new device, click the New Device button (located in the upper left-hand area of the screen):

建立新裝置的 [新增] 按鈕New button for creating a new device

按一下 [新裝置] 會啟動 [新裝置] 畫面:Clicking New Device launches the New Device screen:

裝置管理員的 [新裝置] 畫面New Device screen of the Device Manager

使用下列步驟,在 [新裝置] 畫面中設定新裝置:Use the following steps to configure a new device in the New Device screen:

  1. 指定裝置的新名稱。Give the device a new name. 在下列範例中,會將新裝置命名為 Pixel_API_27In the following example, the new device is named Pixel_API_27:

    為新裝置命名Naming the new device

  2. 按一下 [基底裝置] 下拉式功能表來選取要模擬的實體裝置:Select a physical device to emulate by clicking the Base Device pull-down menu:

    選取要模擬的實體裝置Selecting the physical device to emulate

  3. 按一下 [處理器] 下拉式功能表來選取此虛擬裝置的處理器類型。Select a processor type for this virtual device by clicking the Processor pull-down menu. 選取 x86 會提供最佳效能,因為該選項可讓模擬器利用硬體加速功能。Selecting x86 will provide the best performance because it enables the emulator to take advantage of hardware acceleration. x86_64 選項也會使用硬體加速功能,但執行速度比 x86 稍微慢一點 (x86_64 通常用於測試 64 位元應用程式):The x86_64 option will also make use of hardware acceleration, but it runs slightly slower than x86 (x86_64 is normally used for testing 64-bit apps):

    選取處理器類型Selecting the processor type

  4. 按一下 [OS] 下拉式功能表來選取 Android 版本 (API 層級)。Select the Android version (API level) by clicking the OS pull-down menu. 例如,選取 Oreo 8.1 - API 27 以建立適用於 API 層級 27 的虛擬裝置:For example, select Oreo 8.1 - API 27 to create a virtual device for API level 27:

    選取 Android 版本Selecting the Android version

    如果您選取尚未安裝的 Android API 層級,Device Manager 會在畫面底部顯示 [A new device image will be downloaded] (即將下載新的裝置映像) 訊息 – 它會在建立新的虛擬裝置時下載並安裝必要檔案:If you select an Android API level that has not yet been installed, the Device Manager will display A new device will be downloaded message at the bottom of the screen – it will download and install the necessary files as it creates the new virtual device:

    即將下載新的裝置映像

  5. 如果您想要在虛擬裝置中包含 Google Play Services API,請啟用 [Google API] 選項。If you want to include Google Play Services APIs in your virtual device, enable the Google APIs option. 若要包含 Google Play 商店應用程式,請啟用 [Google Play 商店] 選項:To include the Google Play Store app, enable the Google Play Store option:

    選取 Google Play Services 和 Google Play 商店Selecting Google Play Services and Google Play Store

    請注意,Google Play 商店影像僅適用於某些基底裝置類型,例如 Pixel、Pixel 2、Nexus 5 和 Nexus 5X。Note that Google Play Store images are available only for some base device types such as Pixel, Pixel 2, Nexus 5, and Nexus 5X.

  6. 編輯您需要修改的任何屬性。Edit any properties that you need to modify. 若要變更內容,請參閱編輯 Android 虛擬裝置內容To make changes to properties, see Editing Android Virtual Device Properties.

  7. 新增您需要明確設定的任何其他屬性。Add any additional properties that you need to explicitly set. [新裝置] 畫面只會列出最常修改的屬性,但您可以按一下 [新增屬性] 下拉式功能表 (位於底部) 來新增其他屬性:The New Device screen lists only the most commonly-modified properties, but you can click the Add Property pull-down menu (at the bottom) to add additional properties:

    [新增屬性] 下拉式功能表Add Property pull-down menu

    您也可以按一下此屬性清單頂端的 [自訂...] 來定義自訂屬性。You can also define a custom property by clicking Custom... at the top of this property list.

  8. 按一下 [建立] 按鈕 (右下角) 來建立新裝置:Click the Create button (lower right-hand corner) to create the new device:

    [建立] 按鈕

  9. Android Device Manager 會將新裝置新增至已安裝的虛擬裝置清單中,並在建立裝置期間顯示 [正在建立] 進度列指示器:The Android Device Manager adds the new device to the list of installed virtual devices while displaying a Creating progress indicator during device creation:

    建立進度指標Creation progress indicator

  10. 當建立程序完成時,即會在已安裝的虛擬裝置清單中顯示新裝置,並具有 [啟動] 按鈕,準備好可供啟動:When the creation process is complete, the new device is shown in the list of installed virtual devices with a Start button, ready to launch:

    準備好可供啟動的新建裝置Newly-created device ready to launch

編輯裝置Edit Device

若要編輯現有的虛擬裝置,選取 [其他選項] 下拉式功能表 (齒輪圖示),然後選取 [編輯]:To edit an existing virtual device, select the Additional Options pull-down menu (gear icon) and select Edit:

用於修改新裝置的 [編輯] 功能表選取項目Edit menu selection for modifying a new device

按一下 [編輯],會啟動適用於所選取虛擬裝置的裝置編輯器:Clicking Edit launches the Device Editor for the selected virtual device:

[裝置編輯器] 畫面Device Editor screen

[裝置編輯器] 畫面會在 [屬性] 欄下方列出虛擬裝置的屬性,其中包含 [值] 欄中每個屬性的對應值。The Device Editor screen lists the properties of the virtual device under the Property column, with the corresponding values of each property in the Value column. 當您選取屬性時,該屬性的詳細描述就會顯示在右邊。When you select a property, a detailed description of that property is displayed on the right.

若要變更屬性,請在 [值] 欄中編輯其值。To change a property, edit its value in the Value column. 例如,在下列螢幕擷取畫面中,正在將 hw.lcd.density 屬性從 480 變更為 240For example, in the following screenshot the hw.lcd.density property is being changed from 480 to 240:

裝置編輯範例Device Editing example

當您進行了必要的組態變更之後,按一下 [儲存] 按鈕。After you have made the necessary configuration changes, click the Save button. 如需變更虛擬裝置內容的詳細資訊,請參閱編輯 Android 虛擬裝置內容For more information about changing virtual device properties, see Editing Android Virtual Device Properties.

其他選項Additional Options

搭配裝置運作的其他選項都可從位於 [播放] 按鈕左邊的下拉式功能表中取得:Additional options for working with a device are available from the pull-down menu located to the left of the Play button:

[其他選項] 功能表的位置Location of additional options menu

[其他選項] 功能表包含下列項目:The additional options menu contains the following items:

  • 編輯 – 在裝置編輯器中開啟目前選取的裝置,如前文所述。Edit – Opens the currently-selected device in the device editor as described earlier.

  • 複製和編輯 – 複製目前選取的裝置,並使用不同的唯一名稱,在 [新裝置] 畫面中開啟它。Duplicate and Edit – Duplicates the currently-selected device and opens it in the New Device screen with a different unique name. 例如,選取 Pixel 2 API 28 並按一下 [複製和編輯],會將計數器附加到名稱:For example, selecting Pixel 2 API 28 and clicking Duplicate and Edit appends a counter to the name:

    [複製和編輯] 畫面Duplicate and Edit screen

  • 在 Finder 中顯示 – 在保存適用於虛擬裝置之檔案的資料夾中開啟 macOS Finder 視窗。Reveal in Finder – Opens a macOS Finder window in the folder that holds the files for the virtual device. 例如,選取 Pixel 2 API 28 並按一下 [在 Finder 中顯示],會開啟類似下列範例的視窗:For example, selecting Pixel 2 API 28 and clicking Reveal in Finder opens a window like the following example:

    按一下 [在 Finder 中顯示] 的結果Results of clicking Reveal in Finder

  • 重設為原廠設定 – 當裝置正在執行時,將選取的裝置重設為其預設設定,清除對其內部狀態所做的任何使用者變更 (這也會清除目前的快速開機快照集,如果有的話)。Factory Reset – Resets the selected device to its default settings, erasing any user changes made to the internal state of the device while it was running (this also erases the current Quick Boot snapshot, if any). 這項變更不會改變您在建立和編輯期間對虛擬裝置所做的修改。This change does not alter modifications that you make to the virtual device during creation and editing. 隨即會出現一個對話方塊,提醒您此重設是無法復原的。A dialog box will appear with the reminder that this reset cannot be undone. 按一下 [恢復出廠預設值] 以確認重設。Click Factory Reset to confirm the reset.

    恢復出廠預設值對話方塊

  • 刪除 – 永久刪除所選取的虛擬裝置。Delete – Permanently deletes the selected virtual device. 隨即會出現一個對話方塊,提醒您刪除裝置是無法復原的。A dialog box will appear with the reminder that deleting a device cannot be undone. 如果您確定要刪除裝置,按一下 [刪除]。Click Delete if you are certain that you want to delete the device.

    刪除裝置對話方塊


疑難排解Troubleshooting

下列章節說明如何診斷和因應使用 Android Device Manager 設定虛擬裝置時可能發生的問題。The following sections explain how to diagnose and work around problems that may occur when using the Android Device Manager to configure virtual devices.

Android SDK 不在標準位置上Android SDK in Non-Standard Location

Android SDK 通常會安裝於下列位置:Typically, the Android SDK is installed at the following location:

C:\Program Files (x86)\Android\android-sdkC:\Program Files (x86)\Android\android-sdk

如果 SDK 不是安裝在此位置,您在啟動 Android Device Manager 時可能會收到這個錯誤:If the SDK is not installed at this location, you may get this error when you launch the Android Device Manager:

Android SDK 執行個體錯誤

若要解決這個問題,請使用下列步驟:To work around this problem, use the following steps:

  1. 從 Windows 桌面,瀏覽至 C:\Users\username\AppData\Roaming\XamarinDeviceManagerFrom the Windows desktop, navigate to C:\Users\username\AppData\Roaming\XamarinDeviceManager:

    Android Device Manager 記錄檔位置

  2. 按兩下以開啟其中一個記錄檔,並找出 Config file pathDouble-click to open one of the log files and locate the Config file path. 例如:For example:

    記錄檔中的 Config file pathConfig file path in log file

  3. 瀏覽至此位置,然後按兩下 user.config 加以開啟。Navigate to this location and double-click user.config to open it.

  4. user.config 中,找出 <UserSettings> 項目,並在其中新增 AndroidSdkPath 屬性。In user.config, locate the <UserSettings> element and add an AndroidSdkPath attribute to it. 將此屬性設定為電腦上安裝 Android SDK 的路徑,並儲存檔案。Set this attribute to the path where the Android SDK is installed on your computer and save the file. 例如,如果 Android SDK 安裝於 C:\Programs\Android\SDK,則 <UserSettings> 看起來如下:For example, <UserSettings> would look like the following if the Android SDK was installed at C:\Programs\Android\SDK:

    <UserSettings SdkLibLastWriteTimeUtcTicks="636409365200000000" AndroidSdkPath="C:ProgramsAndroidSDK" />
    

完成對 user.config 的變更後,您應該就能啟動 Android Device Manager。After making this change to user.config, you should be able to launch the Android Device Manager.

Android SDK Tools 的版本錯誤Wrong Version of Android SDK Tools

如果未安裝 Android SDK 工具 26.1.1 或更新版本,您會在啟動時看到此錯誤對話方塊:If Android SDK tools 26.1.1 or later is not installed, you may see this error dialog on launch:

Android SDK 執行個體錯誤對話方塊

如果您看到此錯誤對話方塊,請按一下 [開啟 Android SDK Manager] 以開啟Android SDK Manager。If you see this error dialog, click Open SDK Manager to open the Android SDK Manager. 在 Android SDK 管理員中,按一下 [工具] 索引標籤,然後安裝下列套件:In the Android SDK Manager, click the Tools tab and install the following packages:

  • Android SDK Tools 26.1.1 或更新版本Android SDK Tools 26.1.1 or later
  • Android SDK 平台工具 27.0.1 或更新版本Android SDK Platform-Tools 27.0.1 or later
  • Android SDK 建置工具 27.0.3 或更新版本Android SDK Build-Tools 27.0.3 or later

Android Oreo 上的快照功能會停用 WiFiSnapshot disables WiFi on Android Oreo

如果您有針對具有模擬 Wi-Fi 存取的 Android Oreo 設定 AVD,在使用快照功能後重新啟動 AVD 可能會造成 Wi-Fi 存取被停用。If you have an AVD configured for Android Oreo with simulated Wi-Fi access, restarting the AVD after a snapshot may cause Wi-Fi access to become disabled.

若要解決這個問題:To work around this problem,

  1. 在 Android Device Manager 中選取 AVD。Select the AVD in the Android Device Manager.

  2. 在其他選項功能表中,按一下 [在檔案總管中顯示]。From the additional options menu, click Reveal in Explorer.

  3. 瀏覽至 [快照] > [default_boot]。Navigate to snapshots > default_boot.

  4. 刪除 snapshot.pb 檔案:Delete the snapshot.pb file:

    snapshot.pb 檔案的位置

  5. 重新啟動 AVD。Restart the AVD.

做出這些變更之後,AVD 將會重新啟動為允許 Wi-Fi 再次運作的狀態。After these changes are made, the AVD will restart in a state that allows Wi-Fi to work again.

產生問題報告Generating a Bug Report

如果您發現 Android Device Manager 的問題且無法使用上述疑難排解提示來解決,請以滑鼠右鍵按一下標題列,然後選取 [產生 Bug 報告] 來提出問題報告:If you find a problem with the Android Device Manager that cannot be resolved using the above troubleshooting tips, please file a bug report by right-clicking the title bar and selecting Generate Bug Report:

建檔 Bug 報告的功能表項目位置Location of menu item for filing a bug report

總結Summary

此指南介紹適用於 Xamarin 的 Visual Studio Tools 以及適用於 Mac 的 Visual Studio 所提供的 Android Device Manager。This guide introduced the Android Device Manager available in Visual Studio Tools for Xamarin and Visual Studio for Mac. 其中說明了必要的功能,例如,啟動和停止 Android 模擬器、選取要執行的 Android 虛擬裝置 (AVD)、建立新的虛擬裝置,以及如何編輯虛擬裝置。It explained essential features such as starting and stopping the Android emulator, selecting an Android virtual device (AVD) to run, creating new virtual devices, and how to edit a virtual device. 它說明如何編輯設定檔硬體內容,以進一步自訂,並提供常見問題的疑難排解的秘訣。It explained how to edit profile hardware properties for further customization, and it provided troubleshooting tips for common problems.

Channel 9YouTube 上尋找更多 Xamarin 影片。Find more Xamarin videos on Channel 9 and YouTube.