For game development, protobuf is very useful for network message protocal. For mobile android platform, we need the libs for android. But we can not find the tutorial about the build step for android platform. Here I show a way about this.
You can download and install android studio. Then install the sdk and ndk for you need.
It’s recommended to create a standalone toolchain for building protobuf. This toolchain will be specific to the Android API level and architecture you want to target.
python $NDK_ROOT/build/tools/make_standalone_toolchain.py --arch arm64 --api 21 --install-dir /path/to/standalone-toolchain
Replace /path/to/standalone-toolchain with the directory where you want to install the standalone toolchain.
If you created a standalone toolchain, set the following environment variables:
export PATH=/path/to/standalone-toolchain/bin:$PATH
export CC=arm64-linux-android21-clang
export CXX=arm64-linux-android21-clang++
Adjust the paths and filenames based on your standalone toolchain and the Android API level you are targeting.
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git submodule update --init --recursive
./autogen.sh
./configure --host=arm-linux-androideabi --with-sysroot=/path/to/standalone-toolchain/sysroot
make
You can set host as you need.
- arm: arm-linux-androideabi
- arm64: aarch64-linux-android
- x86: i686-linux-android
- x86_64: x86_64-linux-android
After successfully building protobuf, you can install it to a specific location or directly copy the necessary files to your Android project.