hz-android-2d-porting
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAndroid 2D App Porting to Horizon OS
将Android 2D应用移植到Horizon OS
When to Use
适用场景
Use this skill when:
- Porting an existing Android 2D app to run on Meta Quest headsets
- Adapting a mobile Android app for Horizon OS panels
- Troubleshooting input, layout, or compatibility issues with a 2D app on Quest
- Preparing an Android app for Horizon Store submission
- Evaluating whether an existing Android app is compatible with Horizon OS
在以下场景中使用本技能:
- 将现有Android 2D应用移植到Meta Quest头显运行
- 为Horizon OS面板适配移动Android应用
- 排查Quest上2D应用的输入、布局或兼容性问题
- 为Horizon Store提交准备Android应用
- 评估现有Android应用是否与Horizon OS兼容
Overview
概述
Horizon OS is built on Android (AOSP) and can run standard Android applications inside panels -- floating 2D windows positioned in 3D space. Most well-built Android apps work on Quest with minimal changes, but several areas require attention:
- Input: There is no touchscreen. Users interact via controller pointer (ray-casting), hand tracking, or connected peripherals.
- Layout: Apps run in resizable panels, not full-screen on a fixed display.
- Design: Apps must meet Horizon OS design requirements for Horizon Store approval.
- Performance: Quest uses a mobile GPU (Adreno) with thermal constraints.
The goal of porting is to make the app feel native to the Quest experience while preserving existing functionality.
Horizon OS基于Android(AOSP)构建,可在面板中运行标准Android应用——即位于3D空间中的浮动2D窗口。大多数构建完善的Android应用只需少量修改即可在Quest上运行,但有几个方面需要重点关注:
- 输入:无触摸屏。用户通过控制器指针(射线投射)、手部追踪或连接的外设进行交互。
- 布局:应用在可调整大小的面板中运行,而非在固定显示屏上全屏显示。
- 设计:应用必须满足Horizon OS的设计要求才能通过Horizon Store审核。
- 性能:Quest采用移动GPU(Adreno),存在散热限制。
移植的目标是在保留现有功能的同时,让应用在Quest上拥有原生体验。
Porting Workflow
移植流程
Step 1: Initial Testing
步骤1:初始测试
Invoke metavr (the Quest device CLI) via . The command is published as the npm package , so if is not on PATH you can run the same CLI via — no global install needed; npx fetches the latest published version on demand.
metavr <args>metavrmetavrnpx -y metavr <args>The examples in this doc call directly; the form above is the equivalent when is not on PATH (the published npm package is still ).
metavrnpx -y metavr <args>metavrmetavrInstall the existing APK on a connected Quest device and test basic functionality:
bash
metavr app install path/to/your-app.apk
metavr app launch com.example.yourappNote any immediate issues: crashes, black screens, input problems, or layout breakage.
通过调用metavr(Quest设备CLI)。该命令作为npm包发布,因此如果不在PATH中,你可以通过运行相同的CLI——无需全局安装;npx会按需获取最新发布的版本。
metavr <args>metavrmetavrnpx -y metavr <args>本文档中的示例直接调用;当不在PATH中时,上述形式是等效的(发布的npm包仍为)。
metavrmetavrnpx -y metavr <args>metavr将现有APK安装到已连接的Quest设备上并测试基本功能:
bash
metavr app install path/to/your-app.apk
metavr app launch com.example.yourapp记录任何即时问题:崩溃、黑屏、输入问题或布局损坏。
Step 2: Input Adaptation
步骤2:输入适配
The most common porting issue is input. Touch events are translated from the controller pointer, but:
- Hover states are now visible (users point before clicking)
- Scrolling uses the thumbstick, not swipe gestures
- Multi-touch gestures (pinch-to-zoom) do not translate directly
- Tap targets must be large enough for pointer accuracy (48dp minimum)
See Input Adaptation Reference for detailed guidance.
最常见的移植问题是输入。触摸事件会从控制器指针转换而来,但存在以下差异:
- 悬停状态现在可见(用户点击前会先指向)
- 滚动使用摇杆,而非滑动手势
- 多点触控手势(捏合缩放)无法直接转换
- 点击目标必须足够大以保证指针精度(最小48dp)
有关详细指导,请参阅输入适配参考。
Step 3: Layout Adjustment
步骤3:布局调整
Panels are resizable and can have various aspect ratios. Your app must handle:
- Dynamic width and height changes
- Landscape and portrait orientations
- Different effective DPI values
Use responsive layout strategies such as or Jetpack Compose. See Panel Layout Reference.
ConstraintLayout面板可调整大小,且具有多种宽高比。你的应用必须处理:
- 动态宽度和高度变化
- 横向和纵向方向
- 不同的有效DPI值
使用响应式布局策略,例如或Jetpack Compose。请参阅面板布局参考。
ConstraintLayoutStep 4: Gradle and Manifest Updates
步骤4:Gradle和清单更新
Update your build configuration to target Horizon OS:
kotlin
// build.gradle.kts
android {
defaultConfig {
minSdk = 29 // Android 10 minimum
targetSdk = 34 // API 34 or higher required for all new 2D panel apps
}
}Add required manifest entries for device targeting. See Gradle Setup Reference.
更新构建配置以适配Horizon OS:
kotlin
// build.gradle.kts
android {
defaultConfig {
minSdk = 29 // 最低要求Android 10
targetSdk = 34 // 所有新2D面板应用要求API 34或更高
}
}添加针对设备的必需清单条目。请参阅Gradle设置参考。
Step 5: Input Testing
步骤5:输入测试
Test with all supported input methods:
- Controller: point-and-click, thumbstick scroll, trigger tap
- Hand tracking: pinch-to-select, hand scroll
- Keyboard/mouse: Bluetooth peripherals, system keyboard for text fields
Use the XR Simulator for rapid iteration, then validate on-device.
使用所有支持的输入方法进行测试:
- 控制器:指向点击、摇杆滚动、扳机点击
- 手部追踪:捏合选择、手部滚动
- 键盘/鼠标:蓝牙外设、文本字段使用系统键盘
使用XR Simulator进行快速迭代,然后在设备上验证。
Step 6: Store Submission
步骤6:商店提交
Before submitting to the Horizon Store:
- Verify all Compatibility Requirements
- Test on at least Quest 3 and Quest 2 (if targeting both)
- Confirm the app works in both passthrough and immersive home environments
- Review Meta's content policies and technical requirements
提交到Horizon Store之前:
- 验证所有兼容性要求
- 至少在Quest 3和Quest 2上测试(如果同时针对这两款设备)
- 确认应用在透视模式和沉浸式主环境中均可正常工作
- 查看Meta的内容政策和技术要求
Quick Compatibility Check
快速兼容性检查
Works on Horizon OS
可在Horizon OS上运行的功能
| Feature | Status | Notes |
|---|---|---|
| Standard Android Views | Supported | TextView, RecyclerView, etc. |
| Jetpack Compose | Supported | Full Compose UI toolkit |
| WebView | Supported | Chromium-based |
| Media playback (ExoPlayer) | Supported | Video and audio |
| Networking (HTTP, WebSocket) | Supported | Wi-Fi connectivity |
| Room / SQLite | Supported | Local database |
| WorkManager | Supported | Background tasks |
| Notifications | Supported | Horizon OS notification panel |
| Bluetooth (peripherals) | Supported | Keyboard, mouse, gamepad |
| Android Accessibility APIs | Supported | TalkBack equivalent available |
| 功能 | 状态 | 说明 |
|---|---|---|
| 标准Android视图 | 支持 | TextView、RecyclerView等 |
| Jetpack Compose | 支持 | 完整的Compose UI工具包 |
| WebView | 支持 | 基于Chromium |
| 媒体播放(ExoPlayer) | 支持 | 视频和音频 |
| 网络(HTTP、WebSocket) | 支持 | Wi-Fi连接 |
| Room / SQLite | 支持 | 本地数据库 |
| WorkManager | 支持 | 后台任务 |
| 通知 | 支持 | Horizon OS通知面板 |
| 蓝牙(外设) | 支持 | 键盘、鼠标、游戏手柄 |
| Android无障碍API | 支持 | 有等效的TalkBack功能 |
Restricted or Unavailable
受限或不可用的功能
| Feature | Status | Notes |
|---|---|---|
| Camera (front-facing) | Not available | No standard camera in 2D mode |
| Telephony / SMS | Not available | No cellular radio |
| NFC | Not available | No NFC hardware |
| GPS / Fine location | Limited | Wi-Fi-based location only |
| Fingerprint / BiometricPrompt | Not available | Use Meta account auth instead |
| Split-screen (multi-window) | Limited | Use Spatial SDK panels instead |
| Google Play Services | Not available | Use Meta equivalents or alternatives |
| ARCore | Not available | Use Meta Spatial SDK for spatial features |
| Multi-touch gestures | Limited | Single pointer from controller |
| 功能 | 状态 | 说明 |
|---|---|---|
| 前置摄像头 | 不可用 | 2D模式下无标准摄像头 |
| 电话/SMS | 不可用 | 无蜂窝无线电 |
| NFC | 不可用 | 无NFC硬件 |
| GPS/精确定位 | 受限 | 仅支持基于Wi-Fi的定位 |
| 指纹/BiometricPrompt | 不可用 | 改用Meta账号认证 |
| 分屏(多窗口) | 受限 | 改用Spatial SDK面板 |
| Google Play服务 | 不可用 | 使用Meta等效服务或替代方案 |
| ARCore | 不可用 | 使用Meta Spatial SDK实现空间功能 |
| 多点触控手势 | 受限 | 仅支持控制器的单指针 |
Common Issues and Fixes
常见问题及修复方案
| Issue | Cause | Fix |
|---|---|---|
| App crashes on launch | Missing Google Play Services dependency | Remove or make GMS optional |
| Buttons too small to tap | Touch targets under 48dp | Increase minimum tap target size |
| No scroll in lists | Swipe-based scroll not triggered | Ensure |
| Keyboard doesn't appear | Custom input field not using | Use standard |
| Layout broken | Fixed-size layout assumptions | Use responsive layouts with |
| App requests unavailable permissions | Camera, telephony, etc. | Guard with |
| APK rejected for prohibited permissions | Library or plugin silently added a prohibited permission | Run |
| APK rejected for invalid signature | Signed with v1-only scheme | v2 signing is default in AGP 7.0+; for older AGP, add |
| 问题 | 原因 | 修复方案 |
|---|---|---|
| 应用启动崩溃 | 缺少Google Play Services依赖 | 移除该依赖或设为可选 |
| 按钮过小无法点击 | 点击目标小于48dp | 增加最小点击目标尺寸 |
| 列表无法滚动 | 未触发基于滑动的滚动 | 确保 |
| 键盘不弹出 | 自定义输入字段未使用 | 使用标准 |
| 布局损坏 | 假设布局尺寸固定 | 使用 |
| 应用请求不可用权限 | 摄像头、电话等权限 | 使用 |
| APK因权限被拒 | 库或插件静默添加了禁用权限 | 运行 |
| APK因签名无效被拒 | 仅使用v1签名方案 | AGP 7.0+默认使用v2签名;对于旧版AGP,在签名配置中添加 |
Key Concepts
核心概念
Compatibility Mode vs Native Targeting
兼容模式 vs 原生适配
Apps not specifically targeting Horizon OS run in compatibility mode:
- Fixed panel size (simulating a phone screen)
- Limited resizing
- Basic input translation
Apps that target Horizon OS with proper manifest entries run in native mode:
- Resizable panels
- Full input API support
- Access to Spatial SDK features (optional)
- Better integration with Horizon OS shell
未专门针对Horizon OS的应用将在兼容模式下运行:
- 固定面板尺寸(模拟手机屏幕)
- 调整大小受限
- 基础输入转换
通过正确的清单条目针对Horizon OS的应用将在原生模式下运行:
- 可调整大小的面板
- 完整的输入API支持
- 可访问Spatial SDK功能(可选)
- 与Horizon OS shell更好地集成
Testing Tools
测试工具
- metavr: Command-line tool for installing, launching, and debugging apps on Quest
- XR Simulator: Desktop tool for testing Quest apps without a headset
- Meta Quest Developer Hub (MQDH): GUI tool for device management and debugging
- Android Studio: Full IDE with Quest device support via ADB
- metavr:用于在Quest上安装、启动和调试应用的命令行工具
- XR Simulator:无需头显即可测试Quest应用的桌面工具
- Meta Quest Developer Hub (MQDH):用于设备管理和调试的GUI工具
- Android Studio:通过ADB支持Quest设备的完整IDE
Performance Considerations
性能注意事项
Quest devices have mobile-class hardware with strict thermal limits:
- GPU: Qualcomm Adreno (varies by Quest model)
- RAM: 6-12 GB shared between system and apps
- Thermal: Sustained workloads may trigger thermal throttling
- Avoid heavy overdraw and complex shader effects in 2D UI
- Minimize background work to reduce power consumption
- Test with representative data loads (large lists, images, etc.)
Quest设备采用移动级硬件,具有严格的散热限制:
- GPU:高通Adreno(因Quest型号而异)
- RAM:6-12 GB,由系统和应用共享
- 散热:持续工作负载可能触发热节流
- 避免2D UI中过度绘制和复杂着色器效果
- 尽量减少后台工作以降低功耗
- 使用代表性数据负载进行测试(大型列表、图像等)
References
参考资料
- Compatibility Requirements -- store requirements and API compatibility
- Input Adaptation -- adapting touch to controller and hand input
- Panel Layout -- responsive layout for Horizon OS panels
- Gradle Setup -- build configuration and manifest entries
- 兼容性要求——商店要求和API兼容性
- 输入适配——将触摸适配为控制器和手部输入
- 面板布局——Horizon OS面板的响应式布局
- Gradle设置——构建配置和清单条目