Add cloud-setup.sh bootstrap script for Claude Code sandbox#144
Merged
Conversation
Captures the Android SDK + Robolectric bootstrap script the Claude Code cloud sandbox runs, so it lives in version control alongside the code it sets up. Fixes a session-env drift issue where ANDROID_HOME was sometimes exported as the literal string "$REPO_ROOT/.android-sdk" (REPO_ROOT unset), leaving agents convinced the SDK was missing: - Writes ANDROID_HOME, ANDROID_SDK_ROOT, and CI=true to both $CLAUDE_ENV_FILE and ~/.bashrc, stripping prior exports first so the script is idempotent. - Adds a sanity check that warns loudly when the running env doesn't match the installed SDK path, so future drift surfaces immediately instead of silently misleading agents.
The 130-line walkthrough of manual proxy config, curl-based SDK installs, hand-written package.xml files, and Robolectric jar fetches was telling agents to redo work that .claude/cloud-setup.sh now does automatically before the session starts. Following those steps either succeeded redundantly or failed partway and convinced agents the SDK was unavailable. Replace it with a short status section pointing at .claude/cloud-setup.sh, and add a recovery hint for the literal "$REPO_ROOT/.android-sdk" env drift case. Other cloud sandbox sections (Cursor Cloud) are left unchanged.
Three steps still did work on every run even when nothing changed: - local.properties was rewritten unconditionally - env-var lines used sed-delete-then-append every run - ./gradlew dependencies (multi-minute) ran every time Now each step short-circuits when its target is already in the desired state: local.properties is only rewritten if missing or content-mismatched, env-var writes skip when the exact `export KEY=VALUE` line already exists, and the gradle dependency warm-up is gated on a sentinel file (.android-sdk/.gradle-deps-warmed) keyed on a CACHE_VERSION + SDK path token. A re-run with everything in place now logs only a single "skipping" line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Automates Android SDK and Robolectric setup for Claude Code cloud sandbox sessions by introducing a new bootstrap script (
.claude/cloud-setup.sh) and updating documentation to reflect the automated setup flow.Key Changes
New bootstrap script (
.claude/cloud-setup.sh): Idempotent shell script that:package.xmlmetadata files for AGP recognitionlocal.propertieswith correct SDK path~/.robolectric/ANDROID_HOME,ANDROID_SDK_ROOT, andCI=trueto both$CLAUDE_ENV_FILEand~/.bashrcfor persistenceUpdated AGENTS.md documentation:
Implementation Details
$CLAUDE_ENV_FILE(Claude's mechanism) and~/.bashrcto handle cases where platform-level session env overrides one or the otherCACHE_VERSIONandSDK_ROOTto invalidate cache when SDK components changehttps://claude.ai/code/session_01PBpz6hivdEDaPWDqkx8vDf