diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index dab2789281..b9e8959df0 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -46,23 +46,32 @@ jobs: - uses: dtolnay/rust-toolchain@stable + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + - name: Add Android targets - run: rustup target add aarch64-linux-android armv7-linux-androideabi + run: rustup target add aarch64-linux-android - - name: Install Cargo APK - run: cargo install --force cargo-apk + - name: Install Cargo NDK + run: cargo install --force cargo-ndk - - name: Build app for Android - run: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME cargo apk build --package bevy_mobile_example + - name: Build .so file + run: cargo ndk -t arm64-v8a -o android_example/app/src/main/jniLibs build --package bevy_mobile_example env: # This will reduce the APK size from 1GB to ~200MB CARGO_PROFILE_DEV_DEBUG: false + - name: Build app for Android + 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=@app/build/outputs/apk/debug/app-debug.apk" \ -F "custom_id=$GITHUB_RUN_ID" nonce: diff --git a/.github/workflows/validation-jobs.yml b/.github/workflows/validation-jobs.yml index f5fab3f976..3372fc1b03 100644 --- a/.github/workflows/validation-jobs.yml +++ b/.github/workflows/validation-jobs.yml @@ -49,6 +49,12 @@ jobs: - uses: dtolnay/rust-toolchain@stable + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + - uses: actions/cache@v4 with: path: | @@ -60,13 +66,16 @@ jobs: key: ${{ runner.os }}-cargo-build-android-${{ hashFiles('**/Cargo.toml') }} - name: Install Android targets - run: rustup target add aarch64-linux-android armv7-linux-androideabi + run: rustup target add aarch64-linux-android - - name: Install Cargo APK - run: cargo install --force cargo-apk + - name: Install Cargo NDK + run: cargo install --force cargo-ndk - - name: Build APK - run: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME cargo apk build --package bevy_mobile_example + - name: Build .so file + run: cargo ndk -t arm64-v8a -o android_example/app/src/main/jniLibs build --package bevy_mobile_example + + - name: Build app for Android + run: cd examples/mobile/android_example && chmod +x gradlew && ./gradlew build run-examples-linux-vulkan: if: ${{ github.event_name == 'merge_group' }} diff --git a/Cargo.toml b/Cargo.toml index 61bcc97a63..28fb16ffcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -131,6 +131,7 @@ default = [ "default_font", "webgl2", "sysinfo_plugin", + "android-game-activity", ] # Provides an implementation for picking sprites @@ -327,6 +328,12 @@ wayland = ["bevy_internal/wayland"] # X11 display server support x11 = ["bevy_internal/x11"] +# Android NativeActivity support. Legacy, should be avoided for most new Android games. +android-native-activity = ["bevy_internal/android-native-activity"] + +# Android GameActivity support. Default, choose between this and `android-native-activity`. +android-game-activity = ["bevy_internal/android-game-activity"] + # Enable systems that allow for automated testing on CI bevy_ci_testing = ["bevy_internal/bevy_ci_testing"] diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 45bab606ce..5128a772bb 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -99,6 +99,10 @@ async-io = ["bevy_tasks/async-io"] wayland = ["bevy_winit/wayland"] x11 = ["bevy_winit/x11"] +# Android activity support (choose one) +android-native-activity = ["bevy_winit/android-native-activity"] +android-game-activity = ["bevy_winit/android-game-activity"] + # Transmission textures in `StandardMaterial`: pbr_transmission_textures = [ "bevy_pbr?/pbr_transmission_textures", diff --git a/crates/bevy_winit/Cargo.toml b/crates/bevy_winit/Cargo.toml index 2dd20a9bdd..65b73eed91 100644 --- a/crates/bevy_winit/Cargo.toml +++ b/crates/bevy_winit/Cargo.toml @@ -13,7 +13,11 @@ trace = [] wayland = ["winit/wayland", "winit/wayland-csd-adwaita"] x11 = ["winit/x11"] accesskit_unix = ["accesskit_winit/accesskit_unix", "accesskit_winit/async-io"] + serialize = ["serde", "bevy_input/serialize", "bevy_window/serialize"] +android-native-activity = ["winit/android-native-activity"] +android-game-activity = ["winit/android-game-activity"] + [dependencies] # bevy @@ -41,12 +45,6 @@ cfg-if = "1.0" raw-window-handle = "0.6" serde = { version = "1.0", features = ["derive"], optional = true } -[target.'cfg(target_os = "android")'.dependencies] -winit = { version = "0.30", default-features = false, features = [ - "android-native-activity", - "rwh_06", -] } - [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen = { version = "0.2" } web-sys = "0.3" diff --git a/docs-template/EXAMPLE_README.md.tpl b/docs-template/EXAMPLE_README.md.tpl index fd3f7e27c1..7d8fa20f39 100644 --- a/docs-template/EXAMPLE_README.md.tpl +++ b/docs-template/EXAMPLE_README.md.tpl @@ -45,7 +45,9 @@ git checkout v0.4.0 - [Android](#android) - [Setup](#setup) - [Build & Run](#build--run) + - [About `libc++_shared.so`](#about-libc_sharedso) - [Old phones](#old-phones) + - [About `cargo-apk`](#about-cargo-apk) - [iOS](#ios) - [Setup](#setup-1) - [Build & Run](#build--run-1) @@ -89,33 +91,51 @@ Example | Description ### Setup ```sh -rustup target add aarch64-linux-android armv7-linux-androideabi -cargo install cargo-apk +rustup target add aarch64-linux-android +cargo install cargo-ndk ``` The Android SDK must be installed, and the environment variable `ANDROID_SDK_ROOT` set to the root Android `sdk` folder. When using `NDK (Side by side)`, the environment variable `ANDROID_NDK_ROOT` must also be set to one of the NDKs in `sdk\ndk\[NDK number]`. +Alternatively, you can install Android Studio. + ### Build & Run -To run on a device setup for Android development, run: +To build an Android app, you first need to build shared object files for the target architecture with `cargo-ndk`: ```sh -cargo apk run -p bevy_mobile_example +cargo ndk -t build -o /app/src/main/jniLibs ``` -When using Bevy as a library, the following fields must be added to `Cargo.toml`: +For example, to compile to a 64-bit ARM platform: -```toml -[package.metadata.android] -build_targets = ["aarch64-linux-android", "armv7-linux-androideabi"] - -[package.metadata.android.sdk] -target_sdk_version = 31 +```sh +cargo ndk -t arm64-v8a build -o android_example/app/src/main/jniLibs ``` -Please reference `cargo-apk` [README](https://crates.io/crates/cargo-apk) for other Android Manifest fields. +Setting the output path ensures the shared object files can be found in target-specific directories under `jniLibs` where the JNI can find them. + +See the `cargo-ndk` [README](https://crates.io/crates/cargo-ndk) for other options. + +After this you can build it with `gradlew`: + +```sh +./gradlew build +``` + +Or build it with Android Studio. + +Then you can test it in your Android project. + +#### About `libc++_shared.so` + +Bevy may require `libc++_shared.so` to run on Android, as it is needed by the `oboe` crate, but typically `cargo-ndk` does not copy this file automatically. + +To include it, you can manually obtain it from NDK source or use a `build.rs` script for automation, as described in the `cargo-ndk` [README](https://github.com/bbqsrc/cargo-ndk?tab=readme-ov-file#linking-against-and-copying-libc_sharedso-into-the-relevant-places-in-the-output-directory). + +Alternatively, you can modify project files to include it when building an APK. To understand the specific steps taken in this project, please refer to the comments within the project files for detailed instructions(`app/CMakeList.txt`, `app/build.gradle`, `app/src/main/cpp/dummy.cpp`). ### Debugging @@ -135,18 +155,22 @@ adb uninstall org.bevyengine.example ### Old phones -Bevy by default targets Android API level 31 in its examples which is the -[Play Store's minimum API to upload or update apps](https://developer.android.com/distribute/best-practices/develop/target-sdk). -Users of older phones may want to use an older API when testing. +In its examples, Bevy targets the minimum Android API that Play Store +[requires](https://developer.android.com/distribute/best-practices/develop/target-sdk) to upload and update apps. +Users of older phones may want to use an older API when testing. By default, Bevy uses [`GameAvtivity`](https://developer.android.com/games/agdk/game-activity), which only works for Android API level 31 and higher, so if you want to use older API, you need to switch to `NativeActivity`. -To use a different API, the following fields must be updated in Cargo.toml: +To use `NativeActivity`, you need to edit it in `cargo.toml` manually like this: ```toml -[package.metadata.android.sdk] -target_sdk_version = >>API<< -min_sdk_version = >>API or less<< +bevy = { version = "0.14", default-features = false, features = ["android-native-activity", ...] } ``` +Then build it as the [Build & Run](#build--run) section stated above. + +#### About `cargo-apk` + +You can also build an APK with `cargo-apk`, a simpler and deprecated tool which doesn't support `GameActivity`. If you want to use this, there is a [folder](./mobile/android_basic) inside the mobile example with instructions. + Example | File | Description --- | --- | --- `android` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound diff --git a/docs/cargo_features.md b/docs/cargo_features.md index 417e209a5a..bd29c14c43 100644 --- a/docs/cargo_features.md +++ b/docs/cargo_features.md @@ -11,6 +11,7 @@ The default feature set enables most of the expected features of a game engine, |feature name|description| |-|-| +|android-game-activity|Android GameActivity support. Default, choose between this and `android-native-activity`.| |android_shared_stdcxx|Enable using a shared stdlib for cxx on Android| |animation|Enable animation support, and glTF animation loading| |bevy_animation|Provides animation functionality| @@ -51,6 +52,7 @@ The default feature set enables most of the expected features of a game engine, |feature name|description| |-|-| |accesskit_unix|Enable AccessKit on Unix backends (currently only works with experimental screen readers and forks.)| +|android-native-activity|Android NativeActivity support. Legacy, should be avoided for most new Android games.| |asset_processor|Enables the built-in asset processor for processed assets.| |async-io|Use async-io's implementation of block_on instead of futures-lite's implementation. This is preferred if your application uses async-io.| |basis-universal|Basis Universal compressed texture support| diff --git a/examples/README.md b/examples/README.md index 3647b77cc7..08bd450b29 100644 --- a/examples/README.md +++ b/examples/README.md @@ -72,7 +72,9 @@ git checkout v0.4.0 - [Android](#android) - [Setup](#setup) - [Build & Run](#build--run) + - [About `libc++_shared.so`](#about-libc_sharedso) - [Old phones](#old-phones) + - [About `cargo-apk`](#about-cargo-apk) - [iOS](#ios) - [Setup](#setup-1) - [Build & Run](#build--run-1) @@ -543,33 +545,51 @@ Example | Description ### Setup ```sh -rustup target add aarch64-linux-android armv7-linux-androideabi -cargo install cargo-apk +rustup target add aarch64-linux-android +cargo install cargo-ndk ``` The Android SDK must be installed, and the environment variable `ANDROID_SDK_ROOT` set to the root Android `sdk` folder. When using `NDK (Side by side)`, the environment variable `ANDROID_NDK_ROOT` must also be set to one of the NDKs in `sdk\ndk\[NDK number]`. +Alternatively, you can install Android Studio. + ### Build & Run -To run on a device setup for Android development, run: +To build an Android app, you first need to build shared object files for the target architecture with `cargo-ndk`: ```sh -cargo apk run -p bevy_mobile_example +cargo ndk -t build -o /app/src/main/jniLibs ``` -When using Bevy as a library, the following fields must be added to `Cargo.toml`: +For example, to compile to a 64-bit ARM platform: -```toml -[package.metadata.android] -build_targets = ["aarch64-linux-android", "armv7-linux-androideabi"] - -[package.metadata.android.sdk] -target_sdk_version = 31 +```sh +cargo ndk -t arm64-v8a build -o android_example/app/src/main/jniLibs ``` -Please reference `cargo-apk` [README](https://crates.io/crates/cargo-apk) for other Android Manifest fields. +Setting the output path ensures the shared object files can be found in target-specific directories under `jniLibs` where the JNI can find them. + +See the `cargo-ndk` [README](https://crates.io/crates/cargo-ndk) for other options. + +After this you can build it with `gradlew`: + +```sh +./gradlew build +``` + +Or build it with Android Studio. + +Then you can test it in your Android project. + +#### About `libc++_shared.so` + +Bevy may require `libc++_shared.so` to run on Android, as it is needed by the `oboe` crate, but typically `cargo-ndk` does not copy this file automatically. + +To include it, you can manually obtain it from NDK source or use a `build.rs` script for automation, as described in the `cargo-ndk` [README](https://github.com/bbqsrc/cargo-ndk?tab=readme-ov-file#linking-against-and-copying-libc_sharedso-into-the-relevant-places-in-the-output-directory). + +Alternatively, you can modify project files to include it when building an APK. To understand the specific steps taken in this project, please refer to the comments within the project files for detailed instructions(`app/CMakeList.txt`, `app/build.gradle`, `app/src/main/cpp/dummy.cpp`). ### Debugging @@ -589,18 +609,22 @@ adb uninstall org.bevyengine.example ### Old phones -Bevy by default targets Android API level 31 in its examples which is the -[Play Store's minimum API to upload or update apps](https://developer.android.com/distribute/best-practices/develop/target-sdk). -Users of older phones may want to use an older API when testing. +In its examples, Bevy targets the minimum Android API that Play Store +[requires](https://developer.android.com/distribute/best-practices/develop/target-sdk) to upload and update apps. +Users of older phones may want to use an older API when testing. By default, Bevy uses [`GameAvtivity`](https://developer.android.com/games/agdk/game-activity), which only works for Android API level 31 and higher, so if you want to use older API, you need to switch to `NativeActivity`. -To use a different API, the following fields must be updated in Cargo.toml: +To use `NativeActivity`, you need to edit it in `cargo.toml` manually like this: ```toml -[package.metadata.android.sdk] -target_sdk_version = >>API<< -min_sdk_version = >>API or less<< +bevy = { version = "0.14", default-features = false, features = ["android-native-activity", ...] } ``` +Then build it as the [Build & Run](#build--run) section stated above. + +#### About `cargo-apk` + +You can also build an APK with `cargo-apk`, a simpler and deprecated tool which doesn't support `GameActivity`. If you want to use this, there is a [folder](./mobile/android_basic) inside the mobile example with instructions. + Example | File | Description --- | --- | --- `android` | [`mobile/src/lib.rs`](./mobile/src/lib.rs) | A 3d Scene with a button and playing sound diff --git a/examples/mobile/.gitignore b/examples/mobile/.gitignore index 796b96d1c4..0f1f32c67e 100644 --- a/examples/mobile/.gitignore +++ b/examples/mobile/.gitignore @@ -1 +1,7 @@ /build +.gradle +.idea +.DS_Store +build +.cxx +local.properties diff --git a/examples/mobile/Cargo.toml b/examples/mobile/Cargo.toml index 7d412ace8d..522fd682df 100644 --- a/examples/mobile/Cargo.toml +++ b/examples/mobile/Cargo.toml @@ -17,21 +17,5 @@ bevy = { path = "../../" } [target.aarch64-apple-ios-sim.dependencies] bevy = { path = "../../", features = ["ios_simulator"] } -[package.metadata.android] -package = "org.bevyengine.example" -apk_name = "bevyexample" -assets = "../../assets" -resources = "../../assets/android-res" -# This strips debug symbols from the shared libraries, drastically reducing APK size. If you need them, remove the option. -strip = "strip" -build_targets = ["aarch64-linux-android", "armv7-linux-androideabi"] - -[package.metadata.android.sdk] -target_sdk_version = 31 - -[package.metadata.android.application] -icon = "@mipmap/ic_launcher" -label = "Bevy Example" - [lints] workspace = true diff --git a/examples/mobile/android_basic/Cargo.toml b/examples/mobile/android_basic/Cargo.toml new file mode 100644 index 0000000000..4dfa74beb6 --- /dev/null +++ b/examples/mobile/android_basic/Cargo.toml @@ -0,0 +1,72 @@ +[package] +name = "bevy_mobile_example" +# Version is required by `cargo-apk`, though this value will never change. +version = "0.0.0" +edition = "2021" +description = "Example for building an iOS or Android app with Bevy" +publish = false +license = "MIT OR Apache-2.0" + +[lib] +name = "bevy_mobile_example" +crate-type = ["staticlib", "cdylib"] + +[dependencies] +bevy = { path = "../../", default-features = false, features = [ + "android-native-activity", + "android_shared_stdcxx", + "animation", + "bevy_animation", + "bevy_asset", + "bevy_audio", + "bevy_color", + "bevy_core_pipeline", + "bevy_gilrs", + "bevy_gizmos", + "bevy_gltf", + "bevy_pbr", + "bevy_render", + "bevy_scene", + "bevy_sprite", + "bevy_state", + "bevy_text", + "bevy_ui", + "bevy_winit", + "default_font", + "hdr", + "ktx2", + "multi_threaded", + "png", + "sysinfo_plugin", + "tonemapping_luts", + "vorbis", + "webgl2", + "x11", + "zstd", +] } + +[target.aarch64-apple-ios-sim.dependencies] +bevy = { path = "../../", features = ["ios_simulator"] } + +[package.metadata.android] +package = "org.bevyengine.example" +apk_name = "bevyexample" +assets = "../../assets" +resources = "../../assets/android-res" +# This strips debug symbols from the shared libraries, drastically reducing APK size. If you need them, remove the option. +strip = "strip" +build_targets = ["aarch64-linux-android", "armv7-linux-androideabi"] + +[package.metadata.android.sdk] +target_sdk_version = 33 + +[package.metadata.android.application] +icon = "@mipmap/ic_launcher" +label = "Bevy Example" + +[lints] +workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/examples/mobile/android_basic/readme.md b/examples/mobile/android_basic/readme.md new file mode 100644 index 0000000000..6db652fff6 --- /dev/null +++ b/examples/mobile/android_basic/readme.md @@ -0,0 +1,56 @@ +# Basic Android Example Instruction + +This folder instructs you how to build android apps with `cargo-apk`, a deprecated Android apk building tool. + +## Setup + +```sh +rustup target add aarch64-linux-android armv7-linux-androideabi +cargo install cargo-apk +``` + +Please refer example [README](../../README.md#setup) for NDK/SDK related instructions. + +## Build & Run + +When using `cargo-apk`, it must use `NativeActivity`, so you need to edit it in `Cargo.toml` manually like this: + +```toml +bevy = { version = "0.14", default-features = false, features = ["android-native-activity", ...] } +``` + +Then the following fields must be added to `Cargo.toml`: + +```toml +[package.metadata.android] +build_targets = ["aarch64-linux-android", "armv7-linux-androideabi"] + +[package.metadata.android.sdk] +target_sdk_version = 33 +``` + +Please refer `cargo-apk` [README](https://crates.io/crates/cargo-apk) for other Android Manifest fields. + +For this example, you can replace the `Cargo.toml` with the one within this folder. + +After setup, you can run it on a device for Android development: + +```sh +cargo apk run -p bevy_mobile_example +``` + +Please refer example [README](../../README.md#debugging) for debugging instructions. + +## Old phones + +Bevy by default targets Android API level 33 in its examples which is the +[Play Store's minimum API to upload or update apps](https://developer.android.com/distribute/best-practices/develop/target-sdk). +Users of older phones may want to use an older API when testing. + +To use a different API, the following fields must be updated in `Cargo.toml`: + +```toml +[package.metadata.android.sdk] +target_sdk_version = >>API<< +min_sdk_version = >>API or less<< +``` diff --git a/examples/mobile/android_example/app/CMakeLists.txt b/examples/mobile/android_example/app/CMakeLists.txt new file mode 100644 index 0000000000..c388547c20 --- /dev/null +++ b/examples/mobile/android_example/app/CMakeLists.txt @@ -0,0 +1,5 @@ +# This is part of a hack to convince gradle to insert libc++_shared.so +cmake_minimum_required(VERSION 3.4.1) +project(cppshared_dummy) +set (SRC_DIR ./src/main/cpp) +add_library (dummy SHARED ${SRC_DIR}/dummy.cpp) diff --git a/examples/mobile/android_example/app/build.gradle b/examples/mobile/android_example/app/build.gradle new file mode 100644 index 0000000000..c21a9de629 --- /dev/null +++ b/examples/mobile/android_example/app/build.gradle @@ -0,0 +1,66 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace 'org.bevyengine.example' + compileSdk 34 + + defaultConfig { + applicationId "org.bevyengine.example" + minSdk 31 + targetSdk 33 + versionCode 1 + versionName "1.0" + // need this otherwise it won't insert libc++_shared.so + externalNativeBuild { + cmake { + arguments "-DANDROID_STL=c++_shared" + } + } + // set up targets + ndk { + abiFilters 'arm64-v8a' + } + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + externalNativeBuild { + cmake { + path "CMakeLists.txt" + } + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + buildFeatures { + prefab true + } + // The final part to insert libc++_shared.so only + packagingOptions { + exclude 'lib/*/libdummy.so' + } + sourceSets { + main { + assets.srcDirs += files('../../../../assets') + + res.srcDirs += files('../../../../assets/android-res') + } + } +} + +dependencies { + + implementation libs.appcompat + implementation libs.material + implementation libs.games.activity + testImplementation libs.junit + androidTestImplementation libs.ext.junit + androidTestImplementation libs.espresso.core +} diff --git a/examples/mobile/android_example/app/src/main/AndroidManifest.xml b/examples/mobile/android_example/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..159bfbe18f --- /dev/null +++ b/examples/mobile/android_example/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/mobile/android_example/app/src/main/cpp/dummy.cpp b/examples/mobile/android_example/app/src/main/cpp/dummy.cpp new file mode 100644 index 0000000000..c20beb86c6 --- /dev/null +++ b/examples/mobile/android_example/app/src/main/cpp/dummy.cpp @@ -0,0 +1,2 @@ +// Intentionally blank -- this is a dummy code! +// This is part of a hack to convince gradle to insert libc++_shared.so \ No newline at end of file diff --git a/examples/mobile/android_example/app/src/main/java/org/bevyengine/example/MainActivity.java b/examples/mobile/android_example/app/src/main/java/org/bevyengine/example/MainActivity.java new file mode 100644 index 0000000000..91a2d5a5c1 --- /dev/null +++ b/examples/mobile/android_example/app/src/main/java/org/bevyengine/example/MainActivity.java @@ -0,0 +1,32 @@ +package org.bevyengine.example; + +import android.view.View; + +import com.google.androidgamesdk.GameActivity; + +public class MainActivity extends GameActivity { + static { + System.loadLibrary("bevy_mobile_example"); + } + + @Override + public void onWindowFocusChanged(boolean hasFocus) { + super.onWindowFocusChanged(hasFocus); + + if (hasFocus) { + hideSystemUi(); + } + } + + private void hideSystemUi() { + View decorView = getWindow().getDecorView(); + decorView.setSystemUiVisibility( + View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_FULLSCREEN + ); + } +} \ No newline at end of file diff --git a/examples/mobile/android_example/build.gradle b/examples/mobile/android_example/build.gradle new file mode 100644 index 0000000000..327342f6cd --- /dev/null +++ b/examples/mobile/android_example/build.gradle @@ -0,0 +1,4 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + alias(libs.plugins.android.application) apply false +} diff --git a/examples/mobile/android_example/gradle.properties b/examples/mobile/android_example/gradle.properties new file mode 100644 index 0000000000..4387edc225 --- /dev/null +++ b/examples/mobile/android_example/gradle.properties @@ -0,0 +1,21 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. For more details, visit +# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true \ No newline at end of file diff --git a/examples/mobile/android_example/gradle/libs.versions.toml b/examples/mobile/android_example/gradle/libs.versions.toml new file mode 100644 index 0000000000..88e55de0f2 --- /dev/null +++ b/examples/mobile/android_example/gradle/libs.versions.toml @@ -0,0 +1,19 @@ +[versions] +agp = "8.4.0" +junit = "4.13.2" +junitVersion = "1.1.5" +espressoCore = "3.5.1" +appcompat = "1.6.1" +material = "1.10.0" +gamesActivity = "2.0.2" + +[libraries] +junit = { group = "junit", name = "junit", version.ref = "junit" } +ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } +espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } +appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } +material = { group = "com.google.android.material", name = "material", version.ref = "material" } +games-activity = { group = "androidx.games", name = "games-activity", version.ref = "gamesActivity" } + +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } diff --git a/examples/mobile/android_example/gradle/wrapper/gradle-wrapper.jar b/examples/mobile/android_example/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..e708b1c023 Binary files /dev/null and b/examples/mobile/android_example/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/mobile/android_example/gradle/wrapper/gradle-wrapper.properties b/examples/mobile/android_example/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..d38484cf25 --- /dev/null +++ b/examples/mobile/android_example/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Mar 07 11:17:51 CST 2024 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/examples/mobile/android_example/gradlew b/examples/mobile/android_example/gradlew new file mode 100644 index 0000000000..4f906e0c81 --- /dev/null +++ b/examples/mobile/android_example/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/examples/mobile/android_example/gradlew.bat b/examples/mobile/android_example/gradlew.bat new file mode 100644 index 0000000000..ac1b06f938 --- /dev/null +++ b/examples/mobile/android_example/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/examples/mobile/android_example/settings.gradle b/examples/mobile/android_example/settings.gradle new file mode 100644 index 0000000000..cc9e80cecf --- /dev/null +++ b/examples/mobile/android_example/settings.gradle @@ -0,0 +1,23 @@ +pluginManagement { + repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + } + } + mavenCentral() + gradlePluginPortal() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + +rootProject.name = "Bevy Example" +include ':app' diff --git a/examples/mobile/android_example_native/app/CMakeLists.txt b/examples/mobile/android_example_native/app/CMakeLists.txt new file mode 100644 index 0000000000..c388547c20 --- /dev/null +++ b/examples/mobile/android_example_native/app/CMakeLists.txt @@ -0,0 +1,5 @@ +# This is part of a hack to convince gradle to insert libc++_shared.so +cmake_minimum_required(VERSION 3.4.1) +project(cppshared_dummy) +set (SRC_DIR ./src/main/cpp) +add_library (dummy SHARED ${SRC_DIR}/dummy.cpp) diff --git a/examples/mobile/android_example_native/app/build.gradle b/examples/mobile/android_example_native/app/build.gradle new file mode 100644 index 0000000000..4b33cd7801 --- /dev/null +++ b/examples/mobile/android_example_native/app/build.gradle @@ -0,0 +1,67 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace 'org.bevyengine.example' + compileSdk 34 + + defaultConfig { + applicationId "org.bevyengine.example" + minSdk 31 + targetSdk 33 + versionCode 1 + versionName "1.0" + // need this otherwise it won't insert libc++_shared.so + externalNativeBuild { + cmake { + arguments "-DANDROID_STL=c++_shared" + } + } + // set up targets + ndk { + abiFilters 'arm64-v8a' + } + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + externalNativeBuild { + cmake { + path "CMakeLists.txt" + } + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + buildFeatures { + viewBinding true + } + // The final part to insert libc++_shared.so only + packagingOptions { + exclude 'lib/*/libdummy.so' + } + + sourceSets { + main { + assets.srcDirs += files('../../../../assets') + + res.srcDirs += files('../../../../assets/android-res') + } + } +} + +dependencies { + + implementation libs.appcompat + implementation libs.material + implementation libs.constraintlayout + testImplementation libs.junit + androidTestImplementation libs.ext.junit + androidTestImplementation libs.espresso.core +} diff --git a/examples/mobile/android_example_native/app/src/main/AndroidManifest.xml b/examples/mobile/android_example_native/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..159bfbe18f --- /dev/null +++ b/examples/mobile/android_example_native/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/mobile/android_example_native/app/src/main/cpp/dummy.cpp b/examples/mobile/android_example_native/app/src/main/cpp/dummy.cpp new file mode 100644 index 0000000000..c20beb86c6 --- /dev/null +++ b/examples/mobile/android_example_native/app/src/main/cpp/dummy.cpp @@ -0,0 +1,2 @@ +// Intentionally blank -- this is a dummy code! +// This is part of a hack to convince gradle to insert libc++_shared.so \ No newline at end of file diff --git a/examples/mobile/android_example_native/app/src/main/java/org/bevyengine/example/MainActivity.java b/examples/mobile/android_example_native/app/src/main/java/org/bevyengine/example/MainActivity.java new file mode 100644 index 0000000000..14d4505228 --- /dev/null +++ b/examples/mobile/android_example_native/app/src/main/java/org/bevyengine/example/MainActivity.java @@ -0,0 +1,32 @@ +package org.bevyengine.example; + +import android.view.View; + +import android.app.NativeActivity; + +public class MainActivity extends NativeActivity { + static { + System.loadLibrary("bevy_mobile_example"); + } + + @Override + public void onWindowFocusChanged(boolean hasFocus) { + super.onWindowFocusChanged(hasFocus); + + if (hasFocus) { + hideSystemUi(); + } + } + + private void hideSystemUi() { + View decorView = getWindow().getDecorView(); + decorView.setSystemUiVisibility( + View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_FULLSCREEN + ); + } + } \ No newline at end of file diff --git a/examples/mobile/android_example_native/build.gradle b/examples/mobile/android_example_native/build.gradle new file mode 100644 index 0000000000..327342f6cd --- /dev/null +++ b/examples/mobile/android_example_native/build.gradle @@ -0,0 +1,4 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + alias(libs.plugins.android.application) apply false +} diff --git a/examples/mobile/android_example_native/gradle.properties b/examples/mobile/android_example_native/gradle.properties new file mode 100644 index 0000000000..4387edc225 --- /dev/null +++ b/examples/mobile/android_example_native/gradle.properties @@ -0,0 +1,21 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. For more details, visit +# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true \ No newline at end of file diff --git a/examples/mobile/android_example_native/gradle/libs.versions.toml b/examples/mobile/android_example_native/gradle/libs.versions.toml new file mode 100644 index 0000000000..20540a5893 --- /dev/null +++ b/examples/mobile/android_example_native/gradle/libs.versions.toml @@ -0,0 +1,19 @@ +[versions] +agp = "8.4.0" +junit = "4.13.2" +junitVersion = "1.1.5" +espressoCore = "3.5.1" +appcompat = "1.6.1" +material = "1.10.0" +constraintlayout = "2.1.4" + +[libraries] +junit = { group = "junit", name = "junit", version.ref = "junit" } +ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } +espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } +appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } +material = { group = "com.google.android.material", name = "material", version.ref = "material" } +constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" } + +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } diff --git a/examples/mobile/android_example_native/gradle/wrapper/gradle-wrapper.jar b/examples/mobile/android_example_native/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..e708b1c023 Binary files /dev/null and b/examples/mobile/android_example_native/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/mobile/android_example_native/gradle/wrapper/gradle-wrapper.properties b/examples/mobile/android_example_native/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..0644b04577 --- /dev/null +++ b/examples/mobile/android_example_native/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon May 13 21:19:35 CST 2024 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/examples/mobile/android_example_native/gradlew b/examples/mobile/android_example_native/gradlew new file mode 100644 index 0000000000..4f906e0c81 --- /dev/null +++ b/examples/mobile/android_example_native/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/examples/mobile/android_example_native/gradlew.bat b/examples/mobile/android_example_native/gradlew.bat new file mode 100644 index 0000000000..ac1b06f938 --- /dev/null +++ b/examples/mobile/android_example_native/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/examples/mobile/android_example_native/settings.gradle b/examples/mobile/android_example_native/settings.gradle new file mode 100644 index 0000000000..cc9e80cecf --- /dev/null +++ b/examples/mobile/android_example_native/settings.gradle @@ -0,0 +1,23 @@ +pluginManagement { + repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + } + } + mavenCentral() + gradlePluginPortal() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + +rootProject.name = "Bevy Example" +include ':app'