Android NDK building - Include LOCAL_SHARED_LIBRARIES? - android

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
Where does ndk-build actually look for these libraries?
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':

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.

Related

Cannot build local shared library in Android Ndk

I want to build library .so for version 4.0.3 but I am unable to do so.
What I feel is that these problems are caused because my .mk file is not
linking with the libraries.
Android.mk file
Binder.cpp \
BpBinder.cpp \
CursorWindow.cpp \
IInterface.cpp \
IMemory.cpp \
IPCThreadState.cpp \
IPermissionController.cpp \
IServiceManager.cpp \
MemoryDealer.cpp \
MemoryBase.cpp \
MemoryHeapBase.cpp \
MemoryHeapPmem.cpp \
Parcel.cpp \
PermissionCache.cpp \
ProcessState.cpp \
Static.cpp
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS += -lpthread
LOCAL_MODULE := libbinder1
LOCAL_SHARED_LIBRARIES := liblog libcutils libutils
LOCAL_SRC_FILES := $(sources)
include $(BUILD_SHARED_LIBRARY)
#include $(CLEAR_VARS)
#LOCAL_CFLAGS += -DHAVE_PTHREADS
#LOCAL_LDLIBS += -lpthread
#LOCAL_MODULE := libbinder
#LOCAL_SRC_FILES := $(sources)
#include $(BUILD_STATIC_LIBRARY)
This file builds static i.e .a file for me but shows following errors while building shared library.
[armeabi] Compile++ thumb: binder1 <= IPCThreadState.cpp
jni/IPCThreadState.cpp:292:8: error: 'pthread_mutex_t' does not name a type
jni/IPCThreadState.cpp:294:8: error: 'pthread_key_t' does not name a type
jni/IPCThreadState.cpp: In static member function 'static android::IPCThreadState* android::IPCThreadState::self()':
I fixed above errors using
LOCAL_CFLAGS += -DHAVE_PTHREADS
But now, at the time of generating library I am getting a huge list of errors.
D:/android-ndk-r9c-windows-x86/android-ndk-r9c/toolchains/arm-linux-androideabi- 4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux- androideabi/bin/ld.exe: error: cannot find -lpthread
D:/android-ndk-r9c-windows-x86/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/binder1/Binder.o: in function android::Vector<android::String16>::do_copy(void*, void const*, unsigned int) const:jni/utils/TypeHelpers.h:142: error: undefined reference to 'android::String16::String16(android::String16 const&)'
Any help will be appreciated.
Android NDK supports pthreads, but does not provide libpthread as usual in Linux toolchains. Your first error message will be gone if you use
LOCAL_CFLAGS += -DHAVE_PTHREADS
and not add LOCAL_LDLIBS += -lpthread
Regarding the undefined reference to do_copy(), it comes from system library libutils.so. It is not safe to use libraries that are not officially published with NDK (see more here), so you better rewrite this piece of code.
Probably you received your Android.mk file from the google source or one of its forks. I doubt that the resulting library will be useable, because the original libbinder.so requires system app with elevated permissions will be loaded when your app starts.
Anyways, referring to system libraries as LOCAL_SHARED_LIBRARIES does not work with ndk-build. Instead of LOCAL_SHARED_LIBRARIES := liblog libcutils libutils you are expected to write
LOCAL_LDLIBS += -llog -lcutils -lutils

Android native shared libraries installation path

I'm struggling to get a native Android application correctly link against a custom shared object built in the same AOSP tree.
I have a shared object built with
LOCAL_SRC_FILES += \
src/libscanengine.c
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include/
LOCAL_C_INCLUDES += kernel/include/
#every module depending on us will
#automagically have this included
LOCAL_EXPORT_C_INCLUDES := \
$(LOCAL_PATH)/include
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libscanengine
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)
It gets built and installed as the mm command invocation
build/core/dynamic_binary.mk:141: warning: overriding commands for target `.so'
build/core/dynamic_binary.mk:118: warning: ignoring old commands for target `.so'
build/core/shared_library.mk:54: warning: overriding commands for target `.so'
build/core/dynamic_binary.mk:141: warning: ignoring old commands for target `.so'
No private recovery resources for TARGET_DEVICE X
No recovery.fstab for TARGET_DEVICE X
make: Circular .so <- .so dependency dropped.
make: Circular .so <- out/target/product/X/symbols/system/lib/libscanengine dependency dropped.
make: Circular .so <- .so dependency dropped.
target Non-prelinked: libscanengine (out/target/product/X/symbols/system/lib/libscanengine)
target Strip: libscanengine (out/target/product/X/obj/lib/libscanengine)
Install: out/target/product/X/system/lib/libscanengine.so
Once I try to buil a native application linked against the newly created .so with the following Android.mk
LOCAL_SRC_FILES := \
src/mores.c
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)
LOCAL_C_INCLUDES += \
$(LOCAL_PATH)/include/
#not working: commented out
#LOCAL_LDLIBS += \
-lscanengine
#LOCAL_C_FLAGS += \
-L../../out/target/product/X/system/lib/
LOCAL_SHARED_LIBRARIES := \
libscanengine
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := mores
include $(BUILD_EXECUTABLE)
I get:
make: *** No rule to make target `out/target/product/X/obj/lib/libscanengine.so', needed by `out/target/product/X/obj/EXECUTABLES/mores_intermediates/LINKED/mores'. Stop.
I noticed two things: the shared library is installed under X/out/lib as libscanengine and not libscanenegine.so as it is required by the native application.
I have to manually copy the .so everytime, which is stupid since all of this should be handled in some way by the Android build system.
Furthermore, the LOCAL_EXPORT_C_INCLUDES directive does not work. Does it work only with PREBUILT_SHARED_OBJECTS?
Android version is 2.3, there is no Java involved, everything is built under AOSP.
Thank you
j
LOCAL_C_FLAGS += \
-L../../out/target/product/X/system/lib/
does not work because it should read
LOCAL_LDFLAGS += \
-Lout/target/product/X/system/lib
or
LOCAL_LDFLAGS += \
-L$(LOCAL_PATH)/out/target/product/X/system/lib
But this does not explain why LOCAL_SHARED_LIBRARIES is not working. What commands do you use to build?
Whilst not a good solution, if the libscanengine target can't be found implicitly via AOSP, then you can always include it manually, like so.
include $(AOSP_ROOT)/PATH/TO/libscanengine/Android.mk
Regarding why the shared object won't build correctly, a hacky solution is providing a static object directly after the shared one which references it, in the Android.mk. For instance, this I adapted from an existing jpeg port. What I wanted was a shared library I could work with in a separate compilation step, but it wouldn't be built unless it was required by something.
$(call my-dir)
include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_SRC_FILES := \
jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
jfdctint.c jidctflt.c jidctred.c jquant1.c \
jquant2.c jutils.c jmemmgr.c \
jmem-android.c
# the assembler is only for the ARM version, don't break the Linux sim
ifneq ($(TARGET_ARCH),arm)
ANDROID_JPEG_NO_ASSEMBLER := true
endif
# temp fix until we understand why this broke cnn.com
#ANDROID_JPEG_NO_ASSEMBLER := true
ifeq ($(strip $(ANDROID_JPEG_NO_ASSEMBLER)),true)
LOCAL_SRC_FILES += jidctint.c jidctfst.c
else
LOCAL_SRC_FILES += jidctint.c jidctfst.S
endif
LOCAL_CFLAGS += -I"$(LOCAL_PATH)/./include" -DAVOID_TABLES
LOCAL_CFLAGS += -O3 -fstrict-aliasing -fprefetch-loop-arrays
#LOCAL_CFLAGS += -march=armv6j
LOCAL_MODULE:= jpeg
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := jpeg2
LOCAL_STATIC_LIBRARIES := jpeg
include $(BUILD_SHARED_LIBRARY)
Whilst neither of these are true solutions, as they don't address the underlying reason behind your problems, they may aid you, as they did me, in getting stuff working quickly and automatically.

Android NDK linking C module with C++ app

This is my complete Android.mk file, when I try to build this, I get a linker problem (see further down)
LOCAL_PATH := $(call my-dir)
#
# Opus - low-latency audio codec
#
include $(CLEAR_VARS)
LOCAL_DIR := opus-1.0.3
LOCAL_MODULE := opus
LOCAL_CELT_SOURCES := \
$(LOCAL_DIR)/celt/bands.c \
...
LOCAL_SILK_SOURCES := \
$(LOCAL_DIR)/silk/CNG.c \
...
LOCAL_SILK_SOURCES_FIXED := \
$(LOCAL_DIR)/silk/fixed/LTP_analysis_filter_FIX.c \
...
LOCAL_SILK_SOURCES_FLOAT := \
$(LOCAL_DIR)/silk/float/apply_sine_window_FLP.c \
...
LOCAL_OPUS_SOURCES := \
$(LOCAL_DIR)/src/opus.c \
...
LOCAL_CFLAGS := -DNONTHREADSAFE_PSEUDOSTACK
LOCAL_C_INCLUDES := \
$(LOCAL_DIR)/include \
$(LOCAL_DIR)/celt \
$(LOCAL_DIR)/silk \
$(LOCAL_DIR)/silk/fixed \
$(LOCAL_DIR)/silk/float
LOCAL_SRC_FILES := $(LOCAL_CELT_SOURCES) \
$(LOCAL_SILK_SOURCES) \
$(LOCAL_SILK_SOURCES_FIXED) \
$(LOCAL_SILK_SOURCES_FLOAT)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_DIR)/include
include $(BUILD_STATIC_LIBRARY)
################
include $(CLEAR_VARS)
LOCAL_MODULE := audio-client-jni
LOCAL_SRC_FILES := audio-client-jni.cpp
# low latency codec
LOCAL_STATIC_LIBRARIES += opus
# for native audio
LOCAL_LDLIBS += -lOpenSLES
# for logging
LOCAL_LDLIBS += -llog
# for native asset manager
LOCAL_LDLIBS += -landroid
include $(BUILD_SHARED_LIBRARY)
To rule out that there's a problem with the way opus is being built I've done the exact same thing using a different build system called tundra and it compliles just fine on Windows using MSVC++.
Here's the linker command and errors (I've formatted the command-line for readability)
C:/Projects/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++
-Wl,-soname,libaudio-client-jni.so
-shared
--sysroot=C:/Projects/android-ndk-r8e/platforms/android-14/arch-arm
C:/Projects/workspace/AudioClient//obj/local/armeabi/objs/audio-client-jni/audio-client-jni.o
C:/Projects/workspace/AudioClient//obj/local/armeabi/libopus.a
C:/Projects/workspace/AudioClient//obj/local/armeabi/libstdc++.a
-lgcc
-no-canonical-prefixes
-Wl,--no-undefined
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
-LC:/Projects/android-ndk-r8e/platforms/android-14/arch-arm/usr/lib
-lOpenSLES
-llog
-landroid
-lstdc++
-lc
-lm
-o C:/Projects/workspace/AudioClient//obj/local/armeabi/libaudio-client-jni.so
errors follow
C:/Projects/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: C:/Projects/workspace/AudioClient//obj/local/armeabi/objs/audio-client-jni/audio-client-jni.o: in function (anonymous namespace)::AuClient::ReceiveThenEnqueue():C:/Projects/workspace/AudioClient//jni/audio-client-jni.cpp:419: error: undefined reference to 'opus_decode'
C:/Projects/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: C:/Projects/workspace/AudioClient//obj/local/armeabi/objs/audio-client-jni/audio-client-jni.o: in function InitializeThread:C:/Projects/workspace/AudioClient//jni/audio-client-jni.cpp:387: error: undefined reference to 'opus_decoder_create'
I need a second pair of eyes on this, it's definetly linking audio-client-jni.o before libopus.a but if that is the issue I don't understand how to modify the makefile to get the desiered result. The opus.h API is defined with extern "C" when included in a C++ app. No luck so far.
Thanks to #AlexCohn for the assist, obviously there wasn't anything wrong, instead all the source files wasn't included properly, slight overlook from my part.
In my case, I wasn't sure how I should set things up to be able to run the bin util commands, luckily, it's as simple as:
"C:\Projects\android-ndk-r8e\toolchains\arm-linux-androideabi-4.6\prebuilt\windows-x86_64\bin\arm-linux-androideabi-nm.exe" "C:\Projects\workspace\AudioClient\obj\local\armeabi\libopus.a"
I just picked what seemed reasonable from the prebuilt toolchain.
With the output from nm I could verify that the exports weren't there. After closer inspection I noticed I had forgotten to include $(LOCAL_OPUS_SOURCES) in my LOCAL_C_INCLUDES. Fixing that, fixed the problem.

Boost Android, ndk-build doesn't create .so / headers can't be found

I've been trying to link boost into my android application following these instructions:
Include Boost C++ library in android
which seems to be pretty concise and sensible. Unfortunately, after days of trying I can't see what I'm doing wrong, as the end result is that ndk-build returns "No such file or Directory" regarding the boost headers I try to include.
After building the boost libraries I needed, I copied them in proj.android/jni/boost/include and proj.android/jni/boost/lib. I then created a directory in jni called boost-build, where I created an Android.mk to handle define the module to link to the libboost_serialization static library (which is the only boost library I'm interested in).
LOCAL_PATH:= $(call my-dir)
# serialization
include $(CLEAR_VARS)
# I'm not sure this is necessary / helpful, but I've tried without it, as well
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include/boost-1_49 \
# EDIT: replaced previous line from this, at Igor's correction: $(LOCAL_PATH)/../include/boost-1_49/boost \
$(LOCAL_PATH)/../include/boost-1_49/boost/archive \
$(LOCAL_PATH)/../include/boost-1_49/boost/serialization
LOCAL_MODULE:= boost_serialization
LOCAL_SRC_FILES:= ../lib/libboost_serialization-gcc-mt-1_49.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/boost-build-includes
include $(PREBUILT_STATIC_LIBRARY)
The android project makefile, proj.android/jni/Android.m:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LDFLAGS= -L$(NDK_ROOT)/sources/crystax/libs/armeabi-v7a/4.6.3 -Lcrystax
LOCAL_CPPFLAGS += -fexceptions
LOCAL_CPPFLAGS += -frtti
LOCAL_MODULE := game_shared
LOCAL_MODULE_FILENAME := libgame
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp \
../../Classes/TitleScene.cpp \
../../Classes/GameSettings.cpp \
../../Classes/Cutscene.cpp \
../../Classes/HighScoreTable.cpp \
../../Classes/MaskNode.cpp \
../../Classes/MenuResponder.cpp \
../../Classes/HudElementBg.cpp \
../../Classes/OHRCharSelectMenu.cpp \
../../Classes/OHRDifficultySelectMenu.cpp \
../../Classes/Types.cpp \
../../Classes/OHRMainMenu.cpp
# I've tried with / without this variable, as well, with the same result
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
$(LOCAL_PATH)/../include/boost-1_49 \
# EDIT: replaced previous line from this, at Igor's correction: $(LOCAL_PATH)/../include/boost-1_49/boost \
$(LOCAL_PATH)/../boost/include/boost-1_49/boost/archive \
$(LOCAL_PATH)/../boost/include/boost-1_49/boost/serialization
LOCAL_WHOLE_STATIC_LIBRARIES := boost_serialization cocos2dx_static cocosdenshion_static cocos_extension_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,CocosDenshion/android) \
$(call import-module,boost-build) \
$(call import-module,cocos2dx)
Now, when I run ndk-build to compile my source, I get the following error:
Compile++ thumb : game_shared <= main.cpp
Compile++ thumb : game_shared <= AppDelegate.cpp
In file included from jni/../../Classes/MapUtils.h:2:0,
from jni/../../Classes/Types.h:3,
from jni/../../Classes/menuresponder.h:2,
from jni/../../Classes/OHRMainMenu.h:2,
from jni/../../Classes/TitleScene.h:10,
from jni/../../Classes/AppDelegate.cpp:6:
jni/../../Classes/BoostUtils.h:2:36: fatal error: boost/archive/tmpdir.hpp: No such file or directory
(BoostUtils.h being a header that simply includes a bunch of serialization-related headers)
#include <boost/archive/tmpdir.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/list.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/assume_abstract.hpp>
Now, exactly once tonight, running this generated a bunch of .so's and .a's, include libbost_serialization.so, in proj.android/obj/local. I have not been able to get that to be generated since, despite deleting the /obj directory. Also odd is that, despite what's suggested by the link at the top of this post, a /libs directory is not being created when ndk-build is run. However, I'm not 100% sure that .so even needs to be generated.
So, for the life of me I can't identify the problem here. Any solutions or direction would be much, much appreciated.
Lesson learned: LOCAL_C_INCLUDES actually is a necessary variable, and make sure it's pointing to the right place. In my case, it was just an errant '../' and including the contents of 'boost/', rather than the directory containing boost.
(Also, sleep more, rather than spend hours glancing over these issues.)

Android NDK linking

I am trying to build an android application that calls into a C++ backend. This backend uses ZeroMQ for messaging. Per the android build page on the ZeroMQ guide, I have built a native toolchain of ndk version 6 and used that to (successfully) build ZeroMQ.
However, when I build my own .so with the JNI implementations, I can't seem to make everything load properly. Specifically, if I call System.LoadLibrary("zmq"), this completes successfully, but if I then call *System.LoadLibrary("my_lib")* I always get an UnsatisfiedLinkError complaining that:
Cannot load library reloc_library[1244]: 29 cannot locate zmq_msg_init'...
The libmy_lib.so has been generated several different ways, each with no success. After generating it, I always copies libmy_lib.so (as well as libzmq.so) to my android project's folder: libs/armeabi/.
# Compile all object files - this part was done for all options
/opt/android-toolchain/bin/arm-linux-androideabi-g++ -fpic -c Client_Events.cpp \
Client Wrapper.cpp jni.cpp -I /opt/android-root/include/ -I /my/project/specific/stuff
# Option 1 - Don't link the lib in at all
/opt/android-toolchain/bin/arm-linux-androideabi-g++ -shared \
-Wl,-soname,libmy_lib.so -o libmy_lib.so jni.o Client_Events.o Client_Wrapper.o
# Option 2 - Link ZeroMQ in statically
/opt/android-toolchain/bin/arm-linux-androideabi-g++ -shared \
-Wl,-soname,libmy_lib.so -o libmy_lib.so jni.o Client_Events.o Client_Wrapper.o \
libzmq.a libstdc++.a -Wl,--whole-archive
# Option 3 - Explicitly link ZeroMQ in dynamically
/opt/android-toolchain/bin/arm-linux-androideabi-g++ -shared \
-Wl,-soname,libmy_lib.so -o libmy_lib.so jni.o Client_Events.o Client_Wrapper.o \
-L /opt/android-root/lib/ -lzmq
With each of these options I tried both explicitly calling System.LoadLibrary("zmq") before loading my own library and not. Nothing varied the results. Using nm confirms that, at least in the case of option #2, the missing symbol *zmq_msg_init* is indeed present in libmy_lib.so.
Any ideas as to why it cannot find the ZeroMQ symbols that are linked in?
I just learnt how to compile a 2nd library and link it to my main library in android ndk. Let me see if I am of any use to you.
The following is how I create my 2nd library (In my case, I build bullet physics library and the irrlicht rendering engine as 2 separate libraries for my game).
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := HEADER FILES
LOCAL_MODULE := bullet
LOCAL_SRC_FILES := SRC FILES
LOCAL_ARM_MODE := arm
LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O3 -DANDROID_NDK -DDISABLE_IMPORTGL
LOCAL_LDLIBS := -ldl -llog
include $(BUILD_SHARED_LIBRARY)
Then copy your libxxxx.so (In my case, libbullet.so and libirrlicht.so) to your jni folder. And in your main library .mk file add the following.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := (includes for bullet)
LOCAL_MODULE := bullet
LOCAL_SRC_FILES := libbullet.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := (includes for irrlicht)
LOCAL_MODULE := irrlicht
LOCAL_SRC_FILES := libirrlicht.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := (includes for bullet + includes for irrlicht + includes for main code)
LOCAL_SRC_FILES := main code src files
LOCAL_MODULE := gamescript
LOCAL_ARM_MODE := arm
LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O3 -DANDROID_NDK -DDISABLE_IMPORTGL
LOCAL_LDLIBS := -lOpenSLES -landroid -ldl -llog
LOCAL_SHARED_LIBRARIES := bullet irrlicht
include $(BUILD_SHARED_LIBRARY)
And now, add all the libraries to your java code in right order.
System.loadLibrary("bullet");
System.loadLibrary("irrlicht");
System.loadLibrary("gamescript");

Categories

Resources