Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NDK building - Include LOCAL_SHARED_LIBRARIES?

I'm having problems building a project under the Android NDK. Most likely its due to the proper shared / static libraries not being included. The ones as -lsomeLib I added, but the ones as LOCAL_SHARED_LIBRARIES are not being included it seems...

My Android.mk contains the following

LOCAL_SHARED_LIBRARIES += libutils libmedia libz libbinder

  1. Where does ndk-build actually look for these libraries?
  2. If I don't include the -lutils -lmedia -lz -lbinder, I am not able to even get to the linker error. I have a feeling including just -LsomeDir and -lsomeLib is not the correct way to add them.

Here is the complete Android.mk.

LOCAL_PATH := /Users/kevin/Desktop/player2/videoplayer/videoplayer/jni
LIBPLAYER_PATH := $(LOCAL_PATH)/../../LibPlayer

include $(CLEAR_VARS)

$(warning Android make file: $(LOCAL_PATH)/Android.mk)
$(warning Android sysroot: $(SYSROOT))
$(warning Additional LD_LIBS: $(LOCAL_PATH)/lib)

ifeq ($(BUILD_ID),MID)
        LOCAL_CFLAGS += -DENABLE_FREE_SCALE
endif

LOCAL_MODULE    := libamplayerjni
LOCAL_SRC_FILES := com_farcore_playerservice_AmPlayer.c sys_conf.c
LOCAL_ARM_MODE := arm
LOCAL_C_INCLUDES := $(LIBPLAYER_PATH)/amplayer/player/include \
    $(LIBPLAYER_PATH)/amplayer/control/include \
    $(LIBPLAYER_PATH)/amcodec/include \
    $(LIBPLAYER_PATH)/amffmpeg \
    $(JNI_H_INCLUDE) \
    /Android/ndk/build/tools/android-9-toolchain/sysroot/usr/include \
    /Android/ndk/build/platforms/android-9/arch-arm/usr/include \
    /Android/source_2.3/system/core/include \
    /Android/source_2.3/frameworks/base/include

LOCAL_LDLIBS := -L/Users/kevin/Desktop/player2/videoplayer/videoplayer/jni/lib -L$(SYSROOT)/usr/lib -llog -lz -lm -ldl **-lmedia -lstagefright -lutils -lbinder -lgcc -landroid -lc -lstdc++ -lthread_db**

**LOCAL_STATIC_LIBRARIES := libamplayer libamcodec libavformat libavcodec libavutil libamadec**
LOCAL_SHARED_LIBRARIES += libutils libmedia libz libbinder 

LOCAL_PRELINK_MODULE := false

include $(BUILD_SHARED_LIBRARY)

One of many errors related specifically to those libraries (ie libmedia.so).

/Users/kevin/Desktop/player2/videoplayer/videoplayer/obj/local/armeabi-v7a/libamadec.a(android_out.o): In function `android_uninit':
/Users/kevin/Desktop/player2/videoplayer/LibPlayer/amadec/audio_out/android_out.cpp:220: undefined reference to `android::AudioTrack::stop()'
/Users/kevin/Desktop/player2/videoplayer/LibPlayer/amadec/audio_out/android_out.cpp:228: undefined reference to `android::AudioTrack::~AudioTrack()'
/Users/kevin/Desktop/player2/videoplayer/videoplayer/obj/local/armeabi-v7a/libamadec.a(android_out.o): In function `~Autolock':
like image 228
Kevin Parker Avatar asked Jun 11 '12 21:06

Kevin Parker


People also ask

What is NDK build?

The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android and provides platform libraries you can use to manage native activities.

What are mk files in Android?

Overview. The Android.mk file resides in a subdirectory of your project's jni/ directory, and describes your sources and shared libraries to the build system. It is really a tiny GNU makefile fragment that the build system parses once or more.

What compiler does NDK use?

Code written in C/C++ can be compiled to ARM, or x86 native code (or their 64-bit variants) using the Android Native Development Kit (NDK). The NDK uses the Clang compiler to compile C/C++. GCC was included until NDK r17, but removed in r18 in 2018.


1 Answers

It looks to me like you should not be including -lmedia etc in your LOCAL_LDLIBS arguments.

1. Where does ndk-build actually look for these libraries?

If you look in $NDK/docs/STABLE-APIS.html you will see that there is a specified set of libraries you can include in this manner. Note:

The headers corresponding to a given API level are now located under $NDK/platforms/android-<level>/arch-arm/usr/include

Having looked myself, none of the libraries you specified exist there, although I only looked for API-14.


2. If I don't include the -lutils -lmedia -lz -lbinder, I am not able to even get to the linker error. I have a feeling including just -LsomeDir and -lsomeLib is not the correct way to add them.

If your libraries are just regular c/c++ libraries that you would #include you should use LOCAL_C_INCLUDES instead.

Also note, from $NDK/docs/ANDROID-MK.html:

  • The build system handles many details for you. For example, you don't need to list header files or explicit dependencies between generated files in your Android.mk. The NDK build system will compute these automatically for you.

In order to use other libraries in my native code, I simply #include it and then specify where to find the headers. Here's my LOCAL_C_INCLUDES:

LOCAL_C_INCLUDES := $(LOCAL_PATH)/shared/Core/inc \
                    $(LOCAL_PATH)/shared/Model/inc  \
                    $(LOCAL_PATH)/shared/boost/include

I hope this helps.

like image 105
n.collins Avatar answered Oct 12 '22 21:10

n.collins