-1

I am using Android Studio 2.2 and try to link ffmpeg libraries to run on Android 4.1.2 device. When loading the avformat library, I get the error

"cannot load library: reloc_library[1306]: 249 cannot locate 'atof'..."

Below is a link that points out that if an app is built with SDK version 21 and above will have this issue when running on devices with older Android version (SDK version < 19).

Cannot load library: reloc_library[1285]: cannot locate 'rand'

I changed the targetSdkVersion to 19 in my build.gradle and built ffmpeg libraries with "android-16" target, and still get the error.

I wonder if anyone has similar issue and found a way to make it work. Thanks.

Community
  • 1
  • 1
mdang
  • 145
  • 14

1 Answers1

0

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.
mdang
  • 145
  • 14
  • I got Android Studio 2.2 to package the prebuild libraries. In the jniLibs, it should only contain the folders and only libraries files should be in it. Before I had include and lib folders in it. The build copies the library files to the jni folder in the build folder, but there weren't any. – mdang Nov 05 '16 at 01:05