Build Google Protobuf library for android development. With android ndk stand alone tool chains.
PREFIX=`pwd`/protobuf/android | |
rm -rf ${PREFIX} | |
mkdir ${PREFIX} | |
export NDK=YOUR_NDK_ROOT | |
# 1. Use the tools from the Standalone Toolchain | |
export PATH=YOUR_NDK_STAND_ALONE_TOOL_PATH/bin:$PATH | |
export SYSROOT=YOUR_NDK_STAND_ALONE_TOOL_PATH/sysroot | |
export CC="arm-linux-androideabi-gcc --sysroot $SYSROOT" | |
export CXX="arm-linux-androideabi-g++ --sysroot $SYSROOT" | |
export CXXSTL=$NDK/sources/cxx-stl/gnu-libstdc++/4.6 | |
########################################## | |
# Fetch Protobuf 2.5.0 from source. | |
########################################## | |
( | |
cd /tmp | |
curl http://protobuf.googlecode.com/files/protobuf-2.5.0.tar.gz --output /tmp/protobuf-2.5.0.tar.gz | |
if [ -d /tmp/protobuf-2.5.0 ] | |
then | |
rm -rf /tmp/protobuf-2.5.0 | |
fi | |
tar xvf /tmp/protobuf-2.5.0.tar.gz | |
) | |
cd /tmp/protobuf-2.5.0 | |
mkdir build | |
# 3. Run the configure to target a static library for the ARMv7 ABI | |
# for using protoc, you need to install protoc to your OS first, or use another protoc by path | |
./configure --prefix=$(pwd)/build \ | |
--host=arm-linux-androideabi \ | |
--with-sysroot=$SYSROOT \ | |
--disable-shared \ | |
--enable-cross-compile \ | |
--with-protoc=protoc \ | |
CFLAGS="-march=armv7-a" \ | |
CXXFLAGS="-march=armv7-a -I$CXXSTL/include -I$CXXSTL/libs/armeabi-v7a/include" | |
# 4. Build | |
make && make install | |
# 5. Inspect the library architecture specific information | |
arm-linux-androideabi-readelf -A build/lib/libprotobuf-lite.a | |
cp build/lib/libprotobuf.a $PREFIX/libprotobuf.a | |
cp build/lib/libprotobuf-lite.a $PREFIX/libprotobuf-lite.a |
This comment has been minimized.
This comment has been minimized.
aso123
commented
Apr 12, 2017
Could you please specify a sample environment variable path for sysroot as I don't find such a folder in my ndk of version r10e? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
keithkml commentedApr 17, 2015
Thanks this was very helpful!