I think I got it to work or atleast get my problem to solve. The problem was due to two things:
1) ffmpeg libraries were built with "android-23".
2) The Android Studio didn't package the ffmpeg libraries to the APK.
Here is what I have for it to work.
Build ffmpeg libraries with "android-19" (or lower as suggested from other links). By the way, the targetSdkVersion does not have to be < 21. For me, it still work with 23.
Call System.loadlibrary("") in specific order for these libraries that I am using.
System.loadLibrary("avutil-55");
System.loadLibrary("swscale-4");
System.loadLibrary("avcodec-57");
System.loadLibrary("avfilter-6");
System.loadLibrary("avformat-57");
System.loadLibrary("avdevice-57");
What threw me off was that the first four line executed fine. The error showed up on the fifth call. I have no idea why.
Anyway, this is what I have in the CMakeLists.txt for the ffmpeg libraries.
# Sub-libraries ffmpeg
add_library( avcodec-57 SHARED IMPORTED )
add_library( avdevice-57 SHARED IMPORTED )
add_library( avfilter-6 SHARED IMPORTED )
add_library( avformat-57 SHARED IMPORTED )
add_library( avutil-55 SHARED IMPORTED )
add_library( swscale-4 SHARED IMPORTED )
set_target_properties( avcodec-57
PROPERTIES IMPORTED_LOCATION
../../../../libs/${ANDROID_ABI}/lib/libavcodec-57.so
)
set_target_properties( avdevice-57
PROPERTIES IMPORTED_LOCATION
../../../../libs/${ANDROID_ABI}/lib/libavdevice-57.so
)
set_target_properties( avfilter-6
PROPERTIES IMPORTED_LOCATION
../../../../libs/${ANDROID_ABI}/lib/libavfilter-6.so
)
set_target_properties( avformat-57
PROPERTIES IMPORTED_LOCATION
../../../../libs/${ANDROID_ABI}/lib/libavformat-57.so
)
set_target_properties( avutil-55
PROPERTIES IMPORTED_LOCATION
../../../../libs/${ANDROID_ABI}/lib/libavutil-55.so
)
set_target_properties( swscale-4
PROPERTIES IMPORTED_LOCATION
../../../../libs/${ANDROID_ABI}/lib/libswscale-4.so
)
# Specifies a path to native header files.
include_directories(
libs/${ANDROID_ABI}/include
)
target_link_libraries( # Specifies the target library.
native-libcore
# Links the target library to the log library
# included in the NDK.
avcodec-57 avdevice-57 avfilter-6 avformat-57 avutil-55 swscale-4
${log-lib}
)
- Finally, because Android Studio 2.2 doesn't package the libraries, I manually copied the libraries to the project ..\build\intermediates\cmake\debug\obj\ folder. This folder does not exist until the CMakeLists.txt is refresh (do a project sync). The libraries will the be copied to the apk when the app is run.