Commit e25369b
authored
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 @cbilgin1 parent 8020fe0 commit e25369b
5 files changed
Lines changed: 76 additions & 28 deletions
File tree
- extension/android
- executorch_android/src/main/java/org/pytorch/executorch
- jni
- scripts
- third-party
- tools/cmake/common
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
230 | 252 | | |
231 | 253 | | |
232 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
466 | 466 | | |
467 | 467 | | |
468 | 468 | | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
| 469 | + | |
| 470 | + | |
473 | 471 | | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
494 | 476 | | |
495 | | - | |
496 | | - | |
| 477 | + | |
497 | 478 | | |
498 | 479 | | |
499 | 480 | | |
| |||
565 | 546 | | |
566 | 547 | | |
567 | 548 | | |
| 549 | + | |
568 | 550 | | |
569 | 551 | | |
570 | 552 | | |
571 | 553 | | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
572 | 594 | | |
573 | 595 | | |
574 | 596 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| |||
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
| 56 | + | |
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
0 commit comments