版本:protobuf-3.7.1 + ndk-r18b
1. 生成makefile
export ndk_root=/home/melon/Downloads/android-ndk-r18b-linux-x86_64/android-ndk-r18b
cmake \
-Dprotobuf_BUILD_SHARED_LIBS=OFF \
-Dprotobuf_BUILD_STATIC_LIBS=ON \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-Dprotobuf_BUILD_TESTS=OFF \
-Dprotobuf_BUILD_EXAMPLES=OFF \
-DCMAKE_TOOLCHAIN_FILE=$ndk_root/build/cmake/android.toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=lib \
-DANDROID_NDK=$ndk_root \
-DANDROID_TOOLCHAIN=clang \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_NATIVE_API_LEVEL=16 \
-DANDROID_STL=c++_shared \
-DANDROID_LINKER_FLAGS="-landroid -llog" \
-DANDROID_CPP_FEATURES="rtti exceptions" \
./../protobuf-3.7.1/cmake
2. 编译
cmake --build .
3. 安装
make install