Skip to content

Commit

Permalink
Drop unneeded cargo-apk setup and add xbuild docs
Browse files Browse the repository at this point in the history
Without configuration `cargo-apk` uses the default `rust.<package>`
namespace, instead of the hardcoded `com.foo.bar`.  Similarly `xbuild`
can build and run this project out of the box, no extra configuration
(nor installation / dependencies!) required.
  • Loading branch information
MarijnS95 committed Jul 18, 2023
1 parent 3ad2b59 commit e95e9c4
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 361 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion agdk-cpal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion agdk-eframe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion agdk-mainloop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion agdk-oboe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
171 changes: 2 additions & 169 deletions na-mainloop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
crate_type = ["cdylib"]
23 changes: 20 additions & 3 deletions na-mainloop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"

Expand Down
18 changes: 9 additions & 9 deletions na-openxr-info/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
path = "src/lib.rs"
name = "test-winit-wgpu"
required-features = ["desktop"]
2 changes: 1 addition & 1 deletion na-openxr-info/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
///! Based on https://github.com/Ralith/openxrs/blob/master/openxr/examples/hello.rs
//! Based on <https://github.com/Ralith/openxrs/blob/master/openxr/examples/hello.rs>
use openxr as xr;

#[cfg(target_os = "android")]
Expand Down
7 changes: 4 additions & 3 deletions na-openxr-wgpu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ library to `app/src/main/jniLibs/<abi>`
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"

Expand All @@ -36,12 +36,13 @@ 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
```

# Desktop

To build for PC you need to build with the "desktop" feature

`cargo run --features=desktop`
`cargo run --features=desktop`
Loading

0 comments on commit e95e9c4

Please sign in to comment.