Skip to content

Commit b0c753b

Browse files
committed
refactor ios env
1 parent 3ec85f2 commit b0c753b

30 files changed

Lines changed: 875 additions & 194 deletions

CLAUDE.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,13 @@ examples/{platform}/
708708
│ └── devices/ # User device definitions
709709
│ ├── *.json
710710
│ └── devices.lock
711-
├── devbox.json # Includes plugin
711+
├── devbox.json # Includes plugin via path: (local development)
712712
└── README.md # Usage guide
713-
# Note: <plugin-dir> is "{platform}" for local includes (plugin:../plugins/{platform}),
714-
# but for GitHub includes it uses the full dotted path
715-
# (e.g., "segment-integrations.devbox-plugins.android").
713+
# Note: Examples use local path includes (path:../../plugins/{platform}/plugin.json)
714+
# so PR checks test against the current plugin source. User-facing docs show the
715+
# GitHub URL format (github:segment-integrations/devbox-plugins?dir=plugins/{platform}).
716+
# <plugin-dir> is "{platform}" for local/path includes, but for GitHub includes it
717+
# uses the full dotted path (e.g., "segment-integrations.devbox-plugins.android").
716718
```
717719

718720
**Test Directory Layout:**

examples/android/devbox.json

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["github:segment-integrations/devbox-plugins/main?dir=plugins/android"],
2+
"include": ["path:../../plugins/android/plugin.json"],
33
"packages": {
44
"jdk17": "latest",
55
"gradle": "latest"
@@ -11,14 +11,10 @@
1111
"shell": {
1212
"scripts": {
1313
"build": [
14-
"echo 'Building Android app...'",
15-
"gradle assembleDebug --info"
14+
"android.sh build"
1615
],
17-
"start:emu": [
18-
"android.sh emulator start ${1:-${ANDROID_DEFAULT_DEVICE:-max}}"
19-
],
20-
"stop:emu": [
21-
"android.sh emulator stop"
16+
"build:release": [
17+
"android.sh build --config Release"
2218
],
2319
"start:app": [
2420
"android.sh run ${1:-${ANDROID_DEFAULT_DEVICE:-max}}"
@@ -28,9 +24,6 @@
2824
],
2925
"test:e2e": [
3026
"process-compose -f tests/test-suite.yaml --no-server --tui=${TEST_TUI:-false}"
31-
],
32-
"test:e2e:debug": [
33-
"ANDROID_DEBUG_SETUP=1 process-compose -f tests/test-suite.yaml --no-server --tui=false --log-level=debug"
3427
]
3528
}
3629
}

examples/ios/devbox.json

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
{
2-
"include": ["github:segment-integrations/devbox-plugins/main?dir=plugins/ios"],
2+
"include": ["path:../../plugins/ios/plugin.json"],
33
"packages": {
44
"process-compose": "latest"
55
},
66
"shell": {
77
"scripts": {
8-
"build:ios": [
9-
"echo 'Building iOS app...'",
10-
"env -u LD -u LDFLAGS -u NIX_LDFLAGS -u NIX_CFLAGS_COMPILE -u NIX_CFLAGS_LINK xcodebuild -project ios.xcodeproj -scheme ios -configuration Debug -destination 'generic/platform=iOS Simulator' -derivedDataPath .devbox/virtenv/ios/DerivedData build"
8+
"build": [
9+
"ios.sh build"
1110
],
12-
"start:sim": [
13-
"ios.sh simulator start ${1:-${IOS_DEFAULT_DEVICE:-max}}"
14-
],
15-
"stop:sim": [
16-
"ios.sh simulator stop"
11+
"build:release": [
12+
"ios.sh build --config Release"
1713
],
1814
"start:app": [
1915
"ios.sh run ${1:-}"
2016
],
21-
"deploy": [
22-
"devbox run build:ios",
23-
"devbox run start:app"
24-
],
2517
"test": [
26-
"env -u LD -u LDFLAGS -u NIX_LDFLAGS -u NIX_CFLAGS_COMPILE -u NIX_CFLAGS_LINK xcodebuild -project ios.xcodeproj -scheme ios -configuration Debug -destination 'generic/platform=iOS Simulator' -derivedDataPath .devbox/virtenv/ios/DerivedData test"
18+
"ios.sh build --action test"
2719
],
2820
"test:e2e": [
2921
"process-compose -f tests/test-suite.yaml --no-server --tui=${TEST_TUI:-false}"

examples/react-native/devbox.json

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
{
2-
"include": ["github:segment-integrations/devbox-plugins/main?dir=plugins/react-native"],
2+
"include": ["path:../../plugins/react-native/plugin.json"],
33
"packages": [
44
"nodejs@20",
55
"watchman@latest",
66
"jdk17@latest",
77
"gradle@latest"
88
],
99
"env": {
10-
"IOS_APP_PROJECT": "ReactNativeExample.xcodeproj",
1110
"IOS_APP_SCHEME": "ReactNativeExample",
1211
"IOS_APP_BUNDLE_ID": "org.reactjs.native.example.ReactNativeExample",
13-
"IOS_APP_ARTIFACT": ".devbox/virtenv/ios/DerivedData/Build/Products/Debug-iphonesimulator/ReactNativeExample.app",
1412
"ANDROID_APP_ID": "com.reactnativeexample",
1513
"ANDROID_APP_APK": "android/app/build/outputs/apk/debug/app-debug.apk",
1614
"ANDROID_MAX_API": "35",
@@ -27,12 +25,21 @@
2725
],
2826
"build:android": [
2927
"devbox run install",
30-
"cd android && gradle assembleDebug"
28+
"android.sh build"
29+
],
30+
"build:android:release": [
31+
"devbox run install",
32+
"android.sh build --config Release"
3133
],
3234
"build:ios": [
3335
"devbox run install",
3436
"cd ios && pod install --repo-update",
35-
"cd ios && env -u LD -u LDFLAGS -u NIX_LDFLAGS -u NIX_CFLAGS_COMPILE -u NIX_CFLAGS_LINK xcodebuild -workspace ReactNativeExample.xcworkspace -scheme ${IOS_APP_SCHEME} -configuration Debug -destination 'generic/platform=iOS Simulator' -derivedDataPath ${DEVBOX_PROJECT_ROOT}/.devbox/virtenv/ios/DerivedData -quiet build"
37+
"ios.sh build --quiet"
38+
],
39+
"build:ios:release": [
40+
"devbox run install",
41+
"cd ios && pod install --repo-update",
42+
"ios.sh build --config Release --quiet"
3643
],
3744
"build:web": [
3845
"devbox run install",
@@ -43,12 +50,26 @@
4350
"devbox run build:ios",
4451
"devbox run build:web"
4552
],
53+
"build:debug": [
54+
"devbox run build:android",
55+
"devbox run build:ios"
56+
],
57+
"build:release": [
58+
"devbox run build:android:release",
59+
"devbox run build:ios:release"
60+
],
4661
"start:android": [
4762
"process-compose -f tests/dev-android.yaml --tui=${DEVBOX_TUI:-false}"
4863
],
64+
"start:android:release": [
65+
"ANDROID_BUILD_CONFIG=Release process-compose -f tests/dev-android.yaml --tui=${DEVBOX_TUI:-false}"
66+
],
4967
"start:ios": [
5068
"process-compose -f tests/dev-ios.yaml --tui=${DEVBOX_TUI:-false}"
5169
],
70+
"start:ios:release": [
71+
"IOS_BUILD_CONFIG=Release process-compose -f tests/dev-ios.yaml --tui=${DEVBOX_TUI:-false}"
72+
],
5273
"start:web": [
5374
"process-compose -f tests/dev-web.yaml --tui=${DEVBOX_TUI:-false}"
5475
],

examples/react-native/tests/dev-android.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ processes:
3838
# Phase 2: Build Android app (Debug)
3939
build-android:
4040
command: |
41-
. ${ANDROID_RUNTIME_DIR}/scripts/init/setup.sh
42-
echo '📦 Building Android app (Debug)...'
43-
cd android && gradle assembleDebug
41+
BUILD_CONFIG="${ANDROID_BUILD_CONFIG:-Debug}"
42+
echo "📦 Building Android app (${BUILD_CONFIG})..."
43+
android.sh build --config "$BUILD_CONFIG"
4444
echo '✓ Build complete'
4545
depends_on:
4646
build-node:

examples/react-native/tests/dev-ios.yaml

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,8 @@ processes:
119119
command: |
120120
set -e
121121
122-
# Use Debug build for fast compilation
123-
BUILD_CONFIG="Debug"
124-
125-
PROJECT_ROOT="${DEVBOX_PROJECT_ROOT:-$(pwd)}"
126-
echo "📲 Building React Native app (Debug)"
127-
echo "Build configuration: $BUILD_CONFIG"
122+
BUILD_CONFIG="${IOS_BUILD_CONFIG:-Debug}"
123+
echo "📲 Building React Native app (${BUILD_CONFIG})"
128124
129125
. ${REACT_NATIVE_VIRTENV}/metro/env-ios.sh
130126
echo "Metro port: $METRO_PORT"
@@ -149,28 +145,13 @@ processes:
149145
150146
echo "Building for simulator: $DEVICE_UDID"
151147
152-
DERIVED_DATA_PATH="$PROJECT_ROOT/.devbox/virtenv/ios/DerivedData"
153-
mkdir -p "$DERIVED_DATA_PATH"
154-
155-
# Build with xcodebuild (Debug for fast iteration)
156-
(
157-
cd ios
158-
env -u LD -u LDFLAGS -u NIX_LDFLAGS -u NIX_CFLAGS_COMPILE -u NIX_CFLAGS_LINK \
159-
NODE_BINARY="$NODE_BINARY" \
160-
RCT_METRO_PORT="$METRO_PORT" \
161-
xcodebuild \
162-
-workspace ReactNativeExample.xcworkspace \
163-
-scheme ${IOS_APP_SCHEME} \
164-
-configuration "$BUILD_CONFIG" \
165-
-destination "id=$DEVICE_UDID" \
166-
-derivedDataPath "$DERIVED_DATA_PATH" \
167-
-quiet \
168-
build
169-
)
148+
# Build with ios.sh build
149+
NODE_BINARY="$NODE_BINARY" RCT_METRO_PORT="$METRO_PORT" \
150+
ios.sh build --config "$BUILD_CONFIG" --quiet
170151
171152
# Install the built app
172153
echo "Installing app to simulator..."
173-
APP_PATH="${DEVBOX_PROJECT_ROOT}/.devbox/virtenv/ios/DerivedData/Build/Products/Debug-iphonesimulator/ReactNativeExample.app"
154+
APP_PATH="${IOS_DERIVED_DATA_PATH:-${DEVBOX_PROJECT_ROOT}/.devbox/virtenv/ios/DerivedData}/Build/Products/${BUILD_CONFIG}-iphonesimulator/ReactNativeExample.app"
174155
175156
if [ ! -d "$APP_PATH" ]; then
176157
echo "ERROR: App bundle not found at $APP_PATH"

examples/react-native/tests/test-suite-android-e2e.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ processes:
3939
# Phase 2: Build Android app
4040
build-android:
4141
command: |
42-
# Source Android environment
43-
. ${ANDROID_RUNTIME_DIR}/scripts/init/setup.sh
44-
echo '📦 Building Android app...'
45-
cd android && gradle assembleDebug
42+
BUILD_CONFIG="${ANDROID_BUILD_CONFIG:-Debug}"
43+
echo "📦 Building Android app (${BUILD_CONFIG})..."
44+
android.sh build --config "$BUILD_CONFIG"
4645
echo '✓ Build complete'
4746
depends_on:
4847
build-node:

examples/react-native/tests/test-suite-ios-e2e.yaml

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,13 @@ processes:
135135
timeout_seconds: 60
136136
success_threshold: 1
137137

138-
# Phase 6: Build and deploy app with xcodebuild
138+
# Phase 6: Build and deploy app
139139
deploy-ios:
140140
command: |
141141
set -e
142142
143-
# Set build configuration (default to Release for E2E tests)
144-
BUILD_CONFIG="Release"
145-
test -n "${IOS_BUILD_CONFIG:-}" && BUILD_CONFIG="$IOS_BUILD_CONFIG"
146-
147-
# Get absolute project root path
148-
PROJECT_ROOT="${DEVBOX_PROJECT_ROOT:-}"
149-
test -z "$PROJECT_ROOT" && PROJECT_ROOT="$(pwd)"
150-
151-
echo "📲 Building React Native app"
152-
echo "Build configuration: $BUILD_CONFIG"
153-
echo "Project root: $PROJECT_ROOT"
154-
155-
# Validate critical variables early
156-
test -z "$BUILD_CONFIG" && { echo "ERROR: BUILD_CONFIG is empty!" >&2; exit 1; }
157-
test -z "$PROJECT_ROOT" && { echo "ERROR: PROJECT_ROOT is empty!" >&2; exit 1; }
143+
BUILD_CONFIG="${IOS_BUILD_CONFIG:-Release}"
144+
echo "📲 Building React Native app (${BUILD_CONFIG})"
158145
159146
# Source Metro environment so React Native uses correct port
160147
. ${REACT_NATIVE_VIRTENV}/metro/env-ios.sh
@@ -181,56 +168,29 @@ processes:
181168
182169
if [ -z "$DEVICE_UDID" ]; then
183170
echo "ERROR: No booted simulator found after $max_attempts attempts" >&2
184-
echo "Available devices:" >&2
185171
xcrun simctl list devices >&2
186172
exit 1
187173
fi
188174
189175
echo "Building for simulator: $DEVICE_UDID"
190176
191-
# Build with xcodebuild
192-
# Remove Nix-specific flags that interfere with Apple toolchain
193-
# NODE_BINARY is set by React Native plugin init hook
194-
# Pass RCT_METRO_PORT so the app connects to the correct Metro instance
195-
196-
DERIVED_DATA_PATH="$PROJECT_ROOT/.devbox/virtenv/ios/DerivedData"
197-
echo "Derived data path: $DERIVED_DATA_PATH"
198-
199-
# Ensure the derived data directory exists
200-
mkdir -p "$DERIVED_DATA_PATH"
201-
202-
# Build with xcodebuild in a subshell to preserve variables
203-
(
204-
cd ios
205-
env -u LD -u LDFLAGS -u NIX_LDFLAGS -u NIX_CFLAGS_COMPILE -u NIX_CFLAGS_LINK \
206-
NODE_BINARY="$NODE_BINARY" \
207-
RCT_METRO_PORT="$METRO_PORT" \
208-
xcodebuild \
209-
-workspace ReactNativeExample.xcworkspace \
210-
-scheme ${IOS_APP_SCHEME} \
211-
-configuration "$BUILD_CONFIG" \
212-
-destination "id=$DEVICE_UDID" \
213-
-derivedDataPath "$DERIVED_DATA_PATH" \
214-
-quiet \
215-
build
216-
)
177+
# Build with ios.sh build
178+
NODE_BINARY="$NODE_BINARY" RCT_METRO_PORT="$METRO_PORT" \
179+
ios.sh build --config "$BUILD_CONFIG" --quiet
217180
218181
# Install the built app
219182
echo "Installing app to simulator..."
220-
221-
# Use Release build for E2E tests
222-
APP_PATH="${DEVBOX_PROJECT_ROOT}/.devbox/virtenv/ios/DerivedData/Build/Products/Release-iphonesimulator/ReactNativeExample.app"
183+
APP_PATH="${IOS_DERIVED_DATA_PATH:-${DEVBOX_PROJECT_ROOT}/.devbox/virtenv/ios/DerivedData}/Build/Products/${BUILD_CONFIG}-iphonesimulator/ReactNativeExample.app"
223184
224185
if [ ! -d "$APP_PATH" ]; then
225186
echo "ERROR: App bundle not found at $APP_PATH" >&2
226-
echo "ERROR: Contents of Products directory:" >&2
227-
ls -la "${DEVBOX_PROJECT_ROOT}/.devbox/virtenv/ios/DerivedData/Build/Products/" >&2 || true
187+
ls -la "${IOS_DERIVED_DATA_PATH:-${DEVBOX_PROJECT_ROOT}/.devbox/virtenv/ios/DerivedData}/Build/Products/" >&2 || true
228188
exit 1
229189
fi
230190
231191
xcrun simctl install "$DEVICE_UDID" "$APP_PATH"
232192
233-
# Launch app with Metro port environment variable
193+
# Launch app with Metro port
234194
echo "Launching app with Metro on port $METRO_PORT..."
235195
xcrun simctl launch "$DEVICE_UDID" "${IOS_APP_BUNDLE_ID}" \
236196
RCT_METRO_PORT="$METRO_PORT"

plugins/android/REFERENCE.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Configure the plugin by setting environment variables in `plugin.json`. These ar
2828
- `ANDROID_DEFAULT_DEVICE` — Default device name when none specified
2929
- `ANDROID_SYSTEM_IMAGE_TAG` — System image tag (e.g., "google_apis", "google_apis_playstore")
3030
- `ANDROID_APP_APK` — Path or glob pattern for APK (relative to project root)
31+
- `ANDROID_BUILD_CONFIG` — Build configuration: Debug or Release (default: "Debug")
32+
- `ANDROID_BUILD_TASK` — Gradle task override (empty = auto-derive from config, e.g., assembleDebug)
3133
- `ANDROID_BUILD_TOOLS_VERSION` — Build tools version (e.g., "36.1.0")
3234
- `ANDROID_INCLUDE_NDK` — Include Android NDK in SDK (true/false, default: false)
3335
- `ANDROID_NDK_VERSION` — NDK version when enabled (e.g., "27.0.12077973")
@@ -43,6 +45,49 @@ Configure the plugin by setting environment variables in `plugin.json`. These ar
4345

4446
## Commands
4547

48+
### Build
49+
50+
```bash
51+
android.sh build [--config Debug|Release] [--task gradle_task] [--quiet]
52+
[-- extra_gradle_args...]
53+
```
54+
- Auto-detects Gradle project by looking for `build.gradle`, `build.gradle.kts`, or `settings.gradle`
55+
- Default: runs `gradle assembleDebug` (or `assembleRelease` if `--config Release`)
56+
- Uses `gradlew` if present in the project, otherwise falls back to system `gradle`
57+
58+
**Project detection order:**
59+
1. Current working directory
60+
2. `$DEVBOX_PROJECT_ROOT` (if different)
61+
3. `$PWD/android/` (React Native convention)
62+
4. `$DEVBOX_PROJECT_ROOT/android/` (if different)
63+
64+
**Examples:**
65+
```bash
66+
# Build with defaults (assembleDebug)
67+
android.sh build
68+
69+
# Build Release
70+
android.sh build --config Release
71+
72+
# Custom Gradle task
73+
android.sh build --task bundleRelease
74+
75+
# Pass extra Gradle flags
76+
android.sh build -- --info --stacktrace
77+
```
78+
79+
Use in `devbox.json`:
80+
```json
81+
{
82+
"shell": {
83+
"scripts": {
84+
"build": ["android.sh build"],
85+
"build:release": ["android.sh build --config Release"]
86+
}
87+
}
88+
}
89+
```
90+
4691
### Emulator
4792

4893
- `devbox run --pure android.sh emulator start [--pure] [device]`
@@ -72,7 +117,7 @@ Configure the plugin by setting environment variables in `plugin.json`. These ar
72117
2. Recursive search of project root for `*.apk` files (excludes .gradle/, build/intermediates/, node_modules/, .devbox/)
73118
3. Recursive search of `$PWD` if different from project root (same exclusions)
74119

75-
**Build script detection:** Tries `build:android` first, then falls back to `build`.
120+
**Build script detection:** Tries `build:android` first, then falls back to `build`. If neither script exists, it runs `android.sh build` to auto-detect and build the Gradle project.
76121

77122
### Device management
78123

0 commit comments

Comments
 (0)