3

I was getting the error

More than one file was found with OS independent path 'lib/x86_64/libopencv_java3.so'. If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/studio/preview/features#automatic_packaging_of_prebuilt_dependencies_used_by_cmake

the link takes me to a page with a release notes for android 4.2, so there is nothing pretaining to my problem,

I am using a Documentscanner library buitl with opencv and that uses jnilibs and the problem I have is with that jnilibs

so

I looked through the Android Dev Guide and came across this

Automatic packaging of prebuilt dependencies used by CMake
Prior versions of the Android Gradle Plugin required that you explicitly package any prebuilt libraries used by your CMake external native build by using jniLibs. You may have libraries in the src/main/jniLibs directory of your module, or possibly in some other directory configured in your build.gradle file:

    sourceSets {
        main {
            // The libs directory contains prebuilt libraries that are used by the
            // app's library defined in CMakeLists.txt via an IMPORTED target.
            jniLibs.srcDirs = ['libs']
        }
    }

With Android Gradle Plugin 4.0, the above configuration is no longer necessary and will result in a build failure:

* What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> More than one file was found with OS independent path 'lib/x86/libprebuilt.so'

External native build now automatically packages those libraries, so explicitly packaging the library with jniLibs results in a duplicate. To avoid the build error, move the prebuilt library to a location outside jniLibs or remove the jniLibs configuration from your build.gradle file.

So now after following the above IE Moving the library/ removing from my gradle.build etc. The app builds and starts to install but then I get the error

Installation did not succeed.
The application could not be installed: INSTALL_FAILED_MISSING_SHARED_LIBRARY

Help would be appreciated

peterh
  • 11,875
  • 18
  • 85
  • 108
Ruben Meiring
  • 333
  • 2
  • 21
  • Can you show us the complete build.gradle file and explain how exactly you included and or built the library? If you downloaded stuff, also link to what exactly you downloaded. Also show us the CMakeLists.txt if available – JensV Oct 27 '20 at 11:36
  • Along with the build.gradle show `find` output or a directory structure for your project – spartygw Oct 27 '20 at 13:11
  • You may find interesting this thread: https://stackoverflow.com/questions/62088079/error-when-building-project-with-ndk-support-after-updating-to-android-studio-4 – David Garcìa Oct 27 '20 at 18:03

2 Answers2

0

Please follow this answer.

According to https://developer.android.com/studio/projects/gradle-external-native-builds#jniLibs

If you are using Android Gradle Plugin 4.0, move any libraries that are used by IMPORTED CMake targets out of your jniLibs directory to avoid this error.

So you only need to move the ${ANDROID_ABI}/libdlib.so folder to another place such as creating a new directory name cmakeLibs

eg:

set_target_properties( dlib
    PROPERTIES IMPORTED_LOCATION
    ${CMAKE_SOURCE_DIR}/../cmakeLibs/${ANDROID_ABI}/libdlib.so )

enter image description here

Refer - https://developer.android.com/studio/projects/gradle-external-native-builds#jniLibs

Mayank Kumar Chaudhari
  • 16,027
  • 10
  • 55
  • 122
  • Thanks for you help , but the solution was really easy and forgot to come update the question, I just had to import the latest opencv module and that fixed the error – Ruben Meiring Dec 11 '20 at 06:45
0

I have solved this by importing the latest opencv module manually, the problem was that the opencv included in the library I was using was outdated.

if you get the same error(or I would recomend doing this if you having issues with opencv)

This is how i fixed

Removed all the libraries and modules pertaining to the error(Opencv etc)

Then download openCV android module and import it

then import the library that uses openCV (In my case it was AndroidScannerDemo by jhansireddy on github)

and then lastly Adjust your code to use the library you are using

Ruben Meiring
  • 333
  • 2
  • 21