Skip to content
This repository was archived by the owner on Apr 26, 2026. It is now read-only.

fix(android): add CMake task dependency to prevent race condition#3165

Merged
hyochan merged 2 commits into
mainfrom
fix/cmake-race-condition-3163
Mar 10, 2026
Merged

fix(android): add CMake task dependency to prevent race condition#3165
hyochan merged 2 commits into
mainfrom
fix/cmake-race-condition-3163

Conversation

@hyochan

@hyochan hyochan commented Mar 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add afterEvaluate block in android/build.gradle to ensure buildCMake* tasks depend on react-native-nitro-modules' corresponding CMake tasks
  • Prevents intermittent linker error where libNitroModules.so is not yet built when IAP's CMake runs

Context

When building with Gradle parallel execution, IAP's buildCMakeDebug[arm64-v8a] can run before react-native-nitro-modules finishes producing libNitroModules.so, causing a linker failure. This was a latent race condition that became more visible after the nitro-modules 0.35.0 upgrade (JNI initialization pattern change).

Investigated upstream nitro 0.35.0 — no CMake/Gradle build order changes were made, confirming this is a pre-existing issue.

Closes #3163

Test plan

  • Android build succeeds with --parallel flag
  • No regression on iOS build (android-only change, no iOS impact)

🤖 Generated with Claude Code

…ace condition

Ensure buildCMake* tasks depend on the corresponding
react-native-nitro-modules tasks so libNitroModules.so is
available before linking.

Closes #3163

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical build stability issue on Android by resolving a race condition in the Gradle build process. The changes ensure that shared libraries are correctly built and available when needed, leading to more reliable and consistent builds, especially when parallel execution is enabled.

Highlights

  • Build Race Condition Fix: Implemented a fix for an intermittent linker error on Android builds by ensuring that the project's CMake tasks (buildCMake*) explicitly depend on the corresponding CMake tasks from react-native-nitro-modules.
  • Gradle Configuration Update: Added an afterEvaluate block to android/build.gradle to dynamically configure task dependencies, preventing a race condition where libNitroModules.so might not be built before IAP's CMake process runs.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • android/build.gradle
    • Added an afterEvaluate block to enforce task dependencies between the project's CMake build tasks and those of react-native-nitro-modules.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a race condition in the Android build process by ensuring that the IAP module's CMake tasks run after the react-native-nitro-modules's CMake tasks. The approach of using an afterEvaluate block to add a dependsOn relationship is sound. I've suggested a small performance improvement to the Gradle script to avoid redundant project lookups during the configuration phase, making the build slightly more efficient.

Comment thread android/build.gradle
Comment on lines +211 to +223
afterEvaluate {
tasks.configureEach { task ->
if (task.name.startsWith('buildCMake')) {
def nitroProject = rootProject.findProject(':react-native-nitro-modules')
if (nitroProject) {
def nitroTask = nitroProject.tasks.findByName(task.name)
if (nitroTask) {
task.dependsOn(nitroTask)
}
}
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better build performance, it's more efficient to find the :react-native-nitro-modules project only once, outside the tasks.configureEach loop. The current implementation looks for the project for every task being configured, which is unnecessary and can slightly slow down Gradle's configuration phase, especially in larger projects.

afterEvaluate {
  def nitroProject = rootProject.findProject(':react-native-nitro-modules')
  if (nitroProject) {
    tasks.configureEach { task ->
      if (task.name.startsWith('buildCMake')) {
        def nitroTask = nitroProject.tasks.findByName(task.name)
        if (nitroTask) {
          task.dependsOn(nitroTask)
        }
      }
    }
  }
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point — hoisted findProject outside the configureEach loop in aa8e254.

Move nitroProject lookup before the task loop to avoid
redundant lookups on every configured task.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Mar 10, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds a post-evaluation block to Android's build.gradle that establishes task dependencies between CMake build tasks and corresponding react-native-nitro-modules tasks, ensuring the Nitro CMake task completes before the local CMake task begins, preventing potential race conditions during the build process.

Changes

Cohort / File(s) Summary
Android CMake Task Synchronization
android/build.gradle
Added afterEvaluate block that iterates all tasks and establishes dependencies for buildCMake tasks with their corresponding react-native-nitro-modules tasks to prevent race conditions where libNitroModules.so may not be built yet.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A race condition once plagued the build,
CMake tasks, so eager and wild,
But now with dependencies neat,
The nitro modules complete their feat,
Before the local tasks run free—
No more missing .so, happy as can be! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding CMake task dependencies to fix a race condition in the Android build process.
Linked Issues check ✅ Passed The PR implementation matches all objectives from #3163: it adds afterEvaluate logic to android/build.gradle that establishes dependencies between buildCMake* tasks and corresponding react-native-nitro-modules tasks to prevent the libNitroModules.so race condition.
Out of Scope Changes check ✅ Passed All changes are scoped to the stated objective of fixing the CMake task race condition; the modification is limited to android/build.gradle with no unrelated alterations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/cmake-race-condition-3163

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@hyochan hyochan added 🤖 android Related to android 🛠 bugfix All kinds of bug fixes labels Mar 10, 2026
@hyochan hyochan merged commit e3e3816 into main Mar 10, 2026
3 of 4 checks passed
@hyochan hyochan deleted the fix/cmake-race-condition-3163 branch March 10, 2026 20:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

🤖 android Related to android 🛠 bugfix All kinds of bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] buildCMakeDebug race condition: libNitroModules.so not found

1 participant