From 626f7fc7140d6ed440b225d6a9f46796eecb6efe Mon Sep 17 00:00:00 2001 From: Lyten02 <87010935+Lyten02@users.noreply.github.com> Date: Fri, 30 Oct 2026 17:21:32 +0100 Subject: [PATCH] Build: cargo-ndk 4.x and NDK r30 cargo-ndk 4 no longer reads [package.metadata.ndk], so the platform fell back to API 21 and linking failed on -laaudio. Pass --platform 26 explicitly (Gradle buildRustLib, CI clippy) and drop the dead metadata. Gradle now copies only libaudiobridge.so into jniLibs: cargo-ndk 4 -o also copies iroh's own cdylibs. Toolchain moves from NDK r23 to r30 (30.0.16248370). --- .github/workflows/ci.yml | 4 ++-- AGENTS.md | 8 ++++---- README.md | 2 +- README.ru.md | 2 +- android/app/build.gradle.kts | 12 +++++++++++- crates/android-native/Cargo.toml | 5 ----- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c567211..13c8f5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ env: CARGO_TERM_COLOR: always # Self-hosted jobs run on the netcup server's `audiobridge` runner, which already has the -# toolchains (Rust + targets, JDK 17, Android SDK/NDK r23, cargo-ndk 3.x, cargo-xwin + LLVM). +# toolchains (Rust + targets, JDK 17, Android SDK/NDK r30, cargo-ndk 4.x, cargo-xwin + LLVM). # Fork PRs are never executed there. CARGO_BUILD_JOBS=2 leaves half of its 4 cores free. jobs: rust: @@ -31,7 +31,7 @@ jobs: - name: Clippy (host) run: cargo clippy -p audiobridge-core -p audiobridge-android --all-targets -- -D warnings - name: Clippy (android arm64) - run: cargo ndk -t arm64-v8a clippy -p audiobridge-android --all-targets -- -D warnings + run: cargo ndk -t arm64-v8a --platform 26 clippy -p audiobridge-android --all-targets -- -D warnings - name: Core tests # the real-network integration tests are timing-sensitive; they are run locally run: cargo test -p audiobridge-core --lib --test rt_alloc diff --git a/AGENTS.md b/AGENTS.md index 3a77e01..8ca2ac5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -65,8 +65,8 @@ cargo test -p audiobridge-android # host-only pure modules (sta cargo clippy -p --all-targets -- -D warnings cargo build -p audiobridge-desktop --release # target\release\AudioBridge.exe powershell -File scripts\install-desktop.ps1 [-SkipBuild] [-NoFirewall] -cargo ndk -t arm64-v8a -o android/app/src/main/jniLibs build --release -p audiobridge-android -cargo ndk -t arm64-v8a clippy -p audiobridge-android --all-targets -- -D warnings # Android clippy needs cargo-ndk (cc needs NDK clang) +cargo ndk -t arm64-v8a --platform 26 build --release -p audiobridge-android # target/aarch64-linux-android/release/libaudiobridge.so (no -o: cargo-ndk 4 would also copy iroh's cdylibs) +cargo ndk -t arm64-v8a --platform 26 clippy -p audiobridge-android --all-targets -- -D warnings # Android clippy needs cargo-ndk (cc needs NDK clang) ``` - Debug-only isolation: `AUDIOBRIDGE_DEV_DIR=` gives a separate identity, logs and instance mutex/events; seed `settings.json` with `"autostart": false` before testing beside the installed app. Release builds ignore this variable. - **APK:** run Gradle from inside `android/` (PowerShell: `Set-Location android; .\gradlew.bat :app:assembleDebug`). It runs `buildRustLib` (cargo-ndk) automatically; add `-PskipRust` to reuse the `.so` already in `jniLibs`. Also: `:app:testDebugUnitTest`, `:app:lintDebug`. @@ -117,8 +117,8 @@ cargo ndk -t arm64-v8a clippy -p audiobridge-android --all-targets -- -D warning - **Rust:** stable rustc ≥ 1.92 (eframe 0.35). Developed on 1.94.1; there is no `rust-toolchain` file. Don't bump eframe without checking its MSRV. - **Opus:** vendored native libopus (`crates/opus-sys`, float build, `USE_ALLOCA`) built with `cc`. Keep stack temporaries (`USE_ALLOCA`/`VAR_ARRAYS`): decoding runs inside `PlayoutHandle::fill`, so it must not heap-allocate. Don't switch back to `unsafe-libopus` (its c2rust VLAs allocate on every decode). - **Android:** - - NDK r23 (`23.1.7779620`) via cargo-ndk. - - `[package.metadata.ndk] platform = 26`, because AAudio starts at API 26. + - NDK r30 (`30.0.16248370`) via cargo-ndk 4.x. + - Always pass `--platform 26` to cargo-ndk, because AAudio starts at API 26 (cargo-ndk 4 ignores `[package.metadata.ndk]` and defaults to API 21, which fails with `-laaudio`). - Use raw `ndk-sys` AAudio; API-28 setters are looked up with `dlsym`. Never enable the `ndk` crate's `api-level-28` feature: the library would fail to load on API 26/27. - Input preset `VoiceRecognition`, never `VoiceCommunication`, which forces Bluetooth SCO/HFP and ruins A2DP. - **Android build:** AGP 8.10.1, Kotlin 2.2.0, Gradle 8.11.1 wrapper, JDK 17 target. Compose versions are pinned explicitly (no BOM). `FAIL_ON_PROJECT_REPOS` means repositories are declared only in `settings.gradle.kts`. diff --git a/README.md b/README.md index be1ae19..ec16bc5 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ See [AGENTS.md](AGENTS.md) for the detailed developer guide. ```powershell cargo test -p audiobridge-core cargo build -p audiobridge-desktop --release # target\release\AudioBridge.exe -cd android; .\gradlew.bat :app:assembleDebug # needs Android SDK, NDK r23 and cargo-ndk +cd android; .\gradlew.bat :app:assembleDebug # needs Android SDK, NDK r30 and cargo-ndk 4.x ``` Rust ≥ 1.92. Opus is vendored and built with `cc`, so you don't need cmake. diff --git a/README.ru.md b/README.ru.md index 7dcbf7f..9bc6510 100644 --- a/README.ru.md +++ b/README.ru.md @@ -53,7 +53,7 @@ AudioBridge передаёт весь звук компьютера на Android ```powershell cargo test -p audiobridge-core cargo build -p audiobridge-desktop --release # target\release\AudioBridge.exe -cd android; .\gradlew.bat :app:assembleDebug # нужны Android SDK, NDK r23 и cargo-ndk +cd android; .\gradlew.bat :app:assembleDebug # нужны Android SDK, NDK r30 и cargo-ndk 4.x ``` Подробное описание архитектуры — в [AGENTS.md](AGENTS.md). Pull request'ы приветствуются, см. [CONTRIBUTING.md](CONTRIBUTING.md). diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 8fac6d9..35b6534 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -68,6 +68,7 @@ dependencies { // Skip with -PskipRust (e.g. when the Rust toolchain is unavailable and a prebuilt .so is already present). val repoRoot: File = rootProject.projectDir.parentFile val jniLibsDir: File = project.file("src/main/jniLibs") +val rustTargetDir: File = System.getenv("CARGO_TARGET_DIR")?.let { repoRoot.resolve(it) } ?: repoRoot.resolve("target") val skipRust: Boolean = providers.gradleProperty("skipRust").isPresent val buildRustLib by tasks.registering(Exec::class) { @@ -77,7 +78,8 @@ val buildRustLib by tasks.registering(Exec::class) { commandLine( "cargo", "ndk", "-t", "arm64-v8a", - "-o", jniLibsDir.absolutePath, + // AAudio (libaaudio.so) exists from API 26 (= minSdk); cargo-ndk defaults to API 21. + "--platform", "26", "build", "--release", "-p", "audiobridge-android", ) @@ -87,6 +89,14 @@ val buildRustLib by tasks.registering(Exec::class) { // cargo tracks its own incremental state; always let it decide what to rebuild. outputs.upToDateWhen { false } onlyIf { !skipRust } + // Not `cargo ndk -o`: cargo-ndk 4 copies every cdylib artifact, including iroh's own cdylibs. + val builtLib = rustTargetDir.resolve("aarch64-linux-android/release/libaudiobridge.so") + val abiDir = jniLibsDir.resolve("arm64-v8a") + doLast { + abiDir.mkdirs() + abiDir.listFiles()?.filter { it.name != builtLib.name }?.forEach { it.delete() } + builtLib.copyTo(abiDir.resolve(builtLib.name), overwrite = true) + } } tasks.configureEach { diff --git a/crates/android-native/Cargo.toml b/crates/android-native/Cargo.toml index 8733a4f..c561535 100644 --- a/crates/android-native/Cargo.toml +++ b/crates/android-native/Cargo.toml @@ -27,8 +27,3 @@ android_logger = "0.15" tracing = { version = "0.1", features = ["log"] } # iroh's DNS resolver reads the system DNS config through ndk-context; JNI init installs the app context. ndk-context = "0.1" - -[package.metadata.ndk] -# AAudio (libaaudio.so) exists from API 26; cargo-ndk would otherwise link against API 21 stubs. -platform = 26 -targets = ["arm64-v8a"]