Skip to content

Commit 5cd1f3c

Browse files
Copilotwinnerspiros
andcommitted
Fix release workflow: build native library (libosu_native.so) and include it in APK
The release workflow was producing APKs without the native library, making Oboe low-latency audio and Vulkan probe features completely non-functional. - Update CMakeLists.txt to use FetchContent for Oboe (self-contained build) - Add conditional AndroidNativeLibrary items to csproj for each ABI - Add NDK/CMake setup and native build steps to release workflow - Add .gitignore entries for native build artifacts Agent-Logs-Url: https://github.com/winnerspiros/osu/sessions/89b53171-bb76-44d0-9986-affb5059fb3c Co-authored-by: winnerspiros <1675249+winnerspiros@users.noreply.github.com>
1 parent 487ea8c commit 5cd1f3c

4 files changed

Lines changed: 57 additions & 3 deletions

File tree

.github/workflows/release.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,34 @@ jobs:
3232
- name: Install .NET Android workload
3333
run: dotnet workload install android
3434

35+
- name: Ensure Android NDK and CMake are available
36+
run: |
37+
# The ubuntu-latest runner has $ANDROID_HOME pre-installed.
38+
# Install a known NDK + CMake version if not already present.
39+
yes | sdkmanager --licenses > /dev/null 2>&1 || true
40+
sdkmanager --install "ndk;27.0.12077973" "cmake;3.22.1" > /dev/null 2>&1
41+
42+
- name: Build native library (libosu_native.so)
43+
run: |
44+
NDK_HOME="$ANDROID_HOME/ndk/27.0.12077973"
45+
CMAKE_BIN="$ANDROID_HOME/cmake/3.22.1/bin/cmake"
46+
47+
for ABI in arm64-v8a armeabi-v7a x86; do
48+
echo "::group::Building osu_native for $ABI"
49+
"$CMAKE_BIN" -B "build-native/$ABI" -S osu.Android/Native \
50+
-DCMAKE_TOOLCHAIN_FILE="$NDK_HOME/build/cmake/android.toolchain.cmake" \
51+
-DANDROID_ABI="$ABI" \
52+
-DANDROID_PLATFORM=android-30 \
53+
-DCMAKE_BUILD_TYPE=Release
54+
"$CMAKE_BIN" --build "build-native/$ABI" --config Release -j "$(nproc)"
55+
mkdir -p "osu.Android/libs/$ABI"
56+
cp "build-native/$ABI/libosu_native.so" "osu.Android/libs/$ABI/"
57+
echo "::endgroup::"
58+
done
59+
60+
echo "Native libraries built successfully:"
61+
find osu.Android/libs -name "*.so" -exec ls -lh {} \;
62+
3563
- name: Decode keystore
3664
id: keystore
3765
run: |

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,7 @@ FodyWeavers.xsd
344344

345345
.idea/.idea.osu.Desktop/.idea/misc.xml
346346
.idea/.idea.osu.Android/.idea/deploymentTargetDropDown.xml
347+
348+
# Native library build artifacts (built by CMake/NDK in CI or locally)
349+
osu.Android/libs/
350+
build-native/

osu.Android/Native/CMakeLists.txt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,22 @@ set(CMAKE_CXX_STANDARD 17)
77
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -flto -fvisibility=hidden -DNDEBUG")
88
set(CMAKE_C_FLAGS_RELEASE "-O2 -flto -fvisibility=hidden -DNDEBUG")
99

10-
find_package(oboe REQUIRED CONFIG)
10+
# Try pre-installed Oboe first (e.g. via Android NDK prefab or local install).
11+
# If not found, download and build from source for CI/hermetic builds.
12+
find_package(oboe QUIET CONFIG)
13+
14+
if(oboe_FOUND)
15+
set(OBOE_LIB oboe::oboe)
16+
else()
17+
include(FetchContent)
18+
FetchContent_Declare(oboe
19+
URL https://github.com/google/oboe/archive/refs/tags/1.9.0.tar.gz
20+
URL_HASH SHA256=e030276d25b8bdfaeb04f66646821b1ba4a2b6a580a7e84fb144a478eaecd663
21+
)
22+
FetchContent_MakeAvailable(oboe)
23+
set(OBOE_LIB oboe)
24+
endif()
25+
1126
find_library(vulkan-lib vulkan)
1227
find_library(log-lib log)
1328
find_library(android-lib android)
@@ -18,7 +33,7 @@ add_library(osu_native SHARED
1833
)
1934

2035
target_link_libraries(osu_native
21-
oboe::oboe
36+
${OBOE_LIB}
2237
${vulkan-lib}
2338
${log-lib}
2439
${android-lib}

osu.Android/osu.Android.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@
1919
<ItemGroup>
2020
<PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.3" />
2121
</ItemGroup>
22-
<!-- Exclude native C++ source files from the build. They are compiled separately via CMake/NDK. -->
22+
<!-- Exclude native C++ source files from the managed build. They are compiled separately via CMake/NDK. -->
2323
<ItemGroup>
2424
<None Remove="Native\*.cpp" />
2525
<None Remove="Native\*.h" />
2626
<None Remove="Native\CMakeLists.txt" />
2727
</ItemGroup>
28+
<!-- Include pre-built native libraries when present (built by the release workflow or local NDK build).
29+
When absent, native features (Oboe audio, Vulkan probe) are gracefully disabled at runtime. -->
30+
<ItemGroup>
31+
<AndroidNativeLibrary Include="libs\arm64-v8a\libosu_native.so" Condition="Exists('libs\arm64-v8a\libosu_native.so')" Abi="arm64-v8a" />
32+
<AndroidNativeLibrary Include="libs\armeabi-v7a\libosu_native.so" Condition="Exists('libs\armeabi-v7a\libosu_native.so')" Abi="armeabi-v7a" />
33+
<AndroidNativeLibrary Include="libs\x86\libosu_native.so" Condition="Exists('libs\x86\libosu_native.so')" Abi="x86" />
34+
</ItemGroup>
2835
</Project>

0 commit comments

Comments
 (0)