-
Notifications
You must be signed in to change notification settings - Fork 57
fix(rn_cli_wallet): pin Android NDK version to stop flaky E2E builds #564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ignaciosantise
wants to merge
3
commits into
main
Choose a base branch
from
fix/flaky-android-ci
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Expo config plugin: pins the Android NDK version in the prebuild-generated | ||
| // android/build.gradle so it can't drift from what CI pre-installs. | ||
| // | ||
| // Why: React Native's Android build fetches the NDK on the fly at build time, | ||
| // and that download intermittently lands corrupted on CI runners | ||
| // ("Archive is not a ZIP archive" -> InstallFailedException) — failing the | ||
| // build but passing on rerun. CI works around it by pre-installing the NDK via | ||
| // sdkmanager, which means CI must know the exact version. Expo owns the default | ||
| // (ExpoRootProjectPlugin: `setIfNotExist("ndkVersion") { ... "27.1.12297006" }`) | ||
| // and bumps it on SDK/RN upgrades, so hardcoding it separately in the CI action | ||
| // silently drifted and reintroduced the flaky fetch. | ||
| // | ||
| // This plugin makes app.json the single source of truth: the version passed here | ||
| // ["./plugins/withAndroidNdkVersion.js", { "ndkVersion": "27.1.12297006" }] | ||
| // drives the native build (injected below) AND the CI pre-install (which reads | ||
| // the same app.json entry). Because android/build.gradle sets rootProject.ext | ||
| // .ndkVersion BEFORE `apply plugin: "expo-root-project"`, Expo's setIfNotExist | ||
| // default is a no-op and our value wins — while app/build.gradle keeps reading | ||
| // `ndkVersion rootProject.ext.ndkVersion` unchanged. | ||
| const { withProjectBuildGradle } = require('@expo/config-plugins'); | ||
|
|
||
| const EXPO_ROOT_APPLY = 'apply plugin: "expo-root-project"'; | ||
|
|
||
| function setNdkVersion(buildGradle, ndkVersion) { | ||
| const line = `ext.ndkVersion = "${ndkVersion}"`; | ||
| // Idempotent — prebuild regenerates build.gradle, but guard double application. | ||
| if (buildGradle.includes(line)) { | ||
| return buildGradle; | ||
| } | ||
| if (!buildGradle.includes(EXPO_ROOT_APPLY)) { | ||
| throw new Error( | ||
| `withAndroidNdkVersion: could not find '${EXPO_ROOT_APPLY}' in android/build.gradle`, | ||
| ); | ||
| } | ||
| // Insert before expo-root-project applies so its setIfNotExist("ndkVersion") | ||
| // keeps our value instead of overwriting it with the Expo default. | ||
| return buildGradle.replace(EXPO_ROOT_APPLY, `${line}\n${EXPO_ROOT_APPLY}`); | ||
| } | ||
|
|
||
| const withAndroidNdkVersion = (config, { ndkVersion } = {}) => { | ||
| if (!ndkVersion) { | ||
| throw new Error( | ||
| 'withAndroidNdkVersion: an { ndkVersion } option is required, e.g. ' + | ||
| '["./plugins/withAndroidNdkVersion.js", { "ndkVersion": "27.1.12297006" }]', | ||
| ); | ||
| } | ||
| return withProjectBuildGradle(config, cfg => { | ||
| // Throw rather than silently no-op: if a future Expo SDK generates a Kotlin | ||
| // DSL (build.gradle.kts) root project, skipping would leave the NDK unpinned | ||
| // and quietly reintroduce the corrupt-download flake this plugin prevents. | ||
| if (cfg.modResults.language !== 'groovy') { | ||
| throw new Error( | ||
| `withAndroidNdkVersion: expected a groovy build.gradle, got '${cfg.modResults.language}'. ` + | ||
| 'Update this plugin to support Kotlin DSL (build.gradle.kts).', | ||
| ); | ||
| } | ||
| cfg.modResults.contents = setNdkVersion(cfg.modResults.contents, ndkVersion); | ||
| return cfg; | ||
| }); | ||
| }; | ||
|
|
||
| module.exports = withAndroidNdkVersion; | ||
| // Exported for unit testing the transform in isolation. | ||
| module.exports.setNdkVersion = setNdkVersion; |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.