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

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

Closed

Description

@jslok

When building for Android, the build intermittently fails with a linker error because IAP's buildCMakeDebug[arm64-v8a] task runs before react-native-nitro-modules has finished producing libNitroModules.so.

This fixed it for me. Add to android/build.gradle in react-native-iap:

  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)
                  }
              }
          }
      }
  }

I have several nitro modules in my project. I am not sure why IAP is the only one with this issue.

Activity

  1. gitdogbot commented on Mar 9, 2026

    @gitdogbot

    @jslok Thanks for the detailed report and the proposed fix! 👍

    What I found: I searched the repository for android/build.gradle, buildCMake, afterEvaluate, libNitroModules, and externalNativeBuild. The android/build.gradle file is referenced in CONTRIBUTING.md (line 158) as the file that "triggers the native C++ build (via CMake/externalNativeBuild)", but the file itself is not accessible in the current codebase snapshot — so I cannot confirm or deny whether the afterEvaluate block is already present.

    The proposed fix looks reasonable for a Nitro Modules-based library:

    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)
                    }
                }
            }
        }
    }

    This should be added to android/build.gradle in the library root.

    A few questions for the maintainers:

    1. Is android/build.gradle intentionally excluded from the repo (generated by Nitrogen)? If so, this fix may need to go into the Nitrogen template or a custom gradle script.
    2. Is this reproducible only with parallel Gradle builds (--parallel)? That would help confirm the ordering issue.
    3. Other Nitro modules in the user's project don't hit this — could there be something specific about how IAP's CMake target links against libNitroModules.so compared to other Nitro modules?

    Maintainers: please check android/build.gradle and confirm whether the afterEvaluate task dependency block is missing.


    🤖 Generated by gitdog.dev · Have more questions? Tag @gitdog and let me know!

  2. added a commit that references this issue on Mar 10, 2026
    1f68121
  3. hyochan commented on Mar 10, 2026

    @hyochan
    Owner

    Thanks for the report and the fix suggestion @jslok!

    This has been merged in #3165. The afterEvaluate block now ensures buildCMake* tasks depend on the corresponding react-native-nitro-modules tasks.

    We investigated the nitro-modules 0.35.0 upgrade — no CMake/Gradle build order changes were made upstream, so this was a pre-existing race condition that likely became more visible with the recent upgrade.

    Will be included in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working🤖 androidRelated to android

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions