- Ubuntu 18.02
- Android NDK 20.0.5594570
- Protobuf v3.12.2
- Language C++ / Java
Use clang:
${ANDROID_NDK_HOME}/build/tools/make-standalone-toolchain.sh \
--arch=arm \
--platform=android-28 \
--toolchain=arm-linux-android-clang5.0 \
--install-dir=$HOME/Android/arm-28-toolchain-clang \
--use-llvm \
--stl=libc++
This generates an arm-28 toolchain under Android
git clone --recurse--submodules https://github.com/protocolbuffers/protobuf.git
cd protobuf
git checkout v3.12.2
./autogen.sh
mkdir build && cd build
vi build-protobuf-android.sh
wherebuild-protobuf-android.sh
export PREFIX=$HOME/Android/andrc/protobuf-3.12.2/
export PATH=$HOME/Android/arm-28-toolchain-clang/bin:$PATH
export SYSROOT=$HOME/Android/arm-28-toolchain-clang/sysroot
export CC="arm-linux-androideabi-clang --sysroot $SYSROOT"
export CXX="arm-linux-androideabi-clang++ --sysroot $SYSROOT"
../configure \
--prefix=$PREFIX \
--host=arm-linux-androideabi \
--with-sysroot="${SYSROOT}" \
--enable-shared \
--enable-cross-compile \
--with-protoc=protoc \
CFLAGS="-march=armv7-a -D__ANDROID_API__=29" \
CXXFLAGS="-frtti -fexceptions -fPIC -march=armv7-a -D__ANDROID_API__=29" \
LIBS="-llog -lz -lc++_static"
make -j 8
make install
Notice!# (I) Need to manually add ./google/protobuf/.libs/descriptor.pb.o to get protoc to link
/bin/bash ../libtool --tag=CXX --mode=link clang++ -pthread -DHAVE_PTHREAD=1 -DHAVE_ZLIB=1 -Wall -Wno-sign-compare -O2 -g -std=c++11 -DNDEBUG -pthread -o protoc google/protobuf/compiler/main.o libprotobuf.la libprotoc.la ./google/protobuf/.libs/descriptor.pb.o -lz
- copy .a/.so and include to
third_party - write and generate
.protofor cpp use
- In project's
build.gradleadd
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
- In app's
build.gradleon the top, addapply plugin: 'com.google.protobuf'on the dependencies, add
implementation 'com.google.protobuf:protobuf-lite:3.0.0'
then
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
javalite {
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
remove java
}
task.plugins {
javalite { }
}
}
}
}
I do as the article say.

In S2:Build Protobuf ,I generate the libprotobuf.so file. When I add it into my android project and compile, it gets an error :
"/libs/protobuf/libprotobuf.so: error adding symbols: File in wrong format", which means the so file's format is wrong.
But when I try to print the format of libprotobuf.so,
I think the format is correct, but why I meet such a error?
thanks for answer