2

How to build Google protobuf (c++ version, https://github.com/google/protobuf/releases/latest ) with Android target?

Eugene Gr. Philippov
  • 1,908
  • 2
  • 23
  • 18
  • Please explain in more detail the purpose of a question with an answer posted in the same second. Especially an answer you describe yourself as unclean. So it obviously is not what the SelfLearner badge is meant for. Was you answer meant as MCVE? Then it should be part of the question. – Yunnosch Jun 27 '17 at 06:00
  • @Yunnosch I spent two days trying to figure the correct sequence and setup. Why do you complain? SO has special interface for posting Q+A pair. What's MCVE? – Eugene Gr. Philippov Jun 27 '17 at 06:09
  • Well that is exactly the information I meant. I think your Q/A pair, with this added explanation is nice. (Though I don't know enough about the topic to vote.) – Yunnosch Jun 27 '17 at 06:11

2 Answers2

2

I compiled protobuf without ndk-build. Here's the script (not very clean but it works):

rm -rf /tmp/protobuf-3.3.0/
tar xzvf ~/Downloads/protobuf-cpp-3.3.0.tar.gz -C /tmp/
cd /tmp/protobuf-3.3.0/
export NDK_ROOT=/home/user/SDKS/ANDROID/NDK/android-ndk-r13b
export SYSROOT=$NDK_ROOT/platforms/android-9/arch-arm
export PREBUILT=$NDK_ROOT/toolchains/arm-linux-androideabi-4.9
export LDFLAGS="--sysroot=$SYSROOT"
export LD="$NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/ld $LDFLAGS"
export LIBS="-llog $NDK_ROOT/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_static.a"
export CPPFLAGS=""
export INCLUDES="-I$NDK_ROOT/sources/cxx-stl/gnu-libstdc++/4.9/include/ -I$NDK_ROOT/platforms/android-9/arch-arm/usr/include/ -I$NDK_ROOT/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include/"
export CXXFLAGS="-march=armv7-a -mfloat-abi=softfp -DGOOGLE_PROTOBUF_NO_RTTI --sysroot=$SYSROOT"
export CCFLAGS="$CXXFLAGS"
export CXX="$PREBUILT/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ $CXXFLAGS"
export CC="$CXX"
./autogen.sh
./configure --host=arm-linux-androideabi --with-sysroot=$SYSROOT --enable-cross-compile --with-protoc=protoc --disable-static --enable-shared CXX="$CXX" CC="$CC" LD="$LD"
make
cp -v /tmp/protobuf-3.3.0/src/.libs/* ~/git/project/build/protobuf_android/
Eugene Gr. Philippov
  • 1,908
  • 2
  • 23
  • 18
  • Very useful, it worked perfect on a Ubuntu x86_64 with version 3.3.2. I spent two days trying to build those libraries for android, and it always broke at `configure` because of: `sched_yield not found`. Just one comment: if you need a static library (.a) instead of a shared one (.so), replace `--disable-static --enable-shared` for `--disable-shared` – Albert Aug 03 '17 at 19:55
0

This is probs overkill since I was using it in another project, so the dependencies are excessive but...

protobuf aarch64/arm Android.mk

Surge1223
  • 91
  • 6