Android app tries to load .so that is linked in my library file

Here’s the CMakeLists.txt that Android NDK (20) uses to build the library of my project:

cmake_minimum_required(VERSION 3.10.2)

project(orwell)

set(PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../)

set(CMAKE_INCLUDE_CURRENT_DIR ON) # Find includes in corresponding build directories
set(CMAKE_AUTOMOC ON) # Instruct CMake to run moc automatically when needed
set(CMAKE_AUTOUIC ON) # Create code from a list of Qt designer ui files

find_library(log-lib log)

add_subdirectory(${PROJECT_ROOT}/myRtspClient _myRtspClient)
include_directories(${PROJECT_ROOT}/myRtspClient/myRtspClient/include)

file(GLOB LIBORWELL_SRCS "${PROJECT_ROOT}/cpp/common/*" )
include_directories(${PROJECT_ROOT}/cpp/common/ ${PROJECT_ROOT}/cpp/desktop/)

set(FFMPEG_INCLUDE_DIR ${PROJECT_ROOT}/deps/ffmpeg/build/android/${ANDROID_ABI}/include)
include_directories(${FFMPEG_INCLUDE_DIR})
set(FFMPEG_LIB_DIR ${PROJECT_ROOT}/deps/ffmpeg/build/android/${ANDROID_ABI}/lib)

add_library(libavcodec SHARED IMPORTED)
set_target_properties(libavcodec PROPERTIES IMPORTED_LOCATION ${FFMPEG_LIB_DIR}/libavcodec.so)
add_library(libavutil SHARED IMPORTED)
set_target_properties(libavutil PROPERTIES IMPORTED_LOCATION ${FFMPEG_LIB_DIR}/libavutil.so)
add_library(libswscale SHARED IMPORTED)
set_target_properties(libswscale PROPERTIES IMPORTED_LOCATION ${FFMPEG_LIB_DIR}/libswscale.so)
add_library(libswresample SHARED IMPORTED)
set_target_properties(libswresample PROPERTIES IMPORTED_LOCATION ${FFMPEG_LIB_DIR}/libswresample.so)

add_library(orwell SHARED ${LIBORWELL_SRCS})

add_dependencies(orwell myRtspClient libavcodec libavutil libswscale libswresample)

target_link_libraries(orwell android log myRtspClient libavcodec libavutil libswscale libswresample)

And in my MainActivity, I have

public class MainActivity extends AppCompatActivity {

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("orwell");
    }

I’m following this example from google:

CMakeLists.txt: https://github.com/googlesamples/android-ndk/blob/master/hello-libs/app/src/main/cpp/CMakeLists.txt

MainActivity.java: https://github.com/googlesamples/android-ndk/blob/master/hello-libs/app/src/main/java/com/example/hellolibs/MainActivity.java

In which he links to some imported lib files, and then imports the created library.

I’m having the following error when running the app (it crashes):

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.orwellandroid, PID: 6838
    java.lang.UnsatisfiedLinkError: dlopen failed: library "libavcodec.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
        at java.lang.System.loadLibrary(System.java:1657)
    ...

Why is it trying to find libavcodec.so?

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

As seen here: https://github.com/googlesamples/android-ndk/blob/master/hello-libs/app/build.gradle#L28

I had to add the path to the libraries in gradle:

sourceSets {
        main {
            // let gradle pack the shared library into apk
            jniLibs.srcDirs = ['../path/to/libs']
        }
    }

it expects to find a folder with this structure: android_abi/lib1.so, android_abi1/lib2.so,...,android_abi2/lib1.so, android_abi2/lib2.so