Skip to content

Commit bbd0d32

Browse files
authored
Try #7493:
2 parents 6506ea4 + ee1daec commit bbd0d32

File tree

21 files changed

+64
-130
lines changed

21 files changed

+64
-130
lines changed

.github/workflows/post-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
--no-push \
4545
--exclude ci \
4646
--exclude errors \
47-
--exclude bevy-ios-example \
47+
--exclude bevy_mobile_example \
4848
--exclude build-wasm-example
4949
5050
- name: Create PR

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
--dependent-version upgrade \
4242
--exclude ci \
4343
--exclude errors \
44-
--exclude bevy-ios-example \
44+
--exclude bevy_mobile_example \
4545
--exclude build-wasm-example
4646
4747
- name: Create PR

.github/workflows/validation-jobs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
run: rustup target add aarch64-apple-ios x86_64-apple-ios
3030

3131
- name: Build and install iOS app in iOS Simulator.
32-
run: cd examples/ios && make install
32+
run: cd examples/mobile && make install
3333

3434
build-android:
3535
runs-on: ubuntu-latest
@@ -56,7 +56,7 @@ jobs:
5656
run: cargo install --force cargo-apk
5757

5858
- name: Build APK
59-
run: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME cargo apk build --package bevy-android-example
59+
run: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME cargo apk build --package bevy_mobile_example
6060

6161
run-examples-on-windows-dx12:
6262
runs-on: windows-latest

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ rust-version = "1.67.0"
1616
exclude = ["benches", "crates/bevy_ecs_compile_fail_tests", "crates/bevy_reflect_compile_fail_tests"]
1717
members = [
1818
"crates/*",
19-
"examples/android",
20-
"examples/ios",
19+
"examples/mobile",
2120
"tools/ci",
2221
"tools/build-example-pages",
2322
"tools/build-wasm-example",

crates/bevy_audio/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ anyhow = "1.0.4"
2121
rodio = { version = "0.16", default-features = false }
2222
parking_lot = "0.12.1"
2323

24+
[target.'cfg(target_os = "android")'.dependencies]
25+
oboe = { version = "0.4", features = ["shared-stdcxx"] }
26+
2427
[target.'cfg(target_arch = "wasm32")'.dependencies]
2528
rodio = { version = "0.16", default-features = false, features = ["wasm-bindgen"] }
2629

crates/bevy_winit/src/lib.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ struct WinitPersistentState {
230230
impl Default for WinitPersistentState {
231231
fn default() -> Self {
232232
Self {
233-
active: true,
233+
active: false,
234234
low_power_event: false,
235235
redraw_request_sent: false,
236236
timeout_reached: false,
@@ -289,7 +289,7 @@ pub fn winit_runner(mut app: App) {
289289
}
290290
}
291291

292-
{
292+
if winit_state.active {
293293
#[cfg(not(target_arch = "wasm32"))]
294294
let (commands, mut new_windows, created_window_writer, winit_windows) =
295295
create_window_system_state.get_mut(&mut app.world);
@@ -474,14 +474,7 @@ pub fn winit_runner(mut app: App) {
474474
}
475475
},
476476
WindowEvent::Touch(touch) => {
477-
let mut location =
478-
touch.location.to_logical(window.resolution.scale_factor());
479-
480-
// On a mobile window, the start is from the top while on PC/Linux/OSX from
481-
// bottom
482-
if cfg!(target_os = "android") || cfg!(target_os = "ios") {
483-
location.y = window.height() as f64 - location.y;
484-
}
477+
let location = touch.location.to_logical(window.resolution.scale_factor());
485478

486479
// Event
487480
input_events
@@ -615,6 +608,13 @@ pub fn winit_runner(mut app: App) {
615608
}
616609
event::Event::Suspended => {
617610
winit_state.active = false;
611+
#[cfg(target_os = "android")]
612+
{
613+
// Bevy doesn't support suspend/resume so we just exit
614+
// and Android will restart the application on resume
615+
// TODO: Save save some state and load on resume
616+
*control_flow = ControlFlow::Exit;
617+
}
618618
}
619619
event::Event::Resumed => {
620620
winit_state.active = true;

examples/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ When using `NDK (Side by side)`, the environment variable `ANDROID_NDK_ROOT` mus
368368
To run on a device setup for Android development, run:
369369

370370
```sh
371-
cargo apk run --example android_example
371+
cargo apk run -p bevy_mobile_example
372372
```
373373

374374
When using Bevy as a library, the following fields must be added to `Cargo.toml`:
@@ -415,7 +415,7 @@ min_sdk_version = >>API or less<<
415415

416416
Example | File | Description
417417
--- | --- | ---
418-
`android` | [`android/android.rs`](./android/android.rs) | The `3d/3d_scene.rs` example for Android
418+
`android` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound
419419

420420
## iOS
421421

@@ -436,7 +436,7 @@ rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim
436436
Using bash:
437437

438438
```sh
439-
cd examples/ios
439+
cd examples/mobile
440440
make run
441441
```
442442

@@ -451,15 +451,15 @@ DEVICE_ID=${YOUR_DEVICE_ID} make run
451451
If you'd like to see xcode do stuff, you can run
452452

453453
```sh
454-
open bevy_ios_example.xcodeproj/
454+
open bevy_mobile_example.xcodeproj/
455455
```
456456

457457
which will open xcode. You then must push the zoom zoom play button and wait
458458
for the magic.
459459

460460
Example | File | Description
461461
--- | --- | ---
462-
`ios` | [`ios/src/lib.rs`](./ios/src/lib.rs) | The `3d/3d_scene.rs` example for iOS
462+
`ios` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound
463463

464464
## WASM
465465

examples/README.md.tpl

+5-5
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ When using `NDK (Side by side)`, the environment variable `ANDROID_NDK_ROOT` mus
9898
To run on a device setup for Android development, run:
9999

100100
```sh
101-
cargo apk run --example android_example
101+
cargo apk run -p bevy_mobile_example
102102
```
103103

104104
When using Bevy as a library, the following fields must be added to `Cargo.toml`:
@@ -145,7 +145,7 @@ min_sdk_version = >>API or less<<
145145

146146
Example | File | Description
147147
--- | --- | ---
148-
`android` | [`android/android.rs`](./android/android.rs) | The `3d/3d_scene.rs` example for Android
148+
`android` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound
149149

150150
## iOS
151151

@@ -166,7 +166,7 @@ rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim
166166
Using bash:
167167

168168
```sh
169-
cd examples/ios
169+
cd examples/mobile
170170
make run
171171
```
172172

@@ -181,15 +181,15 @@ DEVICE_ID=${YOUR_DEVICE_ID} make run
181181
If you'd like to see xcode do stuff, you can run
182182

183183
```sh
184-
open bevy_ios_example.xcodeproj/
184+
open bevy_mobile_example.xcodeproj/
185185
```
186186

187187
which will open xcode. You then must push the zoom zoom play button and wait
188188
for the magic.
189189

190190
Example | File | Description
191191
--- | --- | ---
192-
`ios` | [`ios/src/lib.rs`](./ios/src/lib.rs) | The `3d/3d_scene.rs` example for iOS
192+
`ios` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound
193193

194194
## WASM
195195

examples/android/src/lib.rs

-54
This file was deleted.

examples/ios/Cargo.toml

-14
This file was deleted.
File renamed without changes.

examples/android/Cargo.toml examples/mobile/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[package]
2-
name = "bevy-android-example"
2+
name = "bevy_mobile_example"
33
version = "0.1.0"
44
edition = "2021"
5-
description = "Example for building an Android app with Bevy"
5+
description = "Example for building an iOS or Android app with Bevy"
66
publish = false
77
license = "MIT OR Apache-2.0"
88

99
[lib]
10-
name = "bevy_android_example"
11-
crate-type = ["cdylib"]
10+
name = "bevy_mobile_example"
11+
crate-type = ["staticlib", "cdylib"]
1212

1313
[dependencies]
1414
bevy = { path = "../../" }

examples/ios/Makefile examples/mobile/Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ ifndef DEVICE_ID
66
endif
77

88
run: install
9-
xcrun simctl launch --console $(DEVICE) com.rust.bevy-ios-example
9+
xcrun simctl launch --console $(DEVICE) com.rust.bevy_mobile_example
1010

1111
boot-sim:
1212
xcrun simctl boot $(DEVICE) || true
1313

1414
install: xcodebuild-simulator boot-sim
15-
xcrun simctl install $(DEVICE) build/Build/Products/Debug-iphonesimulator/bevy_ios_example.app
15+
xcrun simctl install $(DEVICE) build/Build/Products/Debug-iphonesimulator/bevy_mobile_example.app
1616

1717
xcodebuild-simulator:
18-
IOS_TARGETS=x86_64-apple-ios xcodebuild -scheme bevy_ios_example -configuration Debug -derivedDataPath build -destination "id=$(DEVICE)"
18+
IOS_TARGETS=x86_64-apple-ios xcodebuild -scheme bevy_mobile_example -configuration Debug -derivedDataPath build -destination "id=$(DEVICE)"
1919

2020
xcodebuild-iphone:
21-
IOS_TARGETS=aarch64-apple-ios xcodebuild -scheme bevy_ios_example -configuration Debug -derivedDataPath build -arch arm64
21+
IOS_TARGETS=aarch64-apple-ios xcodebuild -scheme bevy_mobile_example -configuration Debug -derivedDataPath build -arch arm64
2222

2323
clean:
2424
rm -r build

0 commit comments

Comments
 (0)