Skip to content

Duplicate native library during gradlew build: libfbjni.so (with potential fix?) #3705

@shoffing

Description

@shoffing

Description

While trying to get Detox set up with my existing project, I ran into a duplicate native libs issue while detox was attempting to run gradlew:

> Task :app:compileDebugAndroidTestJavaWithJavac
Note: /home/shoffing/projects/grim-sim/android/app/src/androidTest/java/com/shoffing/grimsim/DetoxTest.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

> Task :react-native-gesture-handler:mergeDebugAndroidTestNativeLibs FAILED
w: Detected multiple Kotlin daemon sessions at

[Incubating] Problems report is available at: file:///home/shoffing/projects/grim-sim/android/build/reports/problems/problems-report.html

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-gesture-handler:mergeDebugAndroidTestNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction
   > 2 files found with path 'lib/arm64-v8a/libfbjni.so' from inputs:
      - /home/shoffing/projects/grim-sim/node_modules/react-native-gesture-handler/android/build/intermediates/library_jni/debug/copyDebugJniLibsProjectOnly/jni/arm64-v8a/libfbjni.so
      - /home/shoffing/.gradle/caches/8.13/transforms/24a0799b84a0c73c289e36d2d1d37648/transformed/react-android-0.81.4-debug/jni/arm64-v8a/libfbjni.so
     If you are using jniLibs and CMake IMPORTED targets, see
     https://developer.android.com/r/tools/jniLibs-vs-imported-targets

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.13/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 6m 37s
1523 actionable tasks: 912 executed, 611 up-to-date


Important: 'detox build' is a convenience shortcut for calling your own build command, as provided in the config file.
Failures in this build command are not the responsibility of Detox. You are responsible for maintaining this command.

Command failed: cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug

After a while of troubleshooting, I stumbled upon #3283 by @coado, and was able to fix the issue by doing something similar here - patching node_modules/react-native-gesture-handler/android/build.gradle and adding:

exclude "**/libfbjni.so"

to the bottom of packagingOptions:

    packagingOptions {
        // For some reason gradle only complains about the duplicated version of libreact_render libraries
        // while there are more libraries copied in intermediates folder of the lib build directory, we exclude
        // only the ones that make the build fail (ideally we should only include libgesturehandler but we
        // are only allowed to specify exclude patterns)
        exclude "**/libreact_render*.so"
        exclude "**/libreactnative.so"
        exclude "**/libjsi.so"
        exclude "**/libc++_shared.so"
        exclude "**/libfbjni.so"
    }

Could this be incorporated upstream? I am not entirely sure I understand the implications of doing this, but it seems to have resolved the issue for me.

Steps to reproduce

  1. Have an expo project.
  2. cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug

A link to a Gist, an Expo Snack or a link to a repository based on this template that reproduces the bug.

N/A

Gesture Handler version

2.28.0

React Native version

0.81.4

Platforms

Android

JavaScript runtime

None

Workflow

Using Expo Prebuild or an Expo development build

Architecture

New Architecture (Fabric)

Build type

Debug mode

Device

Android emulator

Device model

No response

Acknowledgements

Yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions