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

54,305

Solution 1

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
}

Solution 2

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

Solution 3

you can use like this:

add the following code into build.gradle ,

packagingOptions {
    pickFirst 'lib/armeabi-v7a/your_name.so'
    pickFirst 'lib/arm64-v8a/your_name.so'
    pickFirst 'lib/x86/your_name.so'
    pickFirst 'lib/x86_64/your_name.so'
}

this pickFirst that means : if more than one path matches the first-pick, only the first found will be selected. please click Get more information

Solution 4

In case of react-native add android/app/build.gradle file into andorid : {.....} section this :

packagingOptions {
    pickFirst 'lib/x86/libc++_shared.so'
    pickFirst 'lib/x86_64/libjsc.so'
    pickFirst 'lib/arm64-v8a/libjsc.so'
    pickFirst 'lib/arm64-v8a/libc++_shared.so'
    pickFirst 'lib/x86_64/libc++_shared.so'
    pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}

then use "gradlew clean"

Solution 5

I've seen a similar error running my app after migration to Android Studio 3.0. A build clean solved the issue.

Share:
54,305
N Sharma
Author by

N Sharma

I have done masters in Advanced Software Engineering. I have worked on various technologies like Java, Android, Design patterns. My research area during my masters is revolving around the Recommendation algorithms that E-commerce websites are using in order to recommend the products to their customers on the basis of their preferences.

Updated on June 02, 2021

Comments

  • N Sharma
    N Sharma almost 3 years

    I am using libusb in my android application. When I am trying to build libusb native library then I get below error message, *.so files generated.

    Error:Execution failed for task ':app:transformNativeLibsWithMergeJniLibsForDebug'. More than one file was found with OS independent path 'lib/x86/libusb.so'

    enter image description here

    build.gradle

    import org.apache.tools.ant.taskdefs.condition.Os
    
    apply plugin: 'com.android.application'
    
    apply plugin: 'kotlin-android'
    
    apply plugin: 'kotlin-android-extensions'
    
    android {
        compileSdkVersion 26
        buildToolsVersion "26.0.0"
        defaultConfig {
            applicationId "com.williams.libusbpoc"
            minSdkVersion 21
            targetSdkVersion 26
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        externalNativeBuild {
            ndkBuild {
                path 'src/main/jni/Android.mk'
            }
        }
    
        sourceSets.main {
            jniLibs.srcDir 'src/main/libs'
            jni.srcDirs = [] //disable automatic ndk-build call
        }
    
        // call regular ndk-build(.cmd) script from app directory
        task ndkBuild(type: Exec) {
            if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
            } else {
                commandLine 'ndk-build', '-C', file('src/main').absolutePath
            }
        }
    
        tasks.withType(JavaCompile) {
            compileTask -> compileTask.dependsOn ndkBuild
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        androidTestImplementation ('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
        implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
        testImplementation 'junit:junit:4.12'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        compile "org.jetbrains.anko:anko-appcompat-v7-commons:$anko_version"
    }
    

    I am on windows machine. Does anyone know what could be the issue ?

  • Paamand
    Paamand about 6 years
    Did not work for me: Error:(25, 1) A problem occurred evaluating project ':app'. > Cannot cast object 'src/main/jni/lib' with class 'java.lang.String' to class 'java.lang.Iterable'
  • easy_breezy
    easy_breezy almost 4 years
    Thanks it worked for me with Android Studio 4.0.1 and NDK version 21.3.6528147
  • Summer Sun
    Summer Sun about 3 years
    it seems in old gradle version srcDirs is mandatory if you want to pack so into apk
  • Amin Keshavarzian
    Amin Keshavarzian about 3 years
    also worked for a non react problem, thanks
  • hong developer
    hong developer over 2 years
    Where do I execute this command?
  • Muhammad Rafeh Atique
    Muhammad Rafeh Atique over 2 years
    after it I am unable to assemble Debug apk. Means When I assembles debug. its generate apk which is not a debug apk
  • Michael N
    Michael N over 2 years
    Thanks! This helped a lot with FFMPEG.
  • Aviraj Patel
    Aviraj Patel about 2 years
    worked for flutter-android studio too.
  • Qinghua
    Qinghua about 2 years
    clean build folder fixed
  • Naruto Uzumaki
    Naruto Uzumaki almost 2 years
    For react native 0.67 this solution worked, for 0.68 it didn't