Adding Cryptopp to Android.mk - android

I have tried building cryptopp library for android.I have used this part of the tutorial.
https://www.cryptopp.com/wiki/Android_(Command_Line)
$ cat build-all-android.sh
#!/bin/bash
for arch in armeabi armeabi-v7a armeabi-v7a-hard arm64-v8a mips mips64 x86 x86_64
do
. ./setenv-android.sh $arch stlport
if [ "$?" -eq "0" ]; then
make -f GNUmakefile-cross distclean
make -f GNUmakefile-cross static dynamic
sudo make -f GNUmakefile-cross install PREFIX=/usr/local/cryptopp/android-$arch
fi
done
I was able to make the libraries.
My problem is, I can't add it to my project.
It seems like I need to edit my Android.mk file but I can't seem to do it properly. I added this block to my Anroid.mk
#########################################################
# STLport library
include $(CLEAR_VARS)
STLPORT_INCL := /Applications/Cocos/Android/android-ndk-r10e/sources/cxx-stl/stlport
STLPORT_LIB := /Applications/Cocos/Android/android-ndk-r10e/sources/cxx-stl/stlport/libs/$(TARGET_ARCH_ABI)
LOCAL_MODULE := stlport_shared
LOCAL_SRC_FILES := $(STLPORT_LIB)/libstlport_shared.so
LOCAL_CPP_FEATURES += rtti exceptions
LOCAL_EXPORT_CPPFLAGS :=
LOCAL_EXPORT_C_INCLUDES := $(STLPORT_INCL)
include $(PREBUILT_SHARED_LIBRARY)
LOCAL_SHARED_LIBRARIES := stlport_shared
#########################################################
# Crypto++ library
include $(CLEAR_VARS)
CRYPTOPP_INCL := /usr/local/cryptopp/android-$(TARGET_ARCH_ABI)/include
CRYPTOPP_LIB := /usr/local/cryptopp/android-$(TARGET_ARCH_ABI)/lib
LOCAL_MODULE := cryptopp
LOCAL_SRC_FILES := $(CRYPTOPP_LIB)/libcryptopp.so
LOCAL_CPP_FEATURES := rtti exceptions
LOCAL_EXPORT_C_INCLUDES := $(CRYPTOPP_INCL) $(CRYPTOPP_INCL)/cryptopp
include $(PREBUILT_SHARED_LIBRARY)
LOCAL_SHARED_LIBRARIES := cryptopp
#########################################################
I based this on the Crypto++ wiki page Android Activity which referenced AndroidPRNG, which demonstrates using Crypto++ as a shared object on Android.
I'm stuck because I can't make it work. I'm very new to android so I don't exactly know what to do about it. I was able to make the ios version of it run. I followed the XCode tutorial. It's just this that's making me crazy. I would appreciate all the help I can get. Is there something wrong with how I build? After building, do I copy it to my project or just linking the installed verion is fine? How do I properly add/link it to my project? Sorry for asking so many questions.
PS: I'm using cocos2dx for my project. Maybe it's worth mentioning.

After reading and trying all sorts of combination for my Android.mk, I was able to compile cryptopp with cocos2dx.
Anyway, here's how i fixed the compiler error:
FIRST - Build the libraries
cat build-all-android.sh
#!/bin/bash
for arch in armeabi armeabi-v7a armeabi-v7a-hard arm64-v8a mips mips64 x86 x86_64
do
AOSP_PI="android-16" . ./setenv-android.sh $arch gnu-static
if [ "$?" -eq "0" ]; then
make -f GNUmakefile-cross distclean
make -f GNUmakefile-cross static dynamic
sudo make -f GNUmakefile-cross install PREFIX=/usr/local/cryptopp/android-$arch
fi
done
Notice that I used gnu-static -> this is because cocos2dx is using gnu-static.
SECOND - Update Android.mk
# Crypto++ library
include $(CLEAR_VARS)
CRYPTOPP_INCL := /usr/local/cryptopp/android-$(TARGET_ARCH_ABI)/include
CRYPTOPP_LIB := /usr/local/cryptopp/android-$(TARGET_ARCH_ABI)/lib
LOCAL_MODULE := cryptopp
LOCAL_SRC_FILES := $(CRYPTOPP_LIB)/libcryptopp.a
LOCAL_CPP_FEATURES := rtti exceptions
LOCAL_EXPORT_C_INCLUDES := $(CRYPTOPP_INCL) $(CRYPTOPP_INCL)/cryptopp
include $(PREBUILT_STATIC_LIBRARY)
LOCAL_SHARED_LIBRARIES := cryptopp
---------------------------------------- FOR WINDOWS ----------------------------------------
The answer above only works for mac. In Windows, I tried installing the cryptopp libraries but I wasn't successful. AOSP_TOOLCHAIN_PATH was invalid. I tried fixing it by updating the setenv-android.sh to include "windows-x86_64". I was able to fix that part but sadly I had a "make:not a command" error. I was told that I had to download it for my cygwin.
I'm currently downloading it. I will udpate this answer when I'm able to install the make and sudo commands to my Windows.
In the mean time, here's what I did to make my project using cryptopp compile in Windows assuming that you have successfully compiled it in mac:
1.) Copy the cryptopp android specific libraries and header files from /usr/local/cryptopp to your jni folder. It should look something like this:
Note: In /usr/local/cryptopp the include files are located in the specific android folder. In the example above, I placed the include file outside since they are all using the same header files. This way, we will avoid duplicated header files.
2.) After copying, update your Android.mk. Make it point to your new cryptopp directory instead. If you followed the hierarchy in step1, your Android.mk code for cryptopp will look something like this:
# Crypto++ library
include $(CLEAR_VARS)
CRYPTOPP_INCL := $(LOCAL_PATH)/Cryptopp/include
CRYPTOPP_LIB := Cryptopp/android-$(TARGET_ARCH_ABI)/lib
LOCAL_MODULE := cryptopp
LOCAL_SRC_FILES := $(CRYPTOPP_LIB)/libcryptopp.a
LOCAL_CPP_FEATURES := rtti exceptions
LOCAL_EXPORT_C_INCLUDES := $(CRYPTOPP_INCL) $(CRYPTOPP_INCL)/cryptopp
include $(PREBUILT_STATIC_LIBRARY)
LOCAL_SHARED_LIBRARIES := cryptopp
Note: Notice that we didn't use $(LOCAL_PATH) for the CRYPTOPP_LIB which was used by LOCAL_SRC_FILES. This is to avoid having a missing directory: jni/jni/Cryptopp/android-$(TARGET_ARCH_ABI)/lib/libcryptopp.a. Remember that LOCAL_SRC_FILES start searching in jni/.

Related

How to include a prebuilt "*.a" library (from tensorflow) to my android NDK project with no Android.mk file?

I'm trying to compile my application to use tensorflow C++ library after building lintensorflow_core.a into my NDK application. The application has the main java layer, that communicates with the NDK component. In that NDK component, I'm looking to call the tensorflow as such: using namespace ::tensorflow::ops; // NOLINT(build/namespaces)
I've seen bunch of links on how to do it with Android.mk file. But apparently, that does not gets created anymore in the new version of android studio. If it is possible with just Android.mk and ndk-build command, that would be great as well. However, the combination of Android.mk and ndk-build has also failed me. The output basically nothing.
I did have plenty of variation of Android.mk file and here's one of them:
LOCAL_PATH := $(call my-dir)
TENSORFLOW_HOME := $(LOCAL_PATH)/../../../../../tensorflow
TENSORFLOW_CORE := $(LOCAL_PATH)/../../../../../tensorflow/tensorflow/core
TENSORFLOW_OPS := $(LOCAL_PATH)/../../../../../tensorflow/tensorflow/core/ops
include $(CLEAR_VARS)
LOCAL_MODULE := tensorflow
LOCAL_SRC_FILES := $(TENSORFLOW_HOME)/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a
LOCAL_LDLIBS := -static -Wl,--build-id -Wl,--allow-multiple-definition -Wl,--whole-archive
LOCAL_CFLAGS := -std=c++11 -I$(TENSORFLOW_HOME)
LOCAL_C_INCLUDES := $(TENSORFLOW_OPS)
TARGET_ARCH_ABI := armeabi
include $(PREBUILT_STATIC_LIBRARY)
But this has been a total failure. Could someone point me to the right direction?

ANDROID: How to properly link against static libraries while creating shared libraries with dependencies on the static ones

I have to use some c++ code in my android application. This code was used successfully in an iOS project.
The code depends on 2 external libraries: zero-mq and protocol buffers.
I compiled the zmq library as an static library like explained here. I added the static (.a) library and the .jar to my project.
I created the protobuf library with the following configurations:
./configure --host=arm-eabi --with-sysroot=x/android-ndk-r10d/platforms/android-21/arch-arm CC="x/android-ndk-r10d/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc --sysroot x/android-ndk-r10d/platforms/android-21/arch-arm" --enable-cross-compile --with-protoc=protoc LIBS=-lc
make
I changed the real directories to x to make them shorter.
In my Android Project(IDE: Android Studio) I prepared everything which is necessary. I created a JNI Folder and deactivated the auto-creation of the makefiles.
Application.mk:
APP_MODULE := proxy
APP_STL := gnustl_shared
APP_CPPFLAGS := -frtti -fexceptions --std=c++11
APP_ABI := armeabi-v7a ##all later
NDK_TOOLCHAIN_VERSION := 4.9
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := zmq_static
LOCAL_SRC_FILES := zmq/libzmq.a
include $(PREBUILD_STATIC_LIBRARY)
LOCAL_MODULE := protobuf_static1
LOCAL_SRC_FILES := protobuf/libprotobuf.a
LOCAL_EXPORT_C_INCLUDES := google/protobuf protobuf/
include $(PREBUILD_STATIC_LIBRARY)
LOCAL_MODULE := protobuf_static2
LOCAL_SRC_FILES := protobuf/libprotobuf-lite.a
LOCAL_EXPORT_C_INCLUDES := google/protobuf protobuf/
include $(PREBUILD_STATIC_LIBRARY)
LOCAL_MODULE := protobuf_static3
LOCAL_SRC_FILES := protobuf/libprotoc.a
LOCAL_EXPORT_C_INCLUDES := google/protobuf protobuf/
include $(PREBUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := proxy
LOCAL_CFLAGS := -I/include -pthread -lpthread -D__GXX_EXPERIMENTAL_CXX0X__ - frtti
LOCAL_CPPFLAGS := -I/include -pthread -lpthread -D__GXX_EXPERIMENTAL_CXX0X__ -frtti
LOCAL_CPP_FEATURES += exceptions
LOCAL_LDLIBS := -llog
LOCAL_SRC_FILES := \
usersession.cpp\
## LOCAL_ALLOW_UNDEFINED_SYMBOLS := true will compile the code but shutdown on runtime
LOCAL_C_INCLUDES += C:\Users\M\Dropbox\Workspace\ndk_swig_test\app\src\main\jni
LOCAL_C_INCLUDES += C:\Users\M\Dropbox\Workspace\ndk_swig_test\app\src\arm\jni
LOCAL_C_INCLUDES += C:\Users\M\Dropbox\Workspace\ndk_swig_test\app\src\debug\jni
LOCAL_C_INCLUDES += C:\Users\M\Dropbox\Workspace\ndk_swig_test\app\src\armDebug\jni
LOCAL_C_INCLUDES += \zmq
LOCAL_C_INCLUDES += \protobuf
LOCAL_STATIC_LIBRARIES := zmq_static protobuf_static1 protobuf_static2 protobuf_static3
LOCAL_WHOLE_STATIC_LIBRARIES := zmq_static protobuf_static1 protobuf_static2 protobuf_static3
include $(BUILD_SHARED_LIBRARY)
The zmq library is in the subdirectory zmq and the protobuf library is in the subfolder protobuf.
Now the linking of the Objects still does not work. The Error Output when I execute ndk-build:
C:\Users\M\Dropbox\Workspace\ndk_swig_test\app\src\main\jni>ndk-build
[armeabi-v7a] SharedLibrary : libproxy.so
C:/Users/M/Documents/ndk/sources/cxx-stl/gnu- libstdc++/4.9/include/ext/new_allocator.h:127: error: undefined reference to 'ControlledInstance::ControlledInstan (std::shared_ptr<protogen::Application>, std:
:shared_ptr<protogen::Role>, std::shared_ptr<protogen::User>)'
C:/Users/M/Documents/ndk/sources/cxx-stl/gnu- libstdc++/4.9/include/bits/shared_ptr_base.h:511: error: undefined reference to 'protogen::User::User()'
C:/Users/M/Documents/ndk/sources/cxx-stl/gnu- libstdc++/4.9/include/bits/shared_ptr_base.h:914: error: undefined reference to 'google::protobuf::internal::empty tring_'
C:/Users/M/Dropbox/Workspace/ndk_swig_test/app/src/main//jni/controlledinstance.h :23: error: undefined reference to 'protogen::MetaGraph::~MetaGraph()'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [C:/Users/M/Dropbox/Workspace/ndk_swig_test/app/src/main//obj/local/armeabi- v7a/libproxy.so] Error 1
I tried many versions of the Android.mk and recreated the library more than once with different options which I found all over the internet.
I also looked at dozens of threads on stackoverflow which did not help me.(I'm not allowed to link them because of low reputation)
Additionally i read most of the doc files from the ndk e.g. PREBUILTS.
I added some other directories to my JNI directory e.g. the directory with the original files and directories (compiler, io, stubs...). I think this directory should offer the export of the necessary methods if the prebuild library was successfully linked to my shared library - which is not the case.
I tried far more than I can explain in few minutes and I think it would be overkill if i added everything I've tried because nothing helped.
Because this is my first question I dont have the reputation to include more than 2 links. Sorry for that.
There may probably be other issues as well, but you at least have got a typo - it should be include $(PREBUILT_STATIC_LIBRARY), as in, BUILT, not BUILD.

use libcryto.so and libssl.so in an android project?

I'm beginer to Android NDK. I want to build a RSA example base on openssl libary.
First, I built libssl.so and libcrypto.so librairies with ndk-build in the guardianproject.
Next, I create a new sample project to integrate libary (libss.so & lybcryto.so). I follow the same in this post
My App directory
TrialApp
|
|-->Activity.java (includes System.LoadLibrary calls)
|
|-->jni
|-->TestJNI2.cpp
|
|-->Android.mk
|
|-->includes
| |
| |-->openssl (dir containing *.h files)
|
|-->precompiled
|-->libssl.so
|-->libcrypto.so
My android.mk:
LOCAL_PATH := $(call my-dir)
# Prebuilt libssl
include $(CLEAR_VARS)
LOCAL_MODULE := ssl
LOCAL_SRC_FILES := precompiled/libssl.so
include $(PREBUILT_SHARED_LIBRARY)
# Prebuilt libcrypto
include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := precompiled/libcrypto.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
c_includes := $(LOCAL_PATH)
cf_includes := includes/openssl
cf_includes := $(addprefix -Ijni/,$(cf_includes))
export_c_includes := $(c_includes)
LOCAL_MODULE := security
LOCAL_SRC_FILES := TestJNI2.cpp
LOCAL_CFLAGS += $(cf_includes)
LOCAL_EXPORT_C_INCLUDES := $(export_c_includes)
LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libssl.so
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libcrypto.so
include $(BUILD_SHARED_LIBRARY)
TestJNI2.cpp
/* OpenSSL headers */
#include "openssl/bio.h"
#include "openssl/ssl.h"
#include "openssl/err.h"
/* Initializing OpenSSL */
void init_openssl(void){
SSL_load_error_strings();
ERR_load_BIO_strings();
OpenSSL_add_all_algorithms();
}
Then when i build with ndk-build always have problems like this
/data/workspace/TestJNI2/jni/TestJNI2.cpp:3:25: error: openssl/bio.h: No such file or directory
/data/workspace/TestJNI2/jni/TestJNI2.cpp:4:25: error: openssl/ssl.h: No such file or directory
/data/workspace/TestJNI2/jni/TestJNI2.cpp:5:25: error: openssl/err.h: No such file or directory
/data/workspace/TestJNI2/jni/TestJNI2.cpp: In function 'void init_openssl()':
/data/workspace/TestJNI2/jni/TestJNI2.cpp:10: error: 'SSL_load_error_strings' was not declared in this scope
/data/workspace/TestJNI2/jni/TestJNI2.cpp:11: error: 'ERR_load_BIO_strings' was not declared in this scope
/data/workspace/TestJNI2/jni/TestJNI2.cpp:12: error: 'OpenSSL_add_all_algorithms' was not declared in this scope
make: *** [/data/workspace/TestJNI2/obj/local/armeabi/objs/security/TestJNI2.o] Error 1
Can anyone help me? Or how to build an example RSA algorthim base on openssl lib?
You should build static libraries for libssl and libcrypto in your script. If you can't, rename these libraries (you can do this after build, while copying to your precompiled directory). The reason is that the system comes with its own (probably different) version of these shared libraries, and the loader will use /system/lib/libssl.so and /system/lib/libcrypto.so instead of your private copies.
Regarding the Android.mk file, I slightly cleaned it up for you (note that I did not change the names of prebuilt LOCAL_MODULEs, but changed the name of LOCAL_MODULE you finally build, because security is, well, too generic and could also happen to match a system library on some device):
LOCAL_PATH := $(call my-dir)
# Prebuilt libssl
include $(CLEAR_VARS)
LOCAL_MODULE := ssl
LOCAL_SRC_FILES := precompiled/libPrivateSsl.so
include $(PREBUILT_SHARED_LIBRARY)
# Prebuilt libcrypto
include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := precompiled/libPrivateCrypto.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := PrivateSecurity
LOCAL_C_INCLUDES := includes
LOCAL_SRC_FILES := TestJNI2.cpp
LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES := ssl crypto
include $(BUILD_SHARED_LIBRARY)
Don't forget that your Java should load the dependencies first:
{
System.loadLibrary("PrivateSsl");
System.loadLibrary("PrivateCrypto");
System.loadLibrary("PrivateSecurity");
}
I'm beginer to Android NDK. I want to build a RSA example base on openssl libary.
You can, but you have to be careful. Here's the reason Alex told you to use static libraries for libssl and libcrypto in your script.
The master Android process is zygote. Its like init in Linux. Zygote loads OpenSSL when its start, and it loads version 0.9.8. If you link against OpenSSL 1.0.1, then you will get mysterious runtime crashes. The crashes are due to the Android loader using the 0.9.8 version of the library (already mapped from Zygote), and not your version of OpenSSL.
You can use a shared object, but your shared object must be a wrapper around the static version of libssl and libcrypto.
If you are not using Android's build system, then you can find additional instructions for building purely from the command line at OpenSSL's wiki. The wiki page includes setting the envrionment and cross compiling. See FIPS Library and Android.
Another thing to watch out for: be sure to build with -mfloat-abi=softfp. The stock OpenSSL misses that when cross compiling. You need it to ensure floats are passed on the stack, and not through floating point registers. Otherwise, all your floats will mysteriously have 0.0f value (like the floats used to estimate entropy in RAND_add).

"undefined reference to" (function) & "in archive is not an object" Android ndk-build

I'll expose my problem quickly. I am trying to port curl on Android and to use it within my app. I built the curl library with the ARM toolchain, configured and made (a couple times to make sure I didn't do nothing wrong the first time).
I then proceeded to put the newly created libcurl.a and my curljni.c into my jni folder, as long as the following Android.mk :
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= libcurl
LOCAL_SRC_FILES := libcurl.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/curl
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := curljni
LOCAL_SRC_FILES := curljni.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/curl
LOCAL_STATIC_LIBRARIES := libcurl
include $(BUILD_SHARED_LIBRARY)
I've been trying a lot of things and I'm pretty sure it looks good now, but whenever I try to build with the ndk-build tool I obtain the following :
Note : curljni.c makes calls to functions within the libcurl library and its easy.h and curl.h files. They are then included in top of the file.
I also tried to ask for the whole library to get loaded into my Android app, using LOCAL_WHOLE_STATIC_LIBRARIES instead of LOCAL_STATIC_LIBRARIES, but without much more success :
Previously :
Downloaded curl.7.28.0
Made a standalone toolchain for ARM 4.6
Fixed several files within curl whose linebreaks were DOS like and needed Unix like (bug in configure) - one of which was depcomp, linked to libcurl_la-file.lo
./configure --host=arm-linux-androidaebi --with-zlib --enable-ipv6
make/make install
Added the resulting libcurl.a from curl\lib.libs
Ok,
Your Problem is that your library libcurl.a is not builded with Android ndk gcc ..
You have done :
$ ./configure --host=arm-linux-androidaebi --with-zlib --enable-ipv6
$ make
$ make install
this will generate a library using your PC gcc ..NOt good .
What i do is to configure open source library l for android using line command (or like you have done):
./configure --build=x86_64-unknown-linux-gnu --host=arm-linux-androideabi --target=arm-linux-androideabi
But then you schould not call make and make install ! .
You have to create an android.mk whinch will compile all source file in your libcurl + your jni file ' curljni.c' and put all in one lib : here an example of Android.mk compiling SQLITE3
###################################################
# SQLITE3
###################################################
include $(CLEAR_VARS)
LOCAL_MODULE := Mysqlite3
MY_LOCAL_SQLITE_SRC := $(LOCAL_PATH)/sqlite/
LOCAL_CPPFLAGS := -g
LOCAL_CPPFLAGS += -I $(MY_LOCAL_SQLITE_SRC)
LOCAL_EXPORT_C_INCLUDES:=$(MY_LOCAL_SQLITE_SRC)
FILE_LIST :=$(wildcard $(MY_LOCAL_SQLITE_SRC)*.c*)
LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%)
# My SQLITE3 JNI FILE
LOCAL_SRC_FILES +=mysqlite_jni.cpp
# include native NDK library liblog and libz
LOCAL_LDLIBS := -llog -lz
include $(BUILD_SHARED_LIBRARY)

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