Skip to content

Commit b4c64cc

Browse files
abueideclaude
andcommitted
fix(rn): add ADB reverse port forwarding for Metro connection
React Native Android apps connect to localhost:8081 by default, but Metro runs on a dynamically allocated port (e.g., 8091). Add ADB reverse port forwarding before deployment so the app can reach Metro: adb reverse tcp:8081 tcp:$METRO_PORT This fixes the "Unable to load script" error shown in the app. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 304d1c9 commit b4c64cc

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ processes:
141141
. ${REACT_NATIVE_VIRTENV}/metro/env-all.sh
142142
echo "Metro port: $METRO_PORT"
143143
144+
# Setup ADB reverse port forwarding so app can reach Metro
145+
# React Native apps connect to localhost:8081 by default, forward to actual Metro port
146+
serial=""
147+
state_dir="${ANDROID_RUNTIME_DIR:-.devbox/virtenv}/${SUITE_NAME:-default}"
148+
if [ -f "$state_dir/emulator-serial.txt" ]; then
149+
serial="$(cat "$state_dir/emulator-serial.txt")"
150+
fi
151+
if [ -z "$serial" ]; then
152+
serial="emulator-${EMU_PORT:-5554}"
153+
fi
154+
155+
echo "Setting up Metro port forwarding: 8081 -> $METRO_PORT (serial: $serial)"
156+
adb -s "$serial" reverse tcp:8081 tcp:$METRO_PORT
157+
144158
# Deploy using android.sh (APK already built by build-android)
145159
android.sh deploy
146160
depends_on:

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ processes:
9494
. ${REACT_NATIVE_VIRTENV}/metro/env-android.sh
9595
echo "Metro port: $METRO_PORT"
9696
97+
# Setup ADB reverse port forwarding so app can reach Metro
98+
# React Native apps connect to localhost:8081 by default, forward to actual Metro port
99+
serial=""
100+
state_dir="${ANDROID_RUNTIME_DIR:-.devbox/virtenv}/${SUITE_NAME:-default}"
101+
if [ -f "$state_dir/emulator-serial.txt" ]; then
102+
serial="$(cat "$state_dir/emulator-serial.txt")"
103+
fi
104+
if [ -z "$serial" ]; then
105+
serial="emulator-${EMU_PORT:-5554}"
106+
fi
107+
108+
echo "Setting up Metro port forwarding: 8081 -> $METRO_PORT (serial: $serial)"
109+
adb -s "$serial" reverse tcp:8081 tcp:$METRO_PORT
110+
97111
# Deploy using android.sh (APK already built by build-android)
98112
android.sh deploy
99113
depends_on:

0 commit comments

Comments
 (0)