Hybrid System Hybrid System - 6 months ago 93
Android Question

Include Crypto++ Library in Android Project via NDK

I am trying to include Crypto++ (http://www.cryptopp.com/) in an Android NDK project. I want to be able to call Crypto++ member functions from the C++ portion of my code. I thought I could just include the headers and source from Crypto++ in my C++ code but I can't seem to get it to work.

My C++ file looks like this:

#include <jni.h>
#include "cryptopp/modes.h"
#include "cryptopp/aes.h"
using namespace CryptoPP;
...


with all of the Crypto++ headers and source files in the cryptopp subdirectory.

Initially I received many compile errors since the standard C++ libraries were not being found, but I fixed that by adding Application.mk with the following line:

APP_STL := stlport_static


Compiling with ndk-build (both the standard and crystax versions) gives me the following error:

ABI='armeabi'
ABI='armeabi-v7a'
ABI='x86'
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : ndk-tests-cpp <= ndk-tests.cpp
In file included from jni/cryptopp/modes.h:7,
from jni/ndk-tests.cpp:2:
jni/cryptopp/cryptlib.h: In static member function 'static void CryptoPP::NameValuePairs::ThrowIfTypeMismatch(const char*, const std::type_info&, const std::type_info&)':
jni/cryptopp/cryptlib.h:291: error: exception handling disabled, use -fexceptions to enable
make: *** [obj/local/armeabi/objs-debug/ndk-tests-cpp/ndk-tests.o] Error 1


I have never included an external library in an NDK project before - maybe I am just overlooking something basic.

Answer

You have to enable exceptions for your Android project. Try to include these lines into your Applications.mk:

APP_CPPFLAGS += -frtti 
APP_CPPFLAGS += -fexceptions
Comments