Skip to content

emu_downloads: add ANDROID_REPOSITORY env var to override download base URL#411

Merged
jpcottin merged 2 commits into
google:masterfrom
jpcottin:feat/android-repository-env-override
May 16, 2026
Merged

emu_downloads: add ANDROID_REPOSITORY env var to override download base URL#411
jpcottin merged 2 commits into
google:masterfrom
jpcottin:feat/android-repository-env-override

Conversation

@jpcottin
Copy link
Copy Markdown
Collaborator

Why

All system-image and emulator-zip downloads are currently hardcoded to https://dl.google.com/.... That breaks for users behind corporate proxies, air-gapped environments, or in regions where Google's CDN is slow/unreachable — most prominently the long-standing #240 ("China available mirror image"). It also makes it hard to test new emulator releases via a staged mirror without forking the script.

Change

Two commits:

  1. Add override of download location. (cherry-pick of @gregersn's commit from Custom naming and repository #359, authored 2021-10-11) — introduces an ANDROID_REPOSITORY env var, defaulted to https://dl.google.com, and uses it as the base for system-image catalogs (sys-img2-5.xml), the emulator repo catalog (repository2-1.xml), the per-package system-image zip URLs, and the platform-tools download.

  2. normalize ANDROID_REPOSITORY trailing slash (mine) — small follow-up. The two modules disagreed on whether the default had a trailing slash (https://dl.google.com/ vs https://dl.google.com), and combined with format strings starting /android/... this produced https://dl.google.com//android/... (double slash). Normalized both defaults to no trailing slash and added .rstrip("/") so user-supplied bases with a trailing slash also work cleanly.

Conflict resolution notes

The original cherry-pick had two conflicts against current master, both resolved to keep HEAD's logic and apply the substitution:

  • SYSIMG_REPOS: kept HEAD's newer sys-img2-5.xml filenames (Greger's commit predated the bump and still referenced sys-img2-1.xml), wrapped each in %s/... with ANDROID_REPOSITORY.
  • AndroidReleaseZip.url construction: kept the url_dir = sort_base or self.tag logic (added later for 16KB-page sysimg URL routing — see the is_16k work), substituted ANDROID_REPOSITORY for the hardcoded base.

Credit

@gregersn opened the original feature in #359 (along with an unrelated --name flag). Splitting into two PRs (#410 for --name, this one for ANDROID_REPOSITORY) for reviewability. Original authorship preserved on commit 1 via cherry-pick.

Cross-link

Addresses #240 ("Requesting/Begging for a China available mirror image"). This PR provides the client-side override needed to point at any mirror; standing up the actual mirror is out of scope.

Test plan

  • All 42 existing unit tests pass (pytest tests/ --ignore=tests/e2e)
  • Functional verification of URL construction in three scenarios:
    • No env var: https://dl.google.com/android/repository/sys-img/android/sys-img2-5.xml
    • ANDROID_REPOSITORY=https://my-mirror.example.com: https://my-mirror.example.com/android/repository/sys-img/android/sys-img2-5.xml
    • ANDROID_REPOSITORY=https://my-mirror.example.com/ (trailing slash): same as above — rstrip prevents double-slash
  • CI from ci: add GitHub Actions workflow to run pytest on PRs #405 reruns the matrix (Python 3.10/3.11/3.12/3.13)

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 16, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

jpcottin added 2 commits May 16, 2026 14:53
Introduces an ANDROID_REPOSITORY environment variable, defaulting to
https://dl.google.com, as the base URL for all system-image catalog
fetches (sys-img2-5.xml), the emulator repo catalog (repository2-1.xml),
per-package system-image zip downloads, and the platform-tools download.

Lets users behind corporate proxies, in air-gapped environments, or
in regions where Google's CDN is slow or unreachable point at a mirror
instead.

Original implementation by Greger Stolt Nilsen from google#359; cherry-picked
onto current master with conflict resolutions to preserve current
master's sys-img2-5.xml index version and the url_dir routing logic for
16KB-page sysimg URLs.
…ling slash

The two modules disagreed on whether the default base URL had a trailing
slash (`https://dl.google.com/` vs `https://dl.google.com`). Combined
with format strings that start with `/android/...`, the slashed default
produced double-slash URLs (`https://dl.google.com//android/...`).
Servers usually tolerate this, but it's ugly in logs and breaks any
exact-match logic downstream.

Drop the trailing slash from both defaults, and `.rstrip("/")` the
env-var value so user-supplied bases with a trailing slash also produce
clean URLs.
@jpcottin jpcottin force-pushed the feat/android-repository-env-override branch from 4b8b0bb to 3c7ae13 Compare May 16, 2026 21:53
@jpcottin jpcottin merged commit f12e8ab into google:master May 16, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant