在 Android 模拟器中运行 Sceneform 应用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
使用 Android 模拟器在没有实体设备的情况下测试 AR 场景。借助 Android 模拟器,您可以在受您控制的模拟设备的虚拟环境中运行 ARCore 应用。
设置您的开发环境
软件要求:
硬件要求:
- 您还需要一个支持 OpenGL ES 3.0 或更高版本的开发机器才能在您的应用中使用 Sceneform。
安装 Android Studio 3.1 或更高版本。
在 Android Studio 中,依次转到 Preferences > Appearance and Behavior > System Settings > Android SDK。
选择 SDK Platforms 标签页,然后勾选 Show Package Details。
在 Android 8.1 (Oreo) 下,选择:
Google APIs Intel x86 Atom System Image API 级别 27,版本 4 或更高版本。
选择 SDK Tools 标签页,然后添加 Android 模拟器 27.2.9 或更高版本。
点击 OK 以安装选定的软件包和工具。
再次点击确定以确认更改。
接受组件安装程序的许可协议。
点击 Finish。
创建支持 AR 的虚拟设备
您可以按照 Android Studio 说明来创建支持 AR 的虚拟设备。
- 选择 Pixel 或 Pixel 2 硬件配置文件。
- 选择 Oreo:API 级别 27:x86:Android 8.1 (Google API) 系统映像。
确认您的虚拟设备已正确配置:
- 转到验证配置 > 显示高级设置。
- 确保相机返回设置为 VirtualScene。
Sceneform 需要 OpenGL ES 3.0 或更高版本。
确保您的模拟器已配置为使用最新版本的 OpenGL ES:
- 点击正在运行的模拟器工具栏中的
。
- 依次选择设置 > > 高级 >:OpenGL ES API 级别 > 渲染程序最大值(最高为 OpenGL ES 3.1)。
- 重启模拟器。出现提示时,请勿保存当前状态。
重启模拟器后,与模拟设备进行短暂的互动,然后通过 grep 命令查看设备日志,检查是否使用了 OpenGL ES 3.0 或更高版本:
adb logcat | grep eglMakeCurrent
如果您看到 ver 3 0
或更高版本,则可以在模拟器中运行 Sceneform 应用:
… … … … D EGL_emulation: eglMakeCurrent: 0xebe63540: ver 3 0 (tinfo 0xd104cb40)
如果您看到的是更低版本,则表示您的桌面设备 GPU 不支持 OpenGL ES 3.0,您必须改用一台受支持的设备来运行 Sceneform 应用。
运行您的应用
在模拟器中支持 AR 的虚拟设备上测试 ARCore 应用。为此,您可以按照 Android Studio 说明在 Android 模拟器中运行应用。
更新面向 AR 的 Google Play 服务
模拟器上适用于 AR 的 Google Play 服务版本可能已过时。请按照以下说明进行更新:
从 GitHub 版本页面下载最新的 Google_Play_Services_for_AR_1.15.0_x86_for_emulator.apk。
将下载的 APK 安装到您要使用的每个 AVD 中:
启动所需的 AVD,然后将下载的 APK 拖动到正在运行的模拟器上,或者在虚拟设备运行时使用 adb
进行安装:
adb install -r Google_Play_Services_for_AR_1.15.0_x86_for_emulator.apk
对您要使用的任何其他 AVD 重复上述步骤。
控制虚拟场景
当应用连接到 ARCore 时,您会在模拟器窗口下方看到描述如何控制摄像头的叠加层和状态栏。
![]()
移动虚拟摄像头
按住 Option (macOS) 或 Alt(Linux 或 Windows)可以访问相机移动控件。使用以下控件可移动相机:
平台 |
操作 |
您需要采取的行动 |
macOS
|
向左或向右移动
|
按住 Option 键,然后按 A 或 D |
|
向下或向上移动
|
按住 Option + 按 Q 或 E |
|
前进或后退
|
按住 Option 并按 W 或 S |
|
更改设备屏幕方向
|
按住 Option 键并移动鼠标
|
Linux 或 Windows
|
向左或向右移动
|
按住 Alt + 按 A 或 D |
|
向下或向上移动
|
按住 Alt + 按 Q 或 E |
|
前进或后退
|
按住 Alt + 按 W 或 S |
|
更改设备屏幕方向
|
按住 Alt 并移动鼠标
|
释放 Option 或 Alt 以返回模拟器中的交互模式。
使用 Extended controls 中的 Virtual Sensors 标签页可更精确地定位设备。
问题排查提示
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2022-09-26。
[null,null,["最后更新时间 (UTC):2022-09-26。"],[[["\u003cp\u003eThe Android Emulator can be used to test ARCore apps in a virtual environment without a physical device, using a controlled emulated device.\u003c/p\u003e\n"],["\u003cp\u003eTo use the emulator for AR development, you need Android Studio 3.1 or later and Android Emulator 27.2.9 or later, along with a development machine supporting OpenGL ES 3.0 or higher.\u003c/p\u003e\n"],["\u003cp\u003eYou can create a virtual device with AR support by selecting the Pixel or Pixel 2 hardware profile and the Oreo: API Level 27: x86: Android 8.1 (Google APIs) system image, while ensuring the Camera Back is set to VirtualScene.\u003c/p\u003e\n"],["\u003cp\u003eTo configure the emulator to support Sceneform, you need to set the OpenGL ES API level to Renderer maximum (up to OpenGL ES 3.1) and verify that the emulator is using at least version 3.0.\u003c/p\u003e\n"],["\u003cp\u003eTo control the virtual camera within the AR environment, press and hold Option (macOS) or Alt (Linux/Windows) and use the A, S, D, W, Q, or E keys, or move the mouse for device orientation changes.\u003c/p\u003e\n"]]],["To test AR apps without a physical device, use the Android Emulator. First, install Android Studio 3.1+ and Android Emulator 27.2.9+. Configure the emulator with a Pixel/Pixel 2 device, Android 8.1 (API 27) system image, and set \"Camera Back\" to \"VirtualScene.\" Ensure OpenGL ES 3.0+ is enabled and update Google Play Services for AR. Control the virtual camera using Option/Alt plus WASD/QE keys or mouse movement. Finally, run the app on the emulator and interact with the AR environment.\n"],null,["# Run Sceneform apps in Android Emulator\n\nUse the [Android Emulator](//developer.android.com/studio/run/emulator.html)\nto test AR scenarios without a physical device. The Android Emulator lets you\nrun ARCore apps in a virtual environment with an emulated device that you\ncontrol.\n\nSet up your development environment\n-----------------------------------\n\nSoftware requirements:\n\n- [Android Studio](//developer.android.com/studio/) **3.1** or later.\n\n- [Android Emulator](//developer.android.com/studio/run/emulator.html#requirements)\n **27.2.9** or later.\n\nHardware requirements:\n\n- You'll also need a development machine that supports **OpenGL ES 3.0** or higher to use Sceneform in your app.\n\nGet Android Studio and SDK tools for ARCore\n-------------------------------------------\n\n1. Install [Android Studio](//developer.android.com/studio/) 3.1 or later.\n\n2. In Android Studio, go to **Preferences \\\u003e Appearance and Behavior \\\u003e System Settings \\\u003e Android SDK**.\n\n3. Select the **SDK Platforms** tab and check **Show Package Details**.\n\n Under **Android 8.1 (Oreo)** , select: \n\n **Google APIs Intel x86 Atom System Image** API Level 27, version 4 or later.\n4. Select the **SDK Tools** tab and add **Android Emulator** 27.2.9 or later.\n\n5. Click **OK** to install the selected pacakges and tools.\n\n6. Click **OK** again to confirm changes.\n\n7. Accept the license agreement for the Component Installer.\n\n8. Click **Finish**.\n\nCreate a virtual device with AR support\n---------------------------------------\n\nYou can follow the Android Studio instructions to [create a\nVirtual Device](//developer.android.com/studio/run/managing-avds.html#createavd)\nwith AR support.\n\n### Configure the virtual device\n\n- Select the **Pixel** or **Pixel 2** hardware profile.\n- Select the **Oreo: API Level 27: x86: Android 8.1 (Google APIs)** system image.\n- Confirm that your virtual device is configured correctly:\n\n - Go to **Verify Configuration \\\u003e Show Advanced Settings**.\n - Make sure that **Camera Back** is set to **VirtualScene**.\n\nConfigure the emulator to support Sceneform\n-------------------------------------------\n\nSceneform requires **OpenGL ES 3.0** or higher.\n\n1. Make sure your emulator is configured to use the latest version of\n OpenGL ES:\n\n - Click in the running emulator's toolbar.\n - Select **Settings \\\u003e Advanced \\\u003e OpenGL ES API level \\\u003e\n Renderer maximum (up to OpenGL ES 3.1)**.\n - Restart the emulator. When prompted, do not save the current state.\n2. After restarting the emulator, briefly interact with the emulated deivce,\n then check whether OpenGL ES 3.0 or higher is being used by grepping the\n device logs:\n\n \u003cbr /\u003e\n\n ```\n adb logcat | grep eglMakeCurrent\n ```\n\n \u003cbr /\u003e\n\n If you see **`ver 3 0`** or higher version, then you can run Sceneform\n apps in the emulator: \n\n ```\n … … … … D EGL_emulation: eglMakeCurrent: 0xebe63540: ver 3 0 (tinfo 0xd104cb40)\n ```\n\n \u003cbr /\u003e\n\n If you see a lower version, then your desktop GPU does not support\n OpenGL ES 3.0 and you must instead use a physical\n [supported device](/ar/discover/supported-devices) to run Sceneform apps.\n\nRun your app\n------------\n\nTest an ARCore app on an AR-supported virtual device in the emulator. To do\nthis, you can follow the [Android Studio instructions](//developer.android.com/studio/run/emulator.html#runningapp) to\nrun an app in the Android Emulator.\n| **Note:** To run apps with NDK components in the Android Emulator, your app must be built with [**x86 ABIs**](//developer.android.com/ndk/guides/abis.html). For an example, see the [**ARCore HelloAR C sample app**](//github.com/google-ar/arcore-android-sdk/tree/master/samples/hello_ar_c).\n\n### Update Google Play Services for AR\n\nThe version of Google Play Services for AR on the emulator is likely out of\ndate. Follow these instructions to update it:\n\n1. Download the latest **Google_Play_Services_for_AR_1.15.0_x86_for_emulator.apk** from the GitHub\n [releases](//github.com/google-ar/arcore-android-sdk/releases) page.\n\n2. Install the downloaded APK into each AVD you'd like to use:\n\n Start the desired AVD, then drag the downloaded APK onto the running\n emulator, or install it using `adb` while the virtual device is running: \n\n ```\n adb install -r Google_Play_Services_for_AR_1.15.0_x86_for_emulator.apk\n ```\n\n \u003cbr /\u003e\n\nRepeat these steps process for any additional AVDs you'd like to use.\n\n### Control the virtual scene\n\nWhen your app connects to ARCore, you'll see an overlay describing how to control\nthe camera and a status bar below the emulator window.\n\n#### Move the virtual camera\n\nPress and hold **Option** (macOS) or **Alt** (Linux or Windows) to access camera\nmovement controls. Use the following controls to move the camera:\n\n\u003cbr /\u003e\n\n| Platform | Action | What to do |\n|--------------------------|---------------------------|----------------------------------------|\n| **macOS** | Move left or right | Hold **Option** + press **A** or **D** |\n| | Move down or up | Hold **Option** + press **Q** or **E** |\n| | Move forward or back | Hold **Option** + press **W** or **S** |\n| | Change device orientation | Hold **Option** + move mouse |\n| **Linux** or **Windows** | Move left or right | Hold **Alt** + press **A** or **D** |\n| | Move down or up | Hold **Alt** + press **Q** or **E** |\n| | Move forward or back | Hold **Alt** + press **W** or **S** |\n| | Change device orientation | Hold **Alt** + move mouse |\n\n\u003cbr /\u003e\n\nRelease **Option** or **Alt** to return to interactive mode in the emulator.\n\nUse the **Virtual Sensors** tab in [Extended controls](//developer.android.com/studio/run/emulator.html#extended)\nfor more precise device positioning.\n\n### Troubleshooting tips\n\n- If your ARCore app launches and you see an \"AR Core not supported\" message,\n check the revision on your system image. Make sure you are using\n **API Level 27 Revision 4**.\n\n- If your ARCore app fails to open the camera when it launches, make sure that\n **Camera Back** is set to **VirtualScene** , as described in the [configuration\n steps above](#configure_the_virtual_device)."]]