Skip to content

Fix Android NDK build on Linux (Boost include resolution)#16

Merged
jpcottin merged 2 commits into
masterfrom
fix/linux-ndk-boost-build
Jun 2, 2026
Merged

Fix Android NDK build on Linux (Boost include resolution)#16
jpcottin merged 2 commits into
masterfrom
fix/linux-ndk-boost-build

Conversation

@jpcottin

@jpcottin jpcottin commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Problem

The native libtorrent build only ran on macOS in CI, so the Linux build path was effectively untested and broke in two ways:

  1. IDE builds used the wrong paths. app/build.gradle.kts read the Boost locations from environment variables only, falling back to macOS Homebrew defaults (/opt/homebrew/...). Android Studio doesn't inherit shell exports, so it always used the macOS paths on Linux.

  2. /usr/include can't be on the NDK cross-compiler's search path. On Debian/Ubuntu, libboost-dev installs Boost into /usr/include alongside glibc. Putting that directory on the Android cross-compiler's include path — in any position — pulls host libc headers into the NDK's #include_next chains, breaking the build (bits/wordsize.h, bits/libc-header-start.h not found). BOOST_INCLUDE_DIR must point at a Boost-only directory, which Homebrew already provides on macOS.

Changes

  • app/build.gradle.kts — resolve BOOST_CMAKE_DIR / BOOST_INCLUDE_DIR via env 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 that BOOST_INCLUDE_DIR must be a Boost-only dir, never /usr/include. The -I flag is unchanged.
  • README.md — corrected Linux instructions (isolated Boost dir) + local.properties option 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 assembleDebug with no Boost env vars set (the IDE scenario, resolving from local.properties) produces a 46M app-debug.apk with libsimpletorrent.so for arm64-v8a and x86_64.

Note: local.properties is gitignored and is not part of this PR; the README documents what to put in it.

jpcottin added 2 commits June 1, 2026 17:17
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.
@jpcottin jpcottin merged commit 9d2da8e into master Jun 2, 2026
5 checks passed
@jpcottin jpcottin deleted the fix/linux-ndk-boost-build branch June 2, 2026 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant