Skip to content

fix(android): honor ANDROID_HOME/ANDROID_SDK_ROOT in build_android_library.sh (#22682) - #25931

Open
wangkangmao wants to merge 1 commit into
pytorch:mainfrom
wangkangmao:fix/android-sdk-env-vars-22682
Open

wangkangmao wants to merge 1 commit into
pytorch:mainfrom
wangkangmao:fix/android-sdk-env-vars-22682

Conversation

@wangkangmao

@wangkangmao wangkangmao commented Dec 1, 2026 •

Copy link
Copy Markdown

Fixes #22682

Root cause

scripts/build_android_library.sh derives the Gradle SDK path exclusively from ANDROID_SDK:

ANDROID_HOME="${ANDROID_SDK:-/opt/android/sdk}" ./gradlew build
ANDROID_HOME="${ANDROID_SDK:-/opt/android/sdk}" ./gradlew :executorch_android:testDebugUnitTest

GitHub Android runners and most developer environments export ANDROID_HOME or ANDROID_SDK_ROOT instead. 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:

local android_sdk="${ANDROID_SDK:-${ANDROID_HOME:-${ANDROID_SDK_ROOT:-/opt/android/sdk}}}"
ANDROID_HOME="${android_sdk}" ANDROID_SDK_ROOT="${android_sdk}" ./gradlew build

Keeping ANDROID_SDK first preserves the existing behavior for current users; adding the two standard variables fixes both the runner case and local setups that only export ANDROID_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, call build_aar(), read the environment gradlew receives):

Scenario ANDROID_HOME gradlew sees ANDROID_SDK_ROOT gradlew sees
ANDROID_SDK=/sdk/from-ANDROID_SDK /sdk/from-ANDROID_SDK /sdk/from-ANDROID_SDK
ANDROID_HOME=/sdk/from-ANDROID_HOME /sdk/from-ANDROID_HOME /sdk/from-ANDROID_HOME
ANDROID_SDK_ROOT=/sdk/from-ANDROID_SDK_ROOT /sdk/from-ANDROID_SDK_ROOT /sdk/from-ANDROID_SDK_ROOT
none set /opt/android/sdk /opt/android/sdk
SDK+HOME+ROOT all set /sdk/S (SDK wins) /sdk/S
HOME+ROOT set /sdk/H (HOME wins) /sdk/H

Negative control against the unmodified script: with only ANDROID_HOME=/sdk/from-ANDROID_HOME, gradlew receives ANDROID_HOME=/opt/android/sdk — the exact bug from the issue.

Additional checks:

bash -n scripts/build_android_library.sh        # exit 0
git diff --check                                 # clean

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

@pytorch-bot

pytorch-bot Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🔗 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.

⚠️ 16 Awaiting Approval

As of commit db4f1d4 with merge base 80c59c7 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla

meta-cla Bot commented Dec 1, 2026

Copy link
Copy Markdown

Hi @wangkangmao!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@linux-foundation-easycla

Copy link
Copy Markdown

CLA Not Signed

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@executorch-triage executorch-triage Bot added the community: contribution PRs coming from community (excluding hardware partners) label Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community: contribution PRs coming from community (excluding hardware partners)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Honor standard SDK environment variables in build_android_library.sh

1 participant