mdang
mdang

Reputation: 155

'imported-lib - NOTFOUND' in building ffmpeg 3.2 for android studio 2.2

I am trying to build and use ffmpeg for Android. My Andoid Studio version is 2.2.2 and ffmpeg is 3.2. Following Android documentation on how to import rebuild library, I think I got the setting right but kept on getting this error

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

This is the setting

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

If I specify the full library name, libavcodec.so..., the error would go away.

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

I wonder if anyone encountered similar issue or know why the compilation behaves this way.

Upvotes: 4

Views: 1180

Answers (1)

mdang
mdang

Reputation: 155

Based on Tsyvarev's input, what I got here compiled and linked.

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

Note follow important differences:

  • The path in set_target_properties need to be absolute. Here is use "../../../../" four levels up to the libs directory; however, for the header files path in include_directory, it needs to be relative. I used the absolute path and the include files couldn't be found. By the way, I removed the 'ffmpeg' folder.

  • The import location property in set_target_properties needs to be IMPORTED_LOCATION.

Upvotes: 2

Related Questions