Issue
In an effort to reduce bandwidth usage of an application, I tried to make an implementation of opus.
First, I cross-compiled the sources into a shared library. I copied the resulting .so file into an opus folder inside my jni folder. I also copied all opus header files into an include subfolder in the opus folder. Finally, I created an Android.mk file to allow the usage of this .so file in my implementation.
So my file structure is as follows:
/jni
/opus
/include
All opus header files
Android.mk
libopus.so
Android.mk
OpusEncoder.h
OpusDecoder.h
OpusEncoder.c
OpusDecoder.c
The Android.mk file in the opus subfolder has the following content:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := opus
LOCAL_SRC_FILES := jni/opus/libopus.so
LOCAL_C_INCLUDES := jni/opus/include
include $(PREBUILD_SHARED_LIBRARY)
As is recommended to expose the .so file for usage.
Now, in my implementation of the Encoder/Decoder, I import opus.h
, and use the appropriate functions in order to expose them through JNI to the Java layer.
The Android.mk in my jni folder (which should build my JNI layer) is as follows:
LOCAL_PATH := $(call my-dir)
MY_DIR := $(LOCAL_PATH)
include $(CLEAR_VARS)
include jni/opus/Android.mk
APP_ABI := armeabi armeabi-v7a
LOCAL_PATH := $(MY_DIR)
LIB_PATH := $(LOCAL_PATH)/../lib
LOCAL_LDLIBS += -llog -landroid
#LOCAL_LDLIBS += $(LIB_PATH) -lopus
LOCAL_SHARED_LIBRARIES := opus
LOCAL_MODULE := OpusCodec
LOCAL_SRC_FILES := OpusEncoder.c \
OpusDecoder.c
include $(BUILD_SHARED_LIBRARY)
However, when I run the ndk-build
command, I get the following 6 error messages:
error: undefined reference to 'opus_encoder_create'
error: undefined reference to 'opus_encode'
error: undefined reference to 'opus_encoder_destroy'
error: undefined reference to 'opus_decoder_create'
error: undefined reference to 'opus_decode'
error: undefined reference to 'opus_decoder_destroy'
Which are all methods exposed by opus.h
in libopus.so
. Any ideas?
Solution
Okay, so this all turned out to be a typographical error on my behalf.
For the keen observer, to make the prebuilt opus library, I used the call include $(PREBUILD_SHARED_LIBRARY)
where it should have been include $(PREBUILT_SHARED_LIBRARY)
(the difference being the T instead of D at the end of PREBUILT).
As a result, it didn't create the library that I tried to link to with LOCAL_SHARED_LIBRARIES := opus
in my main Android.mk file.
So this is how I have my Android.mk file for the prebuilt library:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libopus
LOCAL_SRC_FILES := libopus.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
And this is my Android.mk file for the code I wrote:
MY_PROJECT_PATH := $(call my-dir)
LOCAL_PATH = $(MY_PROJECT_PATH)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
APP_ABI := armeabi armeabi-v7a
LOCAL_PATH = $(MY_PROJECT_PATH)
LOCAL_MODULE := OpusCodec
LOCAL_SHARED_LIBRARIES := libopus
LOCAL_LDLIBS += -llog -landroid
LOCAL_SRC_FILES := OpusEncoder.c OpusDecoder.c
include $(BUILD_SHARED_LIBRARY)
Other than the cosmetic change to the prebuilt library module, and restructuring my main Android.mk file, I didn't have to change a thing (you don't need to specify the LIB_PATH
as I originally tried).
Answered By - ThaMe90
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.