diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e19f6e3..cec828b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,16 @@ jobs: with: rust-version: ${{ matrix.rust_version }} + - name: Install LLVM + run: sudo apt-get update && sudo apt-get install llvm + + - name: Build na-mainloop with xbuild + working-directory: na-mainloop + run: | + cargo install xbuild + # Showcase that x builds out-of-the-box with no external dependencies + x build --platform android --arch arm64 + - name: Install Rust targets run: > rustup target add diff --git a/agdk-cpal/README.md b/agdk-cpal/README.md index f81be11..ffb9202 100644 --- a/agdk-cpal/README.md +++ b/agdk-cpal/README.md @@ -2,7 +2,7 @@ This is a minimal test application based on `GameActivity` that just runs a mainloop based on android_activity::poll_events() and plays a sine wave audio test using the Cpal audio library. -``` +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" diff --git a/agdk-eframe/README.md b/agdk-eframe/README.md index fa05171..0b3d258 100644 --- a/agdk-eframe/README.md +++ b/agdk-eframe/README.md @@ -3,7 +3,7 @@ This tests using `GameActivity` with egui, winit and wgpu. This is based on a re-worked winit backend here: https://github.com/rib/winit/tree/android-activity -``` +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" diff --git a/agdk-mainloop/README.md b/agdk-mainloop/README.md index bdedbbf..05b2b75 100644 --- a/agdk-mainloop/README.md +++ b/agdk-mainloop/README.md @@ -3,7 +3,7 @@ runs a mainloop based on android_activity::poll_events() and traces the events received without doing any rendering. It also saves and restores some minimal application state. -``` +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" diff --git a/agdk-oboe/README.md b/agdk-oboe/README.md index 6ffaf78..636c1c7 100644 --- a/agdk-oboe/README.md +++ b/agdk-oboe/README.md @@ -2,7 +2,7 @@ This is a minimal test application based on `GameActivity` that just runs a mainloop based on android_activity::poll_events() and plays a sine wave audio test using the Oboe audio library. -``` +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" diff --git a/na-mainloop/Cargo.toml b/na-mainloop/Cargo.toml index 63f234c..440a1ce 100644 --- a/na-mainloop/Cargo.toml +++ b/na-mainloop/Cargo.toml @@ -8,178 +8,11 @@ edition = "2021" [dependencies] log = "0.4" android_logger = "0.11.0" -android-activity = { version = "0.4", features = [ "native-activity" ] } +android-activity = { version = "0.4", features = ["native-activity"] } #android-activity = { path = "../../android-activity/android-activity", features = [ "native-activity" ] } ndk-sys = "0.4" ndk = "0.7" [lib] #name="na_mainloop" -crate_type=["cdylib"] - - -#################### -# cargo apk config # -#################### - -[package.metadata.android] -# Specifies the package property of the manifest. -package = "com.foo.bar" - -# Specifies the array of targets to build for. -build_targets = [ "aarch64-linux-android" ] - -# Path to your application's resources folder. -# If not specified, resources will not be included in the APK. -#resources = "path/to/resources_folder" - -# Path to the folder containing your application's assets. -# If not specified, assets will not be included in the APK. -#assets = "path/to/assets_folder" - -# Name for final APK file. -# Defaults to package name. -#apk_name = "myapp" - -# Folder containing extra shared libraries intended to be dynamically loaded at runtime. -# Files matching `libs_folder/${android_abi}/*.so` are added to the apk -# according to the specified build_targets. -#runtime_libs = "path/to/libs_folder" - -# See https://developer.android.com/guide/topics/manifest/uses-sdk-element -# -# Defaults to a `min_sdk_version` of 23 and `target_sdk_version` of 30 (or lower if the detected NDK doesn't support this). -[package.metadata.android.sdk] -min_sdk_version = 28 -target_sdk_version = 31 -#max_sdk_version = 31 - -# See https://developer.android.com/guide/topics/manifest/uses-feature-element -# -# Note: there can be multiple .uses_feature entries. -[[package.metadata.android.uses_feature]] -name = "android.hardware.vulkan.level" -required = true -version = 1 - -# See https://developer.android.com/guide/topics/manifest/uses-permission-element -# -# Note: there can be multiple .uses_permission entries. -#[[package.metadata.android.uses_permission]] -#name = "android.permission.WRITE_EXTERNAL_STORAGE" -#max_sdk_version = 18 - -# See https://developer.android.com/guide/topics/manifest/queries-element#provider -#[[package.metadata.android.queries.provider]] -#authorities = "org.khronos.openxr.runtime_broker;org.khronos.openxr.system_runtime_broker" -# Note: The `name` attribute is normally not required for a queries provider, but is non-optional -# as a workaround for aapt throwing errors about missing `android:name` attribute. -# This will be made optional if/when cargo-apk migrates to aapt2. -#name = "org.khronos.openxr" - -# See https://developer.android.com/guide/topics/manifest/queries-element#intent -#[[package.metadata.android.queries.intent]] -#actions = ["android.intent.action.SEND"] - -# See https://developer.android.com/guide/topics/manifest/queries-element#intent -# Note: there can be several .data entries. -#[[package.metadata.android.queries.intent.data]] -#mime_type = "image/jpeg" - -# See https://developer.android.com/guide/topics/manifest/queries-element#package -#[[package.metadata.android.queries.package]] -#name = "org.freedesktop.monado.openxr_runtime.in_process" - -# See https://developer.android.com/guide/topics/manifest/application-element -#[package.metadata.android.application] - -# See https://developer.android.com/guide/topics/manifest/application-element#debug -# -# Defaults to false. -#debuggable = false - -# See https://developer.android.com/guide/topics/manifest/application-element#theme -# -# Example shows setting the theme of an application to fullscreen. -#theme = "@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen" - -# Virtual path your application's icon for any mipmap level. -# If not specified, an icon will not be included in the APK. -#icon = "@mipmap/ic_launcher" - -# See https://developer.android.com/guide/topics/manifest/application-element#label -# -# Defaults to the compiled artifact's name. -label = "Application Name" - -# See https://developer.android.com/guide/topics/manifest/meta-data-element -# -# Note: there can be several .meta_data entries. -# Note: the `resource` attribute is currently not supported. -#[[package.metadata.android.application.meta_data]] -#name = "com.samsung.android.vr.application.mode" -#value = "vr_only" - -# See https://developer.android.com/guide/topics/manifest/activity-element -[package.metadata.android.application.activity] - -# See https://developer.android.com/guide/topics/manifest/activity-element#nm -# -# The name of the class that implements the activity, a subclass of Activity -# -# Defaults to "android.app.NativeActivity" -# name = "android.app.MyActivity" - -# See https://developer.android.com/guide/topics/manifest/activity-element#config -# -# Defaults to "orientation|keyboardHidden|screenSize". -#config_changes = "orientation" - -# See https://developer.android.com/guide/topics/manifest/activity-element#label -# -# Defaults to the application's label. -#label = "Activity Name" - -# See https://developer.android.com/guide/topics/manifest/activity-element#lmode -# -# Defaults to "standard". -#launch_mode = "singleTop" - -# See https://developer.android.com/guide/topics/manifest/activity-element#screen -# -# Defaults to "unspecified". -#orientation = "landscape" - -# See https://developer.android.com/guide/topics/manifest/activity-element#exported -# -# Unset by default, or "true" when targeting Android >= 31 (S and up). -#exported = "true" - -# See https://developer.android.com/guide/topics/manifest/meta-data-element -# -# Note: there can be several .meta_data entries. -# Note: the `resource` attribute is currently not supported. -#[[package.metadata.android.application.activity.meta_data]] -#name = "com.oculus.vr.focusaware" -#value = "true" - -# See https://developer.android.com/guide/topics/manifest/intent-filter-element -# -# Note: there can be several .intent_filter entries. -#[[package.metadata.android.application.activity.intent_filter]] -# See https://developer.android.com/guide/topics/manifest/action-element -#actions = ["android.intent.action.VIEW", "android.intent.action.WEB_SEARCH"] -# See https://developer.android.com/guide/topics/manifest/category-element -#categories = ["android.intent.category.DEFAULT", "android.intent.category.BROWSABLE"] - -# See https://developer.android.com/guide/topics/manifest/data-element -# -# Note: there can be several .data entries. -# Note: not specifying an attribute excludes it from the final data specification. -#[[package.metadata.android.application.activity.intent_filter.data]] -#scheme = "https" -#host = "github.com" -#port = "8080" -#path = "/rust-windowing/android-ndk-rs/tree/master/cargo-apk" -#path_prefix = "/rust-windowing/" -#mime_type = "image/jpeg" \ No newline at end of file +crate_type = ["cdylib"] diff --git a/na-mainloop/README.md b/na-mainloop/README.md index 0e73eec..f72801c 100644 --- a/na-mainloop/README.md +++ b/na-mainloop/README.md @@ -4,10 +4,26 @@ the events received without doing any rendering. It also saves and restores some minimal application state. Since this test doesn't require a custom `Activity` subclass it's -optionally possible to build this example with `cargo apk`. +optionally possible to build this example with `xbuild` or `cargo apk`. -# Gradle Build +# xbuild + +```bash +cargo install xbuild + +# Get ID of connected debug device, of the form adb:DEVICEID +x devices + +# Build and run for that configuration +x run --device adb:DEVICEID + +# Or build for a generic arm64 Android device +x build --platform android --arch arm64 ``` + +# Gradle Build + +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" @@ -20,7 +36,8 @@ cargo ndk -t arm64-v8a -o app/src/main/jniLibs/ build ``` # Cargo APK Build -``` + +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_SDK_HOME="path/to/sdk" diff --git a/na-openxr-info/Cargo.toml b/na-openxr-info/Cargo.toml index 7d9cbe4..f797889 100644 --- a/na-openxr-info/Cargo.toml +++ b/na-openxr-info/Cargo.toml @@ -17,17 +17,17 @@ android_logger = "0.11.0" android-activity = { version = "0.4", features = ["native-activity"] } [features] -default = [ "linked" ] +default = ["linked"] -android = [ "openxr/linked" ] -desktop = [ "linked", "openxr/static"] -linked = [] +android = ["linked"] +desktop = ["linked", "openxr/static"] +linked = ["openxr/linked"] [lib] -name="main" -crate_type=["cdylib"] +name = "main" +crate_type = ["cdylib"] [[bin]] -path="src/lib.rs" -name="test-winit-wgpu" -required-features = [ "desktop" ] \ No newline at end of file +path = "src/lib.rs" +name = "test-winit-wgpu" +required-features = ["desktop"] diff --git a/na-openxr-info/src/lib.rs b/na-openxr-info/src/lib.rs index 8003c78..8cdded1 100644 --- a/na-openxr-info/src/lib.rs +++ b/na-openxr-info/src/lib.rs @@ -1,4 +1,4 @@ -///! Based on https://github.com/Ralith/openxrs/blob/master/openxr/examples/hello.rs +//! Based on use openxr as xr; #[cfg(target_os = "android")] diff --git a/na-openxr-wgpu/README.md b/na-openxr-wgpu/README.md index 1371e43..2c8e617 100644 --- a/na-openxr-wgpu/README.md +++ b/na-openxr-wgpu/README.md @@ -21,7 +21,7 @@ library to `app/src/main/jniLibs/` For example if building for arm64-v8a: `cp path/to/ovr_openxr_mobile_sdk_42.0/OpenXR/Libs/Android/arm64-v8a/Debug/libopenxr_loader.so app/src/main/jniLibs/arm64-v8a` -``` +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" @@ -36,7 +36,8 @@ cargo ndk -t arm64-v8a -o app/src/main/jniLibs/ build # Oculus Quest: Vulkan Validation Layer To enable the Vulkan validation layer on the Oculus Quest run: -``` + +```bash adb shell setprop debug.oculus.loadandinjectpackagedvvl.co.realfit.naopenxrwgpu 1 ``` @@ -44,4 +45,4 @@ adb shell setprop debug.oculus.loadandinjectpackagedvvl.co.realfit.naopenxrwgpu To build for PC you need to build with the "desktop" feature -`cargo run --features=desktop` \ No newline at end of file +`cargo run --features=desktop` diff --git a/na-subclass-jni/Cargo.toml b/na-subclass-jni/Cargo.toml index 8cef04a..aa13566 100644 --- a/na-subclass-jni/Cargo.toml +++ b/na-subclass-jni/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] log = "0.4" android_logger = "0.11.0" -android-activity = { version = "0.4", features = [ "native-activity" ] } +android-activity = { version = "0.4", features = ["native-activity"] } ndk-context = "0.1" ndk = "0.7" ndk-sys = "0.4" @@ -19,171 +19,4 @@ serde_json = "1" [lib] #name="na_subclass_jni" -crate_type=["cdylib"] - - -#################### -# cargo apk config # -#################### - -[package.metadata.android] -# Specifies the package property of the manifest. -package = "com.foo.bar" - -# Specifies the array of targets to build for. -build_targets = [ "aarch64-linux-android" ] - -# Path to your application's resources folder. -# If not specified, resources will not be included in the APK. -#resources = "path/to/resources_folder" - -# Path to the folder containing your application's assets. -# If not specified, assets will not be included in the APK. -#assets = "path/to/assets_folder" - -# Name for final APK file. -# Defaults to package name. -#apk_name = "myapp" - -# Folder containing extra shared libraries intended to be dynamically loaded at runtime. -# Files matching `libs_folder/${android_abi}/*.so` are added to the apk -# according to the specified build_targets. -#runtime_libs = "path/to/libs_folder" - -# See https://developer.android.com/guide/topics/manifest/uses-sdk-element -# -# Defaults to a `min_sdk_version` of 23 and `target_sdk_version` of 30 (or lower if the detected NDK doesn't support this). -[package.metadata.android.sdk] -min_sdk_version = 28 -target_sdk_version = 31 -#max_sdk_version = 31 - -# See https://developer.android.com/guide/topics/manifest/uses-feature-element -# -# Note: there can be multiple .uses_feature entries. -[[package.metadata.android.uses_feature]] -name = "android.hardware.vulkan.level" -required = true -version = 1 - -# See https://developer.android.com/guide/topics/manifest/uses-permission-element -# -# Note: there can be multiple .uses_permission entries. -#[[package.metadata.android.uses_permission]] -#name = "android.permission.WRITE_EXTERNAL_STORAGE" -#max_sdk_version = 18 - -# See https://developer.android.com/guide/topics/manifest/queries-element#provider -#[[package.metadata.android.queries.provider]] -#authorities = "org.khronos.openxr.runtime_broker;org.khronos.openxr.system_runtime_broker" -# Note: The `name` attribute is normally not required for a queries provider, but is non-optional -# as a workaround for aapt throwing errors about missing `android:name` attribute. -# This will be made optional if/when cargo-apk migrates to aapt2. -#name = "org.khronos.openxr" - -# See https://developer.android.com/guide/topics/manifest/queries-element#intent -#[[package.metadata.android.queries.intent]] -#actions = ["android.intent.action.SEND"] - -# See https://developer.android.com/guide/topics/manifest/queries-element#intent -# Note: there can be several .data entries. -#[[package.metadata.android.queries.intent.data]] -#mime_type = "image/jpeg" - -# See https://developer.android.com/guide/topics/manifest/queries-element#package -#[[package.metadata.android.queries.package]] -#name = "org.freedesktop.monado.openxr_runtime.in_process" - -# See https://developer.android.com/guide/topics/manifest/application-element -#[package.metadata.android.application] - -# See https://developer.android.com/guide/topics/manifest/application-element#debug -# -# Defaults to false. -#debuggable = false - -# See https://developer.android.com/guide/topics/manifest/application-element#theme -# -# Example shows setting the theme of an application to fullscreen. -#theme = "@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen" - -# Virtual path your application's icon for any mipmap level. -# If not specified, an icon will not be included in the APK. -#icon = "@mipmap/ic_launcher" - -# See https://developer.android.com/guide/topics/manifest/application-element#label -# -# Defaults to the compiled artifact's name. -label = "Application Name" - -# See https://developer.android.com/guide/topics/manifest/meta-data-element -# -# Note: there can be several .meta_data entries. -# Note: the `resource` attribute is currently not supported. -#[[package.metadata.android.application.meta_data]] -#name = "com.samsung.android.vr.application.mode" -#value = "vr_only" - -# See https://developer.android.com/guide/topics/manifest/activity-element -[package.metadata.android.application.activity] - -# See https://developer.android.com/guide/topics/manifest/activity-element#nm -# -# The name of the class that implements the activity, a subclass of Activity -# -# Defaults to "android.app.NativeActivity" -# name = "android.app.MyActivity" - -# See https://developer.android.com/guide/topics/manifest/activity-element#config -# -# Defaults to "orientation|keyboardHidden|screenSize". -#config_changes = "orientation" - -# See https://developer.android.com/guide/topics/manifest/activity-element#label -# -# Defaults to the application's label. -#label = "Activity Name" - -# See https://developer.android.com/guide/topics/manifest/activity-element#lmode -# -# Defaults to "standard". -#launch_mode = "singleTop" - -# See https://developer.android.com/guide/topics/manifest/activity-element#screen -# -# Defaults to "unspecified". -#orientation = "landscape" - -# See https://developer.android.com/guide/topics/manifest/activity-element#exported -# -# Unset by default, or "true" when targeting Android >= 31 (S and up). -#exported = "true" - -# See https://developer.android.com/guide/topics/manifest/meta-data-element -# -# Note: there can be several .meta_data entries. -# Note: the `resource` attribute is currently not supported. -#[[package.metadata.android.application.activity.meta_data]] -#name = "com.oculus.vr.focusaware" -#value = "true" - -# See https://developer.android.com/guide/topics/manifest/intent-filter-element -# -# Note: there can be several .intent_filter entries. -#[[package.metadata.android.application.activity.intent_filter]] -# See https://developer.android.com/guide/topics/manifest/action-element -#actions = ["android.intent.action.VIEW", "android.intent.action.WEB_SEARCH"] -# See https://developer.android.com/guide/topics/manifest/category-element -#categories = ["android.intent.category.DEFAULT", "android.intent.category.BROWSABLE"] - -# See https://developer.android.com/guide/topics/manifest/data-element -# -# Note: there can be several .data entries. -# Note: not specifying an attribute excludes it from the final data specification. -#[[package.metadata.android.application.activity.intent_filter.data]] -#scheme = "https" -#host = "github.com" -#port = "8080" -#path = "/rust-windowing/android-ndk-rs/tree/master/cargo-apk" -#path_prefix = "/rust-windowing/" -#mime_type = "image/jpeg" \ No newline at end of file +crate_type = ["cdylib"] diff --git a/na-subclass-jni/README.md b/na-subclass-jni/README.md index 796299a..fb7a1e2 100644 --- a/na-subclass-jni/README.md +++ b/na-subclass-jni/README.md @@ -6,7 +6,8 @@ Note: unlike the `na-mainloop` example, this one can't be built via `cargo apk` since it needs to compile some Java code. # Gradle Build -``` + +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" diff --git a/na-winit-glutin/README.md b/na-winit-glutin/README.md index 5f5cbba..b1aaad9 100644 --- a/na-winit-glutin/README.md +++ b/na-winit-glutin/README.md @@ -4,6 +4,21 @@ Glutin crate. This example demonstrates how to re-create the application's surface state as necessary when the application is paused and resumed on Android. +# xbuild + +```bash +cargo install xbuild + +# Get ID of connected debug device, of the form adb:DEVICEID +x devices + +# Build and run for that configuration +x run --device adb:DEVICEID + +# Or build for a generic arm64 Android device +x build --platform android --arch arm64 +``` + # Gradle Build ```bash diff --git a/na-winit-glutin/src/lib.rs b/na-winit-glutin/src/lib.rs index 692025e..6a49c29 100644 --- a/na-winit-glutin/src/lib.rs +++ b/na-winit-glutin/src/lib.rs @@ -245,7 +245,7 @@ impl App { .build(Some(raw_window_handle)); unsafe { glutin_display - .create_context(&config, &context_attributes) + .create_context(config, &context_attributes) .unwrap_or_else(|_| { glutin_display .create_context(config, &fallback_context_attributes) @@ -268,7 +268,7 @@ impl App { } fn ensure_surface_and_context(&mut self, event_loop: &EventLoopWindowTarget) { - let window = winit::window::Window::new(&event_loop).unwrap(); + let window = winit::window::Window::new(event_loop).unwrap(); let raw_window_handle = window.raw_window_handle(); // Lazily initialize, egl, wgl, glx etc diff --git a/na-winit-wgpu/README.md b/na-winit-wgpu/README.md index c6f2f08..00d4df7 100644 --- a/na-winit-wgpu/README.md +++ b/na-winit-wgpu/README.md @@ -1,6 +1,21 @@ This is the same as agdk-winit-wgpu except it runs with `NativeActivity` instead of `GameActivity` +# xbuild + +```bash +cargo install xbuild + +# Get ID of connected debug device, of the form adb:DEVICEID +x devices + +# Build and run for that configuration +x run --device adb:DEVICEID + +# Or build for a generic arm64 Android device +x build --platform android --arch arm64 +``` + # Gradle Build ```bash