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!