Prebuilt ffmpeg shared libraries using ndk

1,322 views
Skip to first unread message

laerci...@gmail.com

unread,
Jan 24, 2014, 4:10:03 PM1/24/14
to andro...@googlegroups.com
Hi all!

I'm trying to use ffmpeg libraries on Android. Here is what I have so far:
- Prebuilt .so files for the shared libraries (libavformat.so, libavcodec.so, ...)
- A jni-test module that returns a string (just the ndk example)

But when I try to add function calls from jni-test to the prebuilt libraries something crash.

Here is my Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := avcodec-prebuild
LOCAL_SRC_FILES := ffmpeg-build/lib/libavcodec.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ffmpeg-build/include
include $(PREBUILT_SHARED_LIBRARY)

# The libavformat library
include $(CLEAR_VARS)
LOCAL_MODULE := avformat-prebuild
LOCAL_SRC_FILES := ffmpeg-build/lib/libavformat.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ffmpeg-build/include
include $(PREBUILT_SHARED_LIBRARY)

... some other libraries using the same pattern above, and:

# The test library
include $(CLEAR_VARS)
LOCAL_ALLOW_UNDEFINED_SYMBOLS=false
LOCAL_MODULE := jni-test
LOCAL_SRC_FILES := test.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/ffmpeg-build/include
LOCAL_SHARED_LIBRARY := avformat-prebuild avcodec-prebuild avutil-prebuild
#LOCAL_LDLIBS     := $(LOCAL_PATH)/ffmpeg-build/lib/libavformat.so $(LOCAL_PATH)/ffmpeg-build/lib/libavcodec.so $(LOCAL_PATH)/ffmpeg-build/lib/libavutil.so
include $(BUILD_SHARED_LIBRARY)

If I try to ndk-build I get a lot of  "undefined reference to " errors when ndk-build tries to create the shared libraries jni-test. In this case, inspecting the command gives something like (I will split the lines to enhance readability:

/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++
-Wl,-soname,libjni-test.so
-shared
--sysroot=/opt/android-ndk/platforms/android-3/arch-arm /home/asano/dev/AndroidStudioProjects/TesteJNI/testejni/src/obj/local/armeabi/objs/jni-test/test.o
-lgcc -no-canonical-prefixes  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now   -lc -lm -o
/home/asano/dev/AndroidStudioProjects/TesteJNI/testejni/src/obj/local/armeabi/libjni-test.so

What strikes me is that there is nothing like -lavformat. Should not the ndk-build build command mention the libraries listed by LOCAL_SHARED_LIBRARY?


Then I tried to uncomment the line:
LOCAL_LDLIBS     := $(LOCAL_PATH)/ffmpeg-build/lib/libavformat.so $(LOCAL_PATH)/ffmpeg-build/lib/libavcodec.so $(LOCAL_PATH)/ffmpeg-build/lib/libavutil.so

This builds but issues me a warning:

Android NDK: WARNING:/home/asano/dev/AndroidStudioProjects/TesteJNI/testejni/src/jni/Android.mk:jni-test: non-system libraries in linker flags: /home/asano/dev/AndroidStudioProjects/TesteJNI/testejni/src/jni/ffmpeg-build/lib/libavformat.so /home/asano/dev/AndroidStudioProjects/TesteJNI/testejni/src/jni/ffmpeg-build/lib/libavcodec.so /home/asano/dev/AndroidStudioProjects/TesteJNI/testejni/src/jni/ffmpeg-build/lib/libavutil.so 
Android NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES   
Android NDK:     or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the   
Android NDK:     current module   

The .so files get into the apk but when I try to "System.loadLibrary("jni-test");", I get the "UnsatisfiedLinkError".

Does anyone see where I went wrong? Or has some hint on how to debug this?

Thanks in advance!

Tim Mensch

unread,
Jan 30, 2014, 5:50:58 PM1/30/14
to andro...@googlegroups.com
I use a very similar pattern, but I'm not getting undefined references. I'm not using LDLIBS for them; I'm just using LOCAL_SHARED_LIBRARY. I'm on the r9 version of the NDK. Which are you using?

I DO need to call System.loadLibrary() for each of the libraries in the correct order, though. And there's a gotcha in the way FFMPEG creates its libraries; it will tend to have a dependency on libavutil.so.1; I'm not sure if you can get around that via explicit loadLibrary().

I don't set "LOCAL_ALLOW_UNDEFINED_SYMBOLS" to false; maybe that's causing problems?

Tim
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/groups/opt_out.

Álan Livio

unread,
Feb 24, 2014, 9:52:50 AM2/24/14
to andro...@googlegroups.com
Hello Laercio Asano.
Do you compiled the ffmpeg libraries to ARM? Otherwise where did you get the prebuilt?
Thanks.

Abraços.

--
Álan Lívio V. Guedes
lattes.cnpq.br/1481576313942910
Reply all
Reply to author
Forward
0 new messages