You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e25369b
Browse filesBrowse the repository at this point in the historyBrowse files
Android: build/runtime fixes for modern Clang + ETDump path override (pytorch#19293)
## Summary
Five small fixes needed to build and run ExecuTorch Android on hosts
with Apple Clang 21, on devices where `/data/local/tmp` isn't
app-writable, and to make the Android build script behave correctly on
hosts with multiple Python interpreters:
1. **flatcc `-Werror` on modern Clang.** flatcc's vendored
`CMakeLists.txt` hits `-Wimplicit-int-conversion-on-negation` and
`-Wunterminated-string-initialization` on new Clang. Pass
`FLATCC_ALLOW_WERROR=OFF` into the `flatcc_ep` ExternalProject so the
third-party build doesn't fail.
2. **`EXECUTORCH_ANDROID_PROFILING` was never forwarded.**
`scripts/build_android_library.sh` set `EXECUTORCH_ENABLE_EVENT_TRACER`
from `$EXECUTORCH_ANDROID_PROFILING` but never forwarded the separate
`-DEXECUTORCH_ANDROID_PROFILING` define that gates `ETDumpGen`
allocation in `extension/android/jni/jni_layer.cpp`. As a result the
event tracer was compiled in but the JNI never attached it, and
`Module.etdump()` always returned `false`.
3. **`Module.etdump(String outputPath)` overload.** Add a JNI method
(`etdumpToNative`) and Java wrapper so apps can write the ETDump into
their own `filesDir`. The existing `etdump()` hardcodes
`/data/local/tmp/result.etdump`, which is not app-writable on modern
Android (Pixel 9 / API 36 returns `EACCES`). The new overload factors
the write path through a shared `etdump_to_path()` helper; `etdump()`
now delegates to it with the legacy path.
4. **`define_overridable_option` was expanding `${DESCRIPTION}`
unquoted.** The `set(... CACHE TYPE DOCSTRING [FORCE])` form expects the
docstring as a single argument, but `${DESCRIPTION}` was unquoted, so
any `STRING` option with a multi-word description that the user
overrides on the cmake command line had its description text spill into
subsequent `set()` arguments. One-character fix: quote
`"${DESCRIPTION}"` in both `set()` calls.
5. **`scripts/build_android_library.sh` never forwarded
`PYTHON_EXECUTABLE` to cmake.** The script defaults
`PYTHON_EXECUTABLE=python3` and honors a caller override, but only used
it for `which`. cmake's `find_package(Python3)` then picked up whatever
interpreter came first on PATH (e.g. Homebrew's `python3` on macOS)
instead of the project's torch-equipped venv, failing at
`find_package_torch_headers` with `'NoneType' object has no attribute
'submodule_search_locations'`. Pass
`-DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}"` so the script's documented
behavior actually flows through.
## Test plan
- [x] Apple Clang 21 host build: `scripts/build_android_library.sh` now
succeeds (flatcc no longer fails `-Werror`).
- [x] With `EXECUTORCH_ANDROID_PROFILING=1`:
`-DEXECUTORCH_ANDROID_PROFILING` reaches the JNI compile, `ETDumpGen` is
attached, `Module.etdump()` returns `true` and writes a valid `.etdump`.
- [x] On Pixel 9 / API 36: `Module.etdump(context.getFilesDir() +
"/result.etdump")` succeeds; legacy `Module.etdump()` still works on
devices where `/data/local/tmp` is writable.
- [x] Default build (`EXECUTORCH_ANDROID_PROFILING` unset): unchanged —
`etdump()` returns `false` as before.
- [x] `cmake -DEXECUTORCH_VULKAN_FP16_PRECISION=mediump …` (multi-word
description STRING option) now configures cleanly.
- [x] Hosts with both Homebrew `python3` and a torch-equipped venv:
`PYTHON_EXECUTABLE=$VENV/bin/python scripts/build_android_library.sh`
configures correctly.
🤖 Authored with [Claude Code](https://claude.com/claude-code)
cc @kirklandsign@cbilgin
0 commit comments