Fix Android NDK build on Linux (Boost include resolution)#16
Merged
Conversation
The native libtorrent build only ever ran on macOS in CI, so the Linux path was effectively untested and broke in two ways: 1. build.gradle.kts read the Boost paths from environment variables only, falling back to macOS Homebrew defaults. Builds from the IDE (where shell exports aren't visible) always used the wrong paths. 2. On Debian/Ubuntu, Boost lives in /usr/include alongside glibc. Putting that dir on the Android cross-compiler's search path (in any position) pulls host libc headers into the NDK's #include_next chains, breaking the build (missing bits/wordsize.h, bits/libc-header-start.h). BOOST_ INCLUDE_DIR must point at a Boost-only directory, as Homebrew already provides on macOS. Changes: - build.gradle.kts: resolve BOOST_CMAKE_DIR / BOOST_INCLUDE_DIR via env var -> local.properties -> macOS default, so the IDE works without shell exports. macOS behavior is unchanged. - CMakeLists.txt: document that BOOST_INCLUDE_DIR must be a Boost-only dir, never /usr/include (comment only; the -I flag is unchanged).
- README: correct the Linux instructions to use an isolated Boost include dir (not /usr/include, which breaks the NDK #include_next chains) and document the local.properties fallback for Android Studio. - CI: add a Linux "Build Debug APK" job that runs on every push/PR, so the Linux NDK toolchain is exercised and can't silently regress again. It reuses the same isolated-Boost-dir setup already proven in the instrumented-tests job.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The native libtorrent build only ran on macOS in CI, so the Linux build path was effectively untested and broke in two ways:
IDE builds used the wrong paths.
app/build.gradle.ktsread the Boost locations from environment variables only, falling back to macOS Homebrew defaults (/opt/homebrew/...). Android Studio doesn't inherit shellexports, so it always used the macOS paths on Linux./usr/includecan't be on the NDK cross-compiler's search path. On Debian/Ubuntu,libboost-devinstalls Boost into/usr/includealongside glibc. Putting that directory on the Android cross-compiler's include path — in any position — pulls host libc headers into the NDK's#include_nextchains, breaking the build (bits/wordsize.h,bits/libc-header-start.hnot found).BOOST_INCLUDE_DIRmust point at a Boost-only directory, which Homebrew already provides on macOS.Changes
app/build.gradle.kts— resolveBOOST_CMAKE_DIR/BOOST_INCLUDE_DIRviaenv var → local.properties → macOS default, so Android Studio works on Linux without shell exports. macOS behavior is unchanged.app/src/main/cpp/CMakeLists.txt— comment only: document thatBOOST_INCLUDE_DIRmust be a Boost-only dir, never/usr/include. The-Iflag is unchanged.README.md— corrected Linux instructions (isolated Boost dir) +local.propertiesoption for the IDE..github/workflows/android.yml— new "Build Debug APK (Linux)" job on every push/PR so the Linux NDK toolchain is exercised and can't silently regress. Reuses the isolated-Boost-dir setup already proven in the instrumented-tests job.Testing
Verified locally on Ubuntu (NDK r29, Boost 1.83): clean
./gradlew assembleDebugwith no Boost env vars set (the IDE scenario, resolving fromlocal.properties) produces a 46Mapp-debug.apkwithlibsimpletorrent.soforarm64-v8aandx86_64.