Android: compile shared platform-neutral Java sources in place (step 1 of desktop JVM support) - #22338
Android: compile shared platform-neutral Java sources in place (step 1 of desktop JVM support)#22338RanjithRagavan wants to merge 4 commits into
Conversation
…1 of desktop JVM support) Move the platform-neutral Java/Kotlin API sources (Module, Tensor, EValue, DType, LlmModule, AsrModule, training, ...) from extension/android/executorch_android/src/main/java to a new shared source directory extension/java/src/main/java, preserving git history via renames. The Android AAR stays self-contained and behavior-identical: it compiles the shared sources directly via java.srcDirs, so there is no new published artifact, no new transitive dependency, no manifest change, and bytecode remains at Java 11. Verified locally by building release AARs before and after the move: the only classes.jar delta is one new internal class, org.pytorch.executorch.Log. Logging: Tensor.kt previously imported android.util.Log directly. Shared sources now reference an org.pytorch.executorch.Log facade by simple name; each platform artifact compiles exactly one implementation. The Android implementation (new Log.kt in the Android module) delegates to android.util.Log, so logcat tags, priorities, and messages are unchanged. The shared directory deliberately contains no Log definition, avoiding duplicate-class collisions. Buck targets in extension/android/BUCK keep their historical names, ownership, and attributes; their srcs now reference the shared location. This is step 1 of the plan discussed in pytorch#20761: land the behavior- preserving shared-source extraction first, then add the desktop JVM jar and native classifier publication on top.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22338
Note: Links to docs will display an error until the docs builds have been completed.
|
|
@pytorchbot label "release notes: none" |
|
@claude review |
|
Claude finished @kirklandsign's task in 7m 0s —— View job Code Review — Android shared Java sources (step 1)
Overall this is a clean, well-scoped refactor. The A few observations, mostly minor: 1. BUCK explicit list vs. Gradle glob — maintainability hazard (worth noting)The two build systems now consume the shared directory differently:
Consequence: when someone adds a new shared source, the OSS Gradle AAR compiles it (CI stays green) but the internal Buck build silently omits it until the 2. Gradle globs ASR/LLM/training that BUCK's
|
Summary
Step 1 of the desktop JVM plan discussed in #20761, implementing @psiddh's shared-source design: the platform-neutral Java/Kotlin API sources move to a neutral location and are compiled in place by each platform artifact, instead of shipping a shared runtime jar.
flowchart TD S["extension/java/src/main/java — 18 platform-neutral sources<br/>no android.* imports · Log facade by simple name · no Log definition here"] A["Android AAR (self-contained)<br/>shared classes compiled in · Log.kt delegates to android.util.Log<br/>Java 11 · one fbjni dep · no manifest provider"] J["Desktop JVM jar — step 2, not this PR<br/>same classes · console Log · per-OS native jars"] S -->|"compiled via java.srcDirs"| A S -.->|"compiled via kotlin.srcDirs"| JWhat changed
Module,Tensor,EValue,DType,ExecuTorchRuntime,LlmModule,AsrModule, training, annotations) movedextension/android/executorch_android/src/main/java→extension/java/src/main/javaviagit mv(blame/history preserved).executorch_android/build.gradle: main source set addsjava.srcDirs += ['../../java/src/main/java']; spotless target extended so ktfmt still covers the moved files.Tensor.ktdrops itsandroid.util.Logimport and calls theorg.pytorch.executorch.Logfacade by simple name (same package). The Android module compiles the one-file implementationLog.kt, delegating toandroid.util.Log— logcat tags/priorities/messages unchanged. The shared directory contains noLogdefinition, so there is exactly one implementation per artifact (no duplicate-class collision).ImageProcessorstays in the Android module (android.graphics.Bitmap).extension/android/BUCK: targets keep their historical names, ownership, and attributes (required_for_source_only_abi,pure_kotlin, deps);srcsnow reference the shared location.extension/java/README.mddocuments the sharing contract; docs link updated.Android shipping contract — preserved
Verification (run locally, macOS arm64, NDK 26.1, API 34 emulator)
Log.class; manifest/POM/natives unchanged; bytecode major 55 (Java 11) bothmain(pre-existing upstream test/native skew)Note:
extension/android/BUCKsrcsreferencing../java/src/main/java/...needs internal Buck/FoA validation — @psiddh kindly offered to own that side.Next steps after this lands (per the agreed sequencing in #20761): desktop JVM jar implementation, then native classifier publication.