More than one file was found with OS independent path 'lib/x86/libusb.so'

I removed jniLibs.srcDir 'src/main/libs' code inside sourceSets.main block. It was creating *.so files twice.

sourceSets.main {
    jniLibs.srcDir 'src/main/libs'
    jni.srcDirs = [] //disable automatic ndk-build call
}

I was having this issue in my React-Native Bridge project after I added AAR files of 3rd party SDK. And I was linking the Bridge into my Main React-native application.

Solution (May differ for you):

Add this in app/build.gradle the Main React-Native application:

android {
    // ...
    packagingOptions {
        pickFirst '**/*.so'
    }
}
  • Test the Build on React-Native Bridge project after adding the AAR libraries.
  • Clean the React-Native Bridge project
  • Clean the React-Native application project
  • Remove node_modules and re-install the bridge package into the project.
  • Run the application.

I faced another issue related to this (If you include AAR into library project that's not being linked to main application)

https://stackoverflow.com/a/58588503/3197778