fix(android): add CMake task dependency to prevent race condition#3165
Conversation
…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>
Summary of ChangesHello, 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
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| 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) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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)
}
}
}
}
}
There was a problem hiding this comment.
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>
📝 WalkthroughWalkthroughAdds 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
Summary
afterEvaluateblock inandroid/build.gradleto ensurebuildCMake*tasks depend onreact-native-nitro-modules' corresponding CMake taskslibNitroModules.sois not yet built when IAP's CMake runsContext
When building with Gradle parallel execution, IAP's
buildCMakeDebug[arm64-v8a]can run beforereact-native-nitro-modulesfinishes producinglibNitroModules.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
--parallelflag🤖 Generated with Claude Code