Repository navigation
fix(android): honor ANDROID_HOME/ANDROID_SDK_ROOT in build_android_library.sh (#22682) - #25931
wangkangmao wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25931
Note: Links to docs will display an error until the docs builds have been completed.
|
|
Hi @wangkangmao! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
This PR needs a
|
Fixes #22682
Root cause
scripts/build_android_library.shderives the Gradle SDK path exclusively fromANDROID_SDK:GitHub Android runners and most developer environments export
ANDROID_HOMEorANDROID_SDK_ROOTinstead. With only those set, the script ignores the configured SDK and points Gradle at the hardcoded/opt/android/sdk, which either does not exist or is the wrong SDK. This was found during validation of the documentation-only PR #22620 and the implementation change was intentionally deferred from that PR.Change
Resolve the SDK path once at the top of
build_aar()in a stable priority order —ANDROID_SDK>ANDROID_HOME>ANDROID_SDK_ROOT>/opt/android/sdk— and pass the resolved value to Gradle through both standard variables:Keeping
ANDROID_SDKfirst preserves the existing behavior for current users; adding the two standard variables fixes both the runner case and local setups that only exportANDROID_SDK_ROOT. Scope is limited to SDK path resolution: no build flags, targets, or CMake logic change. 5 lines added, 2 removed, 1 file.Verification
Offline harness (
bash -n+ source the script with a mocked./gradlew, callbuild_aar(), read the environment gradlew receives):ANDROID_HOMEgradlew seesANDROID_SDK_ROOTgradlew seesANDROID_SDK=/sdk/from-ANDROID_SDK/sdk/from-ANDROID_SDK/sdk/from-ANDROID_SDKANDROID_HOME=/sdk/from-ANDROID_HOME/sdk/from-ANDROID_HOME/sdk/from-ANDROID_HOMEANDROID_SDK_ROOT=/sdk/from-ANDROID_SDK_ROOT/sdk/from-ANDROID_SDK_ROOT/sdk/from-ANDROID_SDK_ROOT/opt/android/sdk/opt/android/sdk/sdk/S(SDK wins)/sdk/S/sdk/H(HOME wins)/sdk/HNegative control against the unmodified script: with only
ANDROID_HOME=/sdk/from-ANDROID_HOME, gradlew receivesANDROID_HOME=/opt/android/sdk— the exact bug from the issue.Additional checks:
The full Android AAR build (
./gradlew build/:executorch_android:testDebugUnitTest) was not run locally: this Windows host has no configured Android NDK/preset cmake-out for this repo, and the change does not alter compilation flags or code — it only changes how the SDK path is resolved before invoking Gradle. The harness above exercises the exact function and the exact gradlew invocation sites that were modified. CI's Android AAR and emulator jobs will cover the end-to-end path.cc @nil-is-all