Skip to content

fix(android): use Gradle metadata to select install APKs - #2868

Open
huytdps13400 wants to merge 1 commit into
react-native-community:mainfrom
huytdps13400:fix/android-apk-output-metadata
Open

huytdps13400 wants to merge 1 commit into
react-native-community:mainfrom
huytdps13400:fix/android-apk-output-metadata

Conversation

@huytdps13400

Copy link
Copy Markdown

Summary

Fixes #2851. For a single flavor named clientStaging, Gradle writes app-clientStaging-debug.apk; the CLI's capital-letter split guesses app-client-staging-debug.apk. The same combined variant can also represent two dimensions, whose real filename is the hyphenated one.

Consult output-metadata.json in the resolved variant directory before guessing a filename. Prefer an existing ABI output in device CPU order, then an unfiltered output. Malformed/unusable metadata or missing files retain the previous filename fallback. Unsupported split filters are not treated as universal APKs. Explicit --binary-path behavior is unchanged.

This follows the metadata approach investigated in #2851 and the self-closed, unmerged #2853. No equivalent PR is currently open. #2834's task/directory casing changes are separate and are not duplicated here.

Test Plan

  • Added 18 tests using real temporary directories and a mocked ADB boundary: ambiguous single/multi-dimension names, custom filenames, user 0, ABI preference, absent preferred files, unfiltered output, malformed metadata/filters, existing filename fallback and explicit binary paths. Base: 6 fail / 12 pass; patched: all 18 pass.
  • Android command tests: 5 suites / 35 tests pass. Full unit project: 57 suites, 343 tests pass, 1 existing todo, 64 snapshots pass. TypeScript declarations, Babel build and full lint pass (2 warnings in unchanged files).
  • Built real APKs with AGP 8.9.2, Gradle 8.11.1, SDK 35 and JDK 21. On a task-owned Android 15/API 35 arm64 emulator, the original compiled installer fails for the single camelCase flavor and its ABI-split variant; multidimension and plain-debug controls pass. The patched installer installs all 4 cases. Selected host APK hashes match installed APK hashes, and the ABI case picks the arm64 output even when universal/x86 entries occur first in metadata.
  • Invoked the public CLI from this source checkout in a consumer with real RN 0.81.6 / React 19.1.4 dependencies and local CLI commands/configuration:
    node /path/to/cli/packages/cli/build/bin.js run-android \
      --mode clientStagingDebug --device emulator-5556 --no-packager --port 8089 \
      --extra-params '--no-daemon --console=plain --max-workers=2'
    With the original installer, Gradle succeeds and installation fails with Could not find the correct install APK file (exit 1). Restoring the patch installs and launches the app (exit 0); the installed APK hash matches the Gradle output. The fixture Activity is Java, so this verifies the CLI pipeline, not a React Native JS UI or Metro runtime.

No physical-device or Windows runtime verification is claimed. Interactive task/directory resolution is not changed by this patch.

Checklist

  • Documentation is up to date (no new public option).
  • Follows commit message convention described in CONTRIBUTING.md.
  • For functional changes, the test plan invokes these CLI changes from source in a local React Native consumer as described above.

A camelCase flavor cannot be distinguished from multiple flavor dimensions
by splitting capital letters. Prefer existing outputs recorded by AGP,
respect device ABI order, and retain filename guesses as a fallback.

Add regression tests for flavor ambiguity, custom filenames, ABI preference,
invalid metadata, missing artifacts and explicit binary paths.

Fixes react-native-community#2851.
@github-actions github-actions Bot added the bugfix label Oct 5, 2026
@huytdps13400
huytdps13400 force-pushed the fix/android-apk-output-metadata branch from 7539dc8 to 3358636 Compare October 5, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

run-android: "Could not find the correct install APK file" for single-dimension camelCase product flavors when targeting a specific device

1 participant