Skip to content

Commit

Permalink
fix android build (#59)
Browse files Browse the repository at this point in the history
* fix android build

* fix path

* save apps as artifacts

* try patch for android

* apply patches

* update minimum android version

* patch when running too

* run on less different configs

* release android build

* don't switch to landscape

* enable more devices

* remove unsupported version
  • Loading branch information
mockersf authored Dec 1, 2024
1 parent bec588c commit e6eeb12
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 11 deletions.
81 changes: 70 additions & 11 deletions .github/workflows/workflow-mobile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ on:
gitref:
required: true
type: string
default: 'main'
mobile_percy_project:
required: false
type: string
pixeleagle_project:
required: true
type: string
default: 'B25A040A-A980-4602-B90C-D480AB84076D'
branch:
required: true
type: string
default: 'B25A040A-A980-4602-B90C-D480AB84076D'
workflow_dispatch:
inputs:
repository:
Expand All @@ -29,6 +30,7 @@ on:
gitref:
required: true
type: string
default: 'main'
mobile_percy_project:
required: false
type: string
Expand All @@ -50,6 +52,20 @@ jobs:
repository: ${{ inputs.repository }}
ref: ${{ inputs.gitref }}

- name: Checkout patches
uses: actions/checkout@v4
with:
path: 'runner-patches'

- name: Apply patches
shell: pwsh
run: |
Get-ChildItem "runner-patches/patches" -Filter *.patch |
Foreach-Object {
Write-Output "Processing $($_.FullName)"
git apply --ignore-whitespace $($_.FullName)
}
- uses: dtolnay/rust-toolchain@stable

- name: Add iOS targets
Expand All @@ -71,6 +87,12 @@ jobs:
-F "file=@examples/mobile/bevy_mobile_example.ipa" \
-F "custom_id=$GITHUB_RUN_ID"
- uses: actions/upload-artifact@v4
with:
name: app.ipa
path: examples/mobile/bevy_mobile_example.ipa
retention-days: 2

build-for-Android:
runs-on: ubuntu-latest
timeout-minutes: 30
Expand All @@ -80,26 +102,52 @@ jobs:
repository: ${{ inputs.repository }}
ref: ${{ inputs.gitref }}

- name: Checkout patches
uses: actions/checkout@v4
with:
path: 'runner-patches'

- name: Apply patches
shell: pwsh
run: |
Get-ChildItem "runner-patches/patches" -Filter *.patch |
Foreach-Object {
Write-Output "Processing $($_.FullName)"
git apply --ignore-whitespace $($_.FullName)
}
- uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-gnu,aarch64-linux-android,armv7-linux-androideabi

- name: Install Cargo APK
run: cargo install --force cargo-apk
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Install Cargo NDK
run: cargo install --force cargo-ndk

- name: Build .so file
run: cargo ndk -t arm64-v8a -o examples/mobile/android_example/app/src/main/jniLibs build --package bevy_mobile_example --release

- name: Build app for Android
run: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME cargo apk build --package bevy_mobile_example
env:
# This will reduce the APK size from 1GB to ~200MB
CARGO_PROFILE_DEV_DEBUG: false
run: cd examples/mobile/android_example && chmod +x gradlew && ./gradlew build

- name: Upload to Browser Stack
run: |
curl -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@target/debug/apk/bevyexample.apk" \
-F "file=@examples/mobile/android_example/app/build/outputs/apk/debug/app-debug.apk" \
-F "custom_id=$GITHUB_RUN_ID"
- uses: actions/upload-artifact@v4
with:
name: app.apk
path: examples/mobile/android_example/app/build/outputs/apk/debug/app-debug.apk
retention-days: 2

take-screenshots:
runs-on: ubuntu-latest
timeout-minutes: 30
Expand All @@ -117,9 +165,6 @@ jobs:
- os: "iOS"
device: "iPhone 15"
os_version: "17"
- os: "Android"
device: "Xiaomi Redmi Note 11"
os_version: "11.0"
- os: "Android"
device: "Google Pixel 6"
os_version: "12.0"
Expand All @@ -135,6 +180,20 @@ jobs:
repository: ${{ inputs.repository }}
ref: ${{ inputs.gitref }}

- name: Checkout patches
uses: actions/checkout@v4
with:
path: 'runner-patches'

- name: Apply patches
shell: pwsh
run: |
Get-ChildItem "runner-patches/patches" -Filter *.patch |
Foreach-Object {
Write-Output "Processing $($_.FullName)"
git apply --ignore-whitespace $($_.FullName)
}
- name: Set Percy Token if needed
if: "${{ inputs.mobile_percy_project != '' }}"
run: echo "PERCY_TOKEN=${{ secrets.PERCY_TOKEN_MOBILE }}" >> $GITHUB_ENV
Expand Down
50 changes: 50 additions & 0 deletions patches/android.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
diff --git a/.github/start-mobile-example/specs/screenshot.js b/.github/start-mobile-example/specs/screenshot.js
index 32417256d6..9dbc9e773b 100644
--- a/.github/start-mobile-example/specs/screenshot.js
+++ b/.github/start-mobile-example/specs/screenshot.js
@@ -5,7 +5,7 @@ describe('Running Bevy Example', () => {
it('can take a screenshot', async () => {

// Sleep to wait for app startup, device rotation, ...
- await new Promise(r => setTimeout(r, 2000));
+ await new Promise(r => setTimeout(r, 20000));

// Take local screenshot
await browser.saveScreenshot('./screenshot.png');
diff --git a/examples/mobile/src/lib.rs b/examples/mobile/src/lib.rs
index e69a91b933..7add8e039b 100644
--- a/examples/mobile/src/lib.rs
+++ b/examples/mobile/src/lib.rs
@@ -5,6 +5,10 @@ use bevy::{
input::{gestures::RotationGesture, touch::TouchPhase},
log::{Level, LogPlugin},
prelude::*,
+ render::{
+ settings::{Backends, RenderCreation, WgpuSettings},
+ RenderPlugin,
+ },
window::{AppLifecycle, WindowMode},
};

@@ -30,6 +34,13 @@ fn main() {
..default()
}),
..default()
+ })
+ .set(RenderPlugin {
+ render_creation: RenderCreation::Automatic(WgpuSettings {
+ backends: Some(Backends::VULKAN),
+ ..default()
+ }),
+ ..default()
}),
)
.add_systems(Startup, (setup_scene, setup_music))
@@ -180,6 +191,7 @@ fn handle_lifetime(
};

for event in lifecycle_events.read() {
+ warn!("Lifecycle event: {:?}", event);
match event {
AppLifecycle::Idle | AppLifecycle::WillSuspend | AppLifecycle::WillResume => {}
AppLifecycle::Suspended => music_controller.pause(),
14 changes: 14 additions & 0 deletions patches/remove-mobile-landscape-orientation.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/.github/start-mobile-example/mobile.conf.js b/.github/start-mobile-example/mobile.conf.js
index ed0cf8d90..3443c3f71 100644
--- a/.github/start-mobile-example/mobile.conf.js
+++ b/.github/start-mobile-example/mobile.conf.js
@@ -15,8 +15,7 @@ exports.config = {
device: process.env.DEVICE || 'Samsung Galaxy S23',
os_version: process.env.OS_VERSION || "13.0",
app: process.env.BROWSERSTACK_APP_ID,
- 'browserstack.debug': true,
- orientation: 'LANDSCAPE'
+ 'browserstack.debug': true
}],

logLevel: 'info',

0 comments on commit e6eeb12

Please sign in to comment.