The environment

  • Android Studio 4.1.2
  • Gradle 6.5
  • The NDK 21.1

Exception information

More than one file was found with OS independent path 'lib/{ABI}/xx.so'
Copy the code

Source of problem

  • The old import method, which resulted in multiple SO exceptions being found
  • The reason for this is that the higher Gradle tool automatically imports all files from the default so library path (PS: default so path jniLibs).
  • The following import method causes so duplication
Add_library (XXX SHARED IMPORTED) set_target_properties(XXX PROPERTIES IMPORTED_LOCATION ${so}) target_link_libraries(native-lib xxx)Copy the code

The solution

Add header directories("... Set (CMAKE_CXX_FLAGS "-l ${CMAKE_SOURCE_DIR}/.. Target_link_libraries (native lib log my_util c++_shared)Copy the code
  • Project structure drawing

Running effect

  • Jni interface

  • The results