NDKr16b编译protobuf 3.5.1 方法
独立工具链编译方法,请看 https://blog.youkuaiyun.com/qq_28386947/article/details/105745620
上次我们说到ndkr16b编译protobuf3.5.1以上版本会报以下错:
undefined reference to 'scc_info_FileDescriptorProto_google_2fprotobuf_2fdescriptor_2eproto
那如何解决呢。这次我们用cmake的方法交叉编译protbuf3.8.0或任何版本。
目前NDK的最高版本不支持独立工具链,但都会支持cmake编译,以下是编译方法。
1、NDK编译protobuf 3.8.0
编译Android版protobuf前,先确保已经编译安装好linux版protobuf
cd ~/Android
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git checkout v3.8.0
cd cmake
输入以下参数:
cmake -DCMAKE_TOOLCHAIN_FILE=/home/aicrobo/Documents/android-ndk-r16b/build/cmake/android.toolchain.cmake -DANDROID_ABI=armeabi-v7a \
-DANDROID_NATIVE_API_LEVEL=21 \
-DCMAKE_BUILD_TYPE=Release\
-DANDROID_TOOLCHAIN=clang -Dprotobuf_BUILD_TESTS=OFF \
-Dprotobuf_BUILD_SHARED_LIBS=ON
编译生成.so文件在protobuf cmake中。
说一下ndk的重要参数吧:
DANDROID_NATIVE_API_LEVEL 是你ndk API 的多
Dprotobuf_BUILD_SHARED_LIBS ON表示动态库 生成.so文件。
2、编译linux版本protobuf 必须!!在使用ndk之前 ,必须有linux版本的protobuf
//创建protobuf的目录
//git clone protobuf
mkdir $HOME/Android/NDK/google
cd $HOME/Android/NDK/google
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git submodule update --init --recursive
#检查你的proto版本号 别看错了
git checkout -b v3.5.2 v3.5.2
构建 (x86) 版本protobuf 库和构建器(protoc)
sudo apt-get install curl autoconf libtool build-essential g++
#在proto根目录
./autogen.sh
mkdir x86_build
cd x86_build
../configure --prefix=$HOME/Android/NDK/google/x86_pb_install
make install –j8
cd ..
库文件在: $HOME/Android/NDK/google/x86_pb_install/lib
protoc 文件在: $HOME/Android/NDK/google/x86_pb_install/bin
包含的头文件在: $HOME/Android/NDK/google/x86_pb_install/include