Skip to content

fix: duplicate .so resources on cold builds#414

Open
artus9033 wants to merge 2 commits into
mainfrom
fix/duplicate-jni
Open

fix: duplicate .so resources on cold builds#414
artus9033 wants to merge 2 commits into
mainfrom
fix/duplicate-jni

Conversation

@artus9033

Copy link
Copy Markdown
Collaborator

Summary

Fixes a first-run failure when publishing the brownfield AAR (publishToMavenLocal / brownfield publish:android) with Resource and asset merger: Duplicate resources errors for .so files in libsDebug / libsRelease.

Problem

With useStrippedSoFiles enabled (default), native libraries are staged into libs<Variant> (e.g. libsDebug) by copy<Variant>LibSources, and that folder is also registered as a JNI source directory for merge<Variant>JniLibFolders.

On a cold build, Gradle saw the same directory twice in the merge inputs:

  • as a static jniLibs.srcDirs("libsDebug") entry
  • again via mergeJniLibFolders.dependsOn(copyDebugLibSources), which writes to the same path

That produced duplicate-resource errors for every .so file. A second publish often succeeded because the copy task was UP-TO-DATE and the input wiring differed.

Fix

  • RNSourceSets.kt: register JNI libs via project.files(libsDir).builtBy(copy<Variant>LibSources) instead of a static srcDirs(...), matching how Expo updates assets are wired,
  • JNILibsProcessor.kt: remove the redundant dependsOn(copyTask) on mergeJniLibFolders; task ordering is now handled by builtBy.

This ensures libs<Variant> is included once in the JNI merge inputs while preserving the existing copy + copyStrippedSoLibs behavior.

Test plan

CI green.

Copilot AI 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.

Pull request overview

Fixes a first-run AAR publish failure caused by merge<Variant>JniLibFolders seeing duplicate .so resources when useStrippedSoFiles stages native libs into libs<Variant> on cold builds.

Changes:

  • Wire libs<Variant> into sourceSet.jniLibs via a FileCollection that is builtBy(copy<Variant>LibSources) instead of a static srcDirs(...) entry.
  • Remove the redundant dependsOn(copy<Variant>LibSources) from merge<Variant>JniLibFolders configuration so the directory isn’t effectively introduced twice.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/processors/JNILibsProcessor.kt Removes explicit merge-task dependency on the copy task; ordering is now provided via builtBy wiring.
gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/plugin/RNSourceSets.kt Registers libs<Variant> as a JNI libs source through a builtBy(copy<Variant>LibSources) file collection when useStrippedSoFiles is enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants