Skip to content

Build Failure: Duplicate Resources Error During AAR Packaging with React Native Libraries #125

Closed

Description

@hidaeraldo

I'm experiencing a build failure when trying to create an AAR file using the React Native Brownfield plugin. The build process fails with a "Duplicate resources" error during the packageDebugResources task.

Error Details:
Execution failed for task ':rnbrownfieldLibrary:packageDebugResources'.

[color/red] */brownfield-test/react-native-brownfield/android/rnbrownfieldLibrary/build/intermediates/exploded-aar/rnbrownfield/react-native-video/unspecified/debug/res/values/values.xml
[color/red] */brownfield-test/react-native-brownfield/android/rnbrownfieldLibrary/build/intermediates/exploded-aar/rnbrownfield/react-native-firebase_messaging/unspecified/debug/res/values/values.xml: Error: Duplicate resources

Environment:

  • React Native Brownfield Plugin: @callstack/react-native-brownfield@^1.2.0
  • React Native Version: 0.77.2
  • Android Compile SDK: 35
  • Min SDK: 24
  • Build Tool: Gradle with Kotlin DSL

Steps to Reproduce:

  1. Clone this example repo https://github.com/hidaeraldo/brownfield-test
  2. cd react-native-brownfield folder
  3. Install react-native-video and @react-native-firebase/messaging as dependencies
  4. Attempt to build the AAR file using ./gradlew publishToMavenLocal or similar command
  5. Build fails during the packageDebugResources task

Current Configuration:
The issue occurs in the rnbrownfieldLibrary module with the following build.gradle.kts configuration:

plugins {
    id("com.android.library")
    id("org.jetbrains.kotlin.android")
    id("com.facebook.react")
    id("com.callstack.react.brownfield")
    `maven-publish`
}

react {
    autolinkLibrariesWithApp()
}

Dependencies Involved:

  • react-native-video: ^6.16.1
  • @react-native-firebase/messaging: ^21.4.1

Actual Behavior:
Build fails with duplicate resources error, preventing the AAR from being generated.

Workaround Attempts:

  • Tried adding resource exclusions in the packaging block but the issue persists
  • The error occurs even with the default autolinking configuration

Activity

  1. hurali97 commented on Aug 21, 2025

    @hurali97
    Member

    Thanks for raising this. I will look into this over a few days 👍

  2. self-assigned this
    on Aug 21, 2025
  3. VigneshPandianB25 commented on Sep 20, 2025

    @VigneshPandianB25

    packaging {
    jniLibs {
    if (!hermesEnabled) {
    excludes += "lib/x86/libjsctooling.so"
    excludes += "lib/x86_64/libjsctooling.so"
    excludes += "lib/armeabi-v7a/libjsctooling.so"
    excludes += "lib/arm64-v8a/libjsctooling.so"
    }

            // Pick first libworklets.so to resolve conflicts between
            // react-native-reanimated and react-native-worklets
            pickFirsts += "lib/armeabi-v7a/libworklets.so"
            pickFirsts += "lib/arm64-v8a/libworklets.so"
            pickFirsts += "lib/x86/libworklets.so"
            pickFirsts += "lib/x86_64/libworklets.so"
        }
    }
    

    in your build.gradle.kts add inside android
    then add below code as your library name publishing inside
    afterEvaluate {
    listOf("mergeReleaseJniLibFolders", "mergeDebugJniLibFolders").forEach { taskName ->
    tasks.named(taskName) {
    doFirst {
    // Remove duplicate libworklets.so from react-native-worklets to avoid conflicts
    // with react-native-reanimated which also provides the same library
    fileTree("$buildDir/intermediates/exploded-aar/Loyalty_Cobrand/react-native-worklets") {
    include("/jni//libworklets.so")
    }.forEach { file ->
    println("Removing duplicate libworklets.so: ${file.path}")
    file.delete()
    }
    }
    }
    }
    }

  4. added
    bug
    on Mar 31, 2026
  5. marcinszalski-callstack commented on Apr 2, 2026

    @marcinszalski-callstack
    Contributor

    @hidaeraldo

    would it help if you'd add the following snippet into .../apps/RNApp/android/BrownfieldLib/build.gradle.kts:

    afterEvaluate {
        tasks.matching { it.name.startsWith("package") && it.name.endsWith("Resources") }.configureEach {
            doFirst {
                val buildDir = layout.buildDirectory.get().asFile
                val firebaseValuesFiles = fileTree("$buildDir/intermediates/exploded-aar") {
                    include("**/react-native-firebase_messaging/**/res/values/values.xml")
                }.files
    
                firebaseValuesFiles.forEach { file ->
                    if (file.exists()) {
                        println("Removing duplicate colors from: ${file.absolutePath}")
                        var content = file.readText()
    
                        content = content.replace(Regex("<color\\s+name=\"red\">[^<]*</color>"), "")
                        content = content.replace(Regex("<color\\s+name=\"white\">[^<]*</color>"), "")
    
                        file.writeText(content)
                    }
                }
            }
        }
    }
    
  6. marcin-szalski-ridelink commented on May 14, 2026

    @marcin-szalski-ridelink

    no updates here for more than 5 weeks already, @artus9033

  7. artus9033 commented on May 14, 2026

    @artus9033
    Collaborator

    Thanks @marcinszalski-callstack . @hidaeraldo , we couldn't reproduce the issue on our end and since we don't have any reports of it in the newest version, I'll close this one. In case something new would pop out, please let us know.

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

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions