|
| 1 | +# Bevy's Mobile Example |
| 2 | + |
| 3 | +## Android |
| 4 | + |
| 5 | +- **Build Library:** |
| 6 | + |
| 7 | + Run the following command to build the native library for Android: |
| 8 | + |
| 9 | + ```bash |
| 10 | + cargo ndk -t arm64-v8a -t armeabi-v7a -t x86 -t x86_64 -o android/app/src/main/jniLibs build --package bevy_mobile_example |
| 11 | + ``` |
| 12 | + |
| 13 | +- **Run Using Android Studio:** |
| 14 | + |
| 15 | + 1. Open **Android Studio** and navigate to `android`. |
| 16 | + 2. Start an Android emulator or connect a physical device. |
| 17 | + 3. Run or debug the application on the selected device. |
| 18 | + |
| 19 | +- **Run Using Shell Commands:** |
| 20 | + |
| 21 | + 1. Ensure you have a device available for testing: |
| 22 | + - **Emulator:** Create and launch an Android Virtual Device (AVD). |
| 23 | + - **USB Device:** Connect an Android device via USB. |
| 24 | + - **Wireless Device:** Pair your device using **Android Studio** (recommended for simplicity). |
| 25 | + |
| 26 | + 2. Start the ADB server and verify the connection: |
| 27 | + |
| 28 | + ```bash |
| 29 | + adb start-server |
| 30 | + adb devices |
| 31 | + ``` |
| 32 | + |
| 33 | + 3. Navigate to the Android project directory: |
| 34 | + |
| 35 | + ```bash |
| 36 | + cd android |
| 37 | + ``` |
| 38 | + |
| 39 | + 4. Ensure `./gradlew` has execution permissions: |
| 40 | + |
| 41 | + ```bash |
| 42 | + chmod +x ./gradlew |
| 43 | + ``` |
| 44 | + |
| 45 | + 5. Build the application: |
| 46 | + |
| 47 | + - **Debug:** |
| 48 | + |
| 49 | + ```bash |
| 50 | + ./gradlew assembleDebug |
| 51 | + ``` |
| 52 | + |
| 53 | + - **Release:** |
| 54 | + |
| 55 | + ```bash |
| 56 | + ./gradlew assembleRelease |
| 57 | + ``` |
| 58 | + |
| 59 | + - **Bundle (requires signing configuration in Gradle):** |
| 60 | + |
| 61 | + ```bash |
| 62 | + ./gradlew bundleRelease |
| 63 | + ``` |
| 64 | + |
| 65 | + 6. Install the application on the device: |
| 66 | + |
| 67 | + - **Debug:** |
| 68 | + |
| 69 | + ```bash |
| 70 | + adb install -r app/build/outputs/apk/debug/app-debug.apk |
| 71 | + ``` |
| 72 | + |
| 73 | + - **Release:** |
| 74 | + |
| 75 | + ```bash |
| 76 | + adb install -r app/build/outputs/apk/release/app-release-unsigned.apk |
| 77 | + ``` |
| 78 | + |
| 79 | + **Note:** The release build requires signing before installation. |
| 80 | + |
| 81 | + 7. Launch the application: |
| 82 | + |
| 83 | + ```bash |
| 84 | + adb shell am start -n org.bevyengine.mobile/.MainActivity |
| 85 | + ``` |
| 86 | + |
| 87 | +## iOS |
| 88 | + |
| 89 | +- **Run Using Xcode:** |
| 90 | + |
| 91 | + 1. Open **Xcode** by opening `bevh_mobile_example.xcodeproj`. |
| 92 | + 2. Select the target device (Simulator or Physical Device). |
| 93 | + 3. Click **Run** ▶️ or **Debug** 🛠️ to launch the application. |
| 94 | + |
| 95 | +- **Run Using Shell Commands:** |
| 96 | + |
| 97 | + - **Run on the First Available Simulator:** |
| 98 | + |
| 99 | + Simply run: |
| 100 | + |
| 101 | + ```sh |
| 102 | + make |
| 103 | + ``` |
| 104 | + |
| 105 | + This executes the default `run` command in the `Makefile`, launching the app on the first available simulator. |
| 106 | + |
| 107 | + - **Run on a Specific Device:** |
| 108 | + |
| 109 | + 1. **Find the Device ID:** |
| 110 | + |
| 111 | + - For **simulators**, run: |
| 112 | + |
| 113 | + ```sh |
| 114 | + xcrun simctl list devices |
| 115 | + ``` |
| 116 | + |
| 117 | + - For **physical devices**, run: |
| 118 | + |
| 119 | + ```sh |
| 120 | + xcrun xctrace list devices |
| 121 | + ``` |
| 122 | + |
| 123 | + - Copy the desired **Device ID**, e.g., `912BFD4B-9AFB-4DDE-983A-1816245DB2DA`. |
| 124 | + |
| 125 | + 2. **Run the App on the Selected Device:** |
| 126 | + |
| 127 | + ```sh |
| 128 | + make run DEVICE_ID=912BFD4B-9AFB-4DDE-983A-1816245DB2DA |
| 129 | + ``` |
| 130 | + |
| 131 | +## Desktop |
| 132 | + |
| 133 | +This section shows how to develop both mobile and desktop apps within the same Cargo.toml project. Developing on desktop is faster and easier, and you can simulate mobile resolution. When you're ready to release for mobile, you can simply build it for mobile at that point. |
| 134 | +
|
| 135 | +- **To run from the Bevy root:** |
| 136 | +
|
| 137 | + ```bash |
| 138 | + cargo run -p bevy_mobile_example |
| 139 | + ``` |
| 140 | +
|
| 141 | +- **To run from the Bevy examples directory for mobile:** |
| 142 | +
|
| 143 | + ```bash |
| 144 | + cargo run |
| 145 | + ``` |
0 commit comments