android - 'imported-lib - NOTFOUND' 在为 android studio 2.2 构建 ffmpeg 3.2

标签 android ffmpeg cmake

我正在尝试为 Android 构建和使用 ffmpeg。我的Andoid Studio版本是2.2.2,ffmpeg是3.2。按照有关如何导入重建库的 Android 文档,我认为我的设置正确但一直出现此错误

ninja: error: 'avcodec-NOTFOUND', needed by '../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/...

这是设置

add_library( avcodec SHARED IMPORTED )
add_library( avdevice SHARED IMPORTED )
add_library( avfilter SHARED IMPORTED )
add_library( avformat SHARED IMPORTED )
add_library( avutil SHARED IMPORTED )
add_library( swscale SHARED IMPORTED )

set_target_properties( avcodec
                        PROPERTIES FFMPEG_LIB_IMPORTED_LOCATION
                        libs/ffmpeg/${ANDROID_ABI}/lib/libavcodec.so
                        )
set_target_properties(  avdevice
                        PROPERTIES FFMPEG_LIB_IMPORTED_LOCATION
                        libs/ffmpeg/${ANDROID_ABI}/lib/libavdevice.so
                        )
set_target_properties( avfilter
                        PROPERTIES FFMPEG_LIB_IMPORTED_LOCATION
                        libs/ffmpeg/${ANDROID_ABI}/lib/libavfilter.so
                        )
set_target_properties( avformat
                        PROPERTIES FFMPEG_LIB_IMPORTED_LOCATION
                        libs/ffmpeg/${ANDROID_ABI}/lib/libavformat.so
                        )
set_target_properties( avutil
                        PROPERTIES FFMPEG_LIB_IMPORTED_LOCATION
                        libs/ffmpeg/${ANDROID_ABI}/lib/libavutil.so
                        )
set_target_properties( swscale
                        PROPERTIES FFMPEG_LIB_IMPORTED_LOCATION
                        libs/ffmpeg/${ANDROID_ABI}/lib/libswscale.so
                        )

# Specifies a path to native header files.
include_directories(
                    libs/ffmpeg/${ANDROID_ABI}/include
                    )

target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       avcodec avdevice avfilter avformat avutil swscale
                       ${log-lib}
                        )

如果我指定完整的库名称 libavcodec.so...,错误就会消失。

target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       libavcodec.so libavdevice.so libavfilter.so libavformat.so libavutil.so libswscale.so
                       ${log-lib}
                        )

我想知道是否有人遇到过类似的问题或知道为什么编译会这样。

最佳答案

根据 Tsyvarev 的输入,我在此处编译和链接的内容。

add_library( avcodec SHARED IMPORTED )
add_library( avdevice SHARED IMPORTED )
add_library( avfilter SHARED IMPORTED )
add_library( avformat SHARED IMPORTED )
add_library( avutil SHARED IMPORTED )
add_library( swscale SHARED IMPORTED )

set_target_properties( avcodec
                        PROPERTIES IMPORTED_LOCATION
                        ../../../../libs/${ANDROID_ABI}/lib/libavcodec.so
                        )
set_target_properties(  avdevice
                        PROPERTIES IMPORTED_LOCATION
                      ../../../../libs/${ANDROID_ABI}/lib/libavdevice.so
                        )
set_target_properties( avfilter
                        PROPERTIES IMPORTED_LOCATION
                        ../../../..//libs/${ANDROID_ABI}/lib/libavfilter.so
                        )
set_target_properties( avformat
                        PROPERTIES IMPORTED_LOCATION
                        ../../../../libs/${ANDROID_ABI}/lib/libavformat.so
                        )
set_target_properties( avutil
                        PROPERTIES IMPORTED_LOCATION
                        ../../../../libs/${ANDROID_ABI}/lib/libavutil.so
                        )
set_target_properties( swscale
                        PROPERTIES IMPORTED_LOCATION
                        ../../../../libs/${ANDROID_ABI}/lib/libswscale.so
                        )

# Specifies a path to native header files.
include_directories(
                    libs/${ANDROID_ABI}/include
                    )

target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       avcodec avdevice avfilter avformat avutil swscale
                       ${log-lib}
                        )

注意以下重要区别:

  • set_target_properties 中的路径必须是绝对路径。这里是使用"../../../../"四层到libs目录;但是,对于 include_directory 中的头文件路径,它需要是相对的。我使用了绝对路径,但找不到包含文件。顺便说一下,我删除了“ffmpeg”文件夹。

  • set_target_properties 中的导入位置属性需要为 IMPORTED_LOCATION

关于android - 'imported-lib - NOTFOUND' 在为 android studio 2.2 构建 ffmpeg 3.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40352177/

相关文章:

android - Android Andengine场景添加背景

c# - ImageMagick .net c# mp4/webm 视频在没有伪影的情况下获得 N 帧?

c++ - rtsp 流中的 h.264 I 帧丢失处理

python - 在 64 位 Windows 10 上构建/安装 PyFMI 包失败

c++ - 构建 mpi2 时出错 - 链接 libboost_system 时出现问题

java - 显示非常左上角的位图图像,未缩放

android、背景、图层列表和可缩放位图项目

node.js - ffmpeg x11grab 导出视频 16 :9 is distorded

linux - 如何将 vcpkg 与交叉构建工具链以及 sysroot 集成到 linux 中?

android - mGoogleApiClient 无法在另一个 Activity 中实现