Crypto++ in Android(Build)
Crypto++ Library is a free C++ class library of cryptographic schemes. Crypto++
This covers a lot of cryptographic
In Android, default Java cryptographic API is not covered a lot, and slow a bit.
To use Crypto++, we can
Good Explanation to build as Android NDK shared library is Android NDK Advanced Tutorial
This explanation is for 5.6.1, but 5.6.2 works too.
- Create toolchain to build library
- Download Crypto++ and decompress
- Change GNUMakefile to build for Android
- Add libcryptopp.so to Android Native Project
Please refer Toolchain
This is other my entry.
We need some environment variables, NDK, SYSROOT, CXX, CC
|NDK||Android NDK root||/opt/android/android-ndk-r8|
|SYSROOT||Toolchain architecture root||/opt/android/android-ndk-r8/platforms/android-14/arch-arm|
|CC||gcc command name||arm-linux-androideabi-gcc|
|CXX||g++ command name||arm-linux-androideabi-g++|
Also, add toolchain root to path
To check env vars
Show all env
Build Crypto++ under Android gcc, g++
Crypto++ has already GNUMakefile (Makefile) to build.
But, this is for PC architecture ex.. x86_64.
I tried to build Linux Mint15, problem to build and can use it!
But, our target is Android.
You need to change a bit in GNUMakefile.
ifneq ($(GCC42_OR_LATER),0) ifeq ($(UNAME),Darwin) CXXFLAGS += -arch x86_64 -arch i386 else CXXFLAGS += -march=armv7-a endif endif
This is the part to change. Maybe about 40L I think.
This is architecture part please change from -march=native to armv7-a( if you want to use armv5te), use armv5te.
And remove linker option glibc pthread,… LDFLAGS += -pthread
because Android is enabled pthread by default
This is final style to build libcryptopp.so
libcryptopp.so: $(LIBOBJS) $(CXX) -shared -o $@ $(LIBOBJS) $(LDFLAGS) $(LDLIBS)
Add these flags to build C++ env
CXXFLAGS += -nostdinc++ -I$(NDK)/sources/cxx-stl/stlport/stlport LDFLAGS += -nodefaultlibs -L$(NDK)/sources/cxx-stl/stlport/libs/armeabi LDLIBS += -lstlport_shared -lc -lm -ldl -lgcc
Add following description to wait.h ( header file)
Build command of Crypto++
Finally, Let’s build.
Make does compile all sources and create static library …
After make, build shared library to use for Android(.so)
We can get libcryptopp.so
Android STL has 2 version. STLport and GNU STL
Both doesn’t work when using std:string class.
std:string class was handled as basic_string in.
Android basic_string doesn’t have enough feature
I couldn’t fix it : (