gpt4 book ai didi

java - Android 应用程序尝试加载我的库文件中链接的 .so

转载 作者:行者123 更新时间:2023-12-02 02:13:18 103 4
gpt4 key购买 nike

这是 Android NDK (20) 用于构建我的项目库的 CMakeLists.txt:

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)

在我的 MainActivity 中,我有

public class MainActivity extends AppCompatActivity {

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

我正在关注谷歌的这个例子:

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

他在其中链接到一些导入的lib文件,然后导入创建的库。

运行应用程序时出现以下错误(崩溃):

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)
...

为什么它试图寻找libavcodec.so

最佳答案

如下所示:https://github.com/googlesamples/android-ndk/blob/master/hello-libs/app/build.gradle#L28

我必须在 gradle 中添加库的路径:

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

它期望找到具有以下结构的文件夹:android_abi/lib1.so, android_abi1/lib2.so,...,android_abi2/lib1.so, android_abi2/lib2.so

关于java - Android 应用程序尝试加载我的库文件中链接的 .so,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57317567/

103 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com