Bevy 移动端开发指南
Bevy 确实支持 iOS 和 Android 平台开发,但需要特定的配置和工具链。本指南将详细介绍如何在移动平台上开发 Bevy 游戏。
支持状态
- ✅ iOS: 完全支持
- ✅ Android: 完全支持
- ⚠️ 注意:需要额外配置和工具链
环境准备
Android 开发环境
- 必需工具:
# 安装 Android SDK
rustup target add aarch64-linux-android armv7-linux-androideabi
# 安装 Android NDK
# 推荐使用 Android Studio 安装,或直接下载 NDK
# 安装 Cargo-apk
cargo install cargo-apk
- 环境变量配置:
export ANDROID_SDK_ROOT=/path/to/android-sdk
export NDK_HOME=/path/to/android-ndk
iOS 开发环境
- 必需工具:
# 安装 iOS 目标
rustup target add aarch64-apple-ios x86_64-apple-ios
# 安装 Xcode 命令行工具
xcode-select --install
# 安装 cargo-xcode
cargo install cargo-xcode
项目配置
Cargo.toml 配置
[package]
name = "my_bevy_game"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy = "0.11.0"
[lib]
name = "my_bevy_game"
crate-type = ["staticlib", "cdylib"]
[package.metadata.android]
build_targets = ["aarch64-linux-android", "armv7-linux-androideabi"]
min_sdk_version = 16
target_sdk_version = 31
[package.metadata.ios]
bundle_id = "com.example.mybevygame"
Android 配置
- 创建 android 目录结构:
my_bevy_game/
├── android/
│ ├── app/
│ │ ├── src/
│ │ │ └── main/
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── res/
│ │ │ └── java/
│ │ └── build.gradle
│ └── build.gradle
└── src/
- AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mybevygame">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity
android:name="android.app.NativeActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:exported