run-android fails with "No connected devices!" on a cold-booting emulator (waits for adb, not for sys.boot_completed)
Mantenedores costumam responder em até 2 dias
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 72/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Pouca atividade
- Stack de tecnologia
- android, react-native, typescript
- Domínio
- cli, mobile-dev
Direção de pesquisa
Comece em packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts e inspecione a verificação de prontidão do adb em launchEmulator e seu timeout de 30 segundos. Reproduza o tempo de cold boot com os comandos do emulador e do adb indicados na issue. A tarefa estará concluída quando run-android aguardar sys.boot_completed e permitir tempo suficiente para o framework iniciar, sem causar uma instalação prematura do Gradle ou timeouts espúrios.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Environment
npx react-native info is not representative here (pnpm monorepo), so the relevant
versions collected by hand:
System:
OS: macOS 26.5.2 (25F84)
Node: 24.15.0
Java: openjdk 17.0.20 2026-07-21 LTS
SDKs:
Android SDK Platform-Tools: 37.0.0 (adb 1.0.41)
Android Emulator: 36.6.11.0 (build_id 15507667)
npmPackages:
react-native: 0.86.0
@react-native-community/cli: 20.1.0
@react-native-community/cli-platform-android: 20.1.0
Also reproduces against main — tryLaunchEmulator.ts is unchanged since
2514405b (Apr 2024), and the two relevant lines are identical in v20.2.0.
Description
When run-android has to launch the emulator itself, and that emulator does a
genuine cold boot (no quick-boot snapshot — a fresh AVD, an AVD whose
snapshot was invalidated, -no-snapshot-load, or CI), the build fails:
error Failed to install the app. Command failed with exit code 1: ./gradlew app:installDevDebug …
com.android.builder.testing.api.DeviceException: No connected devices!
with Gradle having logged Device is still booting just before.
Root cause
launchEmulator in
packages/cli-platform-android/src/commands/runAndroid/tryLaunchEmulator.ts
treats the emulator as ready the moment adb devices lists it:
const bootCheckInterval = setInterval(async () => {
const devices = adb.getDevices(adbPath);
const connected = port
? devices.find((d) => d.includes(`${port}`))
: devices.length > 0;
if (connected) {
cleanup();
resolve(true); // ← too early
}
}, 1000);
adb.getDevices only keeps devices whose state is device
(adb.ts#L25),
which is an honest signal — but it is a signal about adbd, not about the
Android framework. adbd starts early in boot; ActivityManager finishes much
later. run-android therefore resolves, hands off to Gradle, and Gradle's
install task refuses a device that is still booting.
Measurements
Timing one cold boot on the machine above (AVD launched at t=0):
| Event | t |
|---|---|
adb devices first reports state device |
9.3 s |
getprop sys.boot_completed first returns 1 |
20.2 s |
That is a ~10.9 s window in which the current check is satisfied and the
device cannot actually be installed to. Anything that fits inside that window —
Gradle configuration being warm, a cached build — loses the race. Anything that
takes longer than 10.9 s (a cold Gradle daemon, a first build) accidentally
survives it, which is why this is so often written off as flaky.
Suggested fix
Gate on sys.boot_completed, which is set once ActivityManager has finished
starting and is therefore a strictly later — and safe — signal:
adb -s <serial> shell getprop sys.boot_completed
One consequence worth calling out: with that gate in place the existing
timeout = 30 no longer budgets for "adb answers", it budgets for "the whole
framework is up". On this machine that is 20.2 s of the 30 s, leaving ~10 s of
headroom; slower hardware and CI runners exceed it routinely. The timeout needs
to grow alongside the gate, otherwise the fix converts a wrong-success into a
spurious timeout.
I have this running as a local patch and can open a PR — say the word and I'll
send it. (Happy to make the timeout a flag instead of a constant if you'd
prefer that shape.)
Reproducible Demo
npx @react-native-community/cli init BootRace --version 0.86.0
cd BootRace
# make sure no emulator is running, and force a true cold boot
adb devices # expect: empty
emulator -list-avds # pick one, then wipe its snapshot:
emulator @<avd> -no-snapshot-save -wipe-data & # let it boot once, then kill it
npx react-native run-android
The failure is timing-sensitive by nature. To see the window directly, without
building anything:
emulator @<avd> -no-snapshot-load &
START=$(date +%s)
while ! adb devices | grep -q "device$"; do sleep 0.1; done
echo "adb says 'device' after $(( $(date +%s) - START ))s"
while [ "$(adb shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" != "1" ]; do sleep 0.1; done
echo "sys.boot_completed after $(( $(date +%s) - START ))s"
Every second between those two lines is a second in which run-android believes
the emulator is ready and Gradle disagrees.
- Linguagem predominante
- TypeScript
- Estrelas
- 2.9k
- Forks
- 951
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de react-native-community/cli
-
run-ios --udid <physical device> throws "No simulator available" because the fallback simulator is resolved eagerlyTalvez já em andamento @huytdps13400 assumiu há 52 dias. Abertabug report
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
react-native-community/cli#2826 ·
Mantenedores costumam responder em até 2 dias
-
`project.ios.automaticPodsInstallation` default of `true` never applies unless `project.ios` is explicitly declared in `react-native.config.js`Talvez já em andamento @huytdps13400 assumiu há 52 dias. Abertabug report
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
react-native-community/cli#2825 ·
Mantenedores costumam responder em até 2 dias
-
run-ios: "Unable to boot device in current state: Booted" alert when the simulator is already bootedTalvez já em andamento @bryandent assumiu há 96 dias. Abertastale
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
react-native-community/cli#2820 · 1 comentário ·
Mantenedores costumam responder em até 2 dias
-
run-ios --buildFolder installs the app from the default DerivedData instead of the build folderTalvez já em andamento @lovisschmidt assumiu há 12 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
react-native-community/cli#2869 ·
Mantenedores costumam responder em até 2 dias
-
run-ios on Xcode 27: DeviceHub opens no window when the simulator is shut downTalvez já em andamento @rakodev assumiu há 13 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 25/100
react-native-community/cli#2866 · 2 comentários ·
Mantenedores costumam responder em até 2 dias
Todas as issues de react-native-community/cli
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
umami-software/umami#4637 ·
Mantenedores costumam responder em até 3 dias
-
Hotkeys fire when pressed with the Ctrl key, so browser shortcuts also trigger player actionsTalvez já em andamento @RaphaelFakhri assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
muxinc/media-chrome#1332 ·
Mantenedores costumam responder em até 5 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
polarsource/polar#15580 ·
Mantenedores costumam responder em até 1 dia
-
accepted bug via-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 69/100
pingdotgg/t3code#20931 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
bug/1-unconfirmed kind/bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia