4

I have an application that uses OpenCV 3.1. I copied lib_opencv_java.so file into jniLibs folder. Now I want to integrate a new sdk into my app but this SDK also uses a different version of OpenCV. SDK OpenCV lib's added with Gradle, not copied to jni folder. When I build application it's giving an error on compilation time:

More than one file was found with OS independent path 'lib/arm64-v8a/libopencv_java3.so'

For solving this issue I renamed my OpenCV and regenerated .so file with different name. After that, it did not give above issue, but when I try to open my activity that uses OpenCV. The application crashed with below error:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol “_ZN2cv7imwriteERKNS_6StringERKNS_11_InputArrayERKSt6vectorIiSaIiEE” referenced by “/data/app/io.xxxxxx-gilxH9B4dAHGtuXtU4Sl6Q==/lib/arm64/libProcess.so”.

shizhen
  • 12,251
  • 9
  • 52
  • 88
  • 2
    Size matters. Your users won't be happy to find your app has grown few megabytes just to store two versions of an so. It should not be very hard to bring both libraries to use one version of OpenCv. – Alex Cohn Jan 31 '19 at 05:46
  • yeah, apk size will increase. But why I wanted to keep both libraries is that I didn't want depend on third party sdk's opencv version. Thanks, I'll try to use the same one. – Murodjon Abdukholikov Feb 01 '19 at 00:42

1 Answers1

6

To properly get rid of below error:

More than one file was found with OS independent path 'lib/arm64-v8a/libopencv_java3.so'

You should use below code inside your app/build.gradle

android{
    ...        
    packagingOptions {
        pickFirst 'lib/x86_64/libopencv_java3.so'
        pickFirst 'lib/x86/libopencv_java3.so'
        pickFirst 'lib/arm64-v8a/libopencv_java3.so'
        pickFirst 'lib/armeabi-v7a/libopencv_java3.so'
    }
    ...
}
shizhen
  • 12,251
  • 9
  • 52
  • 88
  • Thanks for your answer. I don't have any problems with configuring android processor architecture libs. It worked for me also. But what I wanted to resolve is that if I have 2 versions of opencv in the project. As Alex Cohn commented, I'll try to apply one for both third party lib and my image processing algorithm. – Murodjon Abdukholikov Feb 01 '19 at 00:49
  • There is no need to include TWO versions of the same .so libs, as this duplicate will increase your final apk size quite a lot. Renaming either one is not a proper solution. My answer is to let gradle only pick up one version of the libs when packaging your apk – shizhen Feb 01 '19 at 01:08
  • Or what is simpler is to remove the opencv version from the third party and include your own. But just be careful about the library version compatibility. – shizhen Feb 01 '19 at 01:13