Google protobuf and Android NDK

前端 未结 2 1242
被撕碎了的回忆
被撕碎了的回忆 2021-01-25 07:23

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

相关标签:
2条回答
  • 2021-01-25 08:03

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

    protobuf aarch64/arm Android.mk

    0 讨论(0)
  • 2021-01-25 08:22

    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/
    
    0 讨论(0)
提交回复
热议问题