Last active
November 28, 2022 07:51
-
-
Save RamseyK/a7a534ffbda34fff08fb0544dde3baa7 to your computer and use it in GitHub Desktop.
Cross compile protobuf and protobuf-c for Android ARM64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
export NDK_ROOT=/Users/"$(whoami)"/android-sdk/ndk-bundle | |
export ANDROID_NDK=${NDK_ROOT} | |
export ANDROID_NDK_ROOT=${NDK_ROOT} | |
export CXXSTL=$NDK_ROOT/sources/cxx-stl/gnu-libstdc++ | |
export ARCH="arm64-v8a" | |
export CFLAGS="-DANDROID -fpermissive -Wno-format -fPIC -fPIE -pie -g -O2 -I../protobuf/arm64build/include" | |
export LDFLAGS="-Wl,--allow-shlib-undefined -fPIC -fPIE -pie -L$CXXSTL/libs/arm64-v8a/include -static-libstdc++ -L../protobuf/arm64build/lib" | |
export CXXFLAGS="-std=c++03 -Wno-c++11-long-long -Wno-c++11-extensions -I$CXXSTL/include $CFLAGS" | |
export CC="aarch64-linux-android-clang" | |
export CXX="aarch64-linux-android-clang++" | |
export AR="aarch64-linux-android-ar" | |
export RANLIB="aarch64-linux-android-ranlib" | |
export STRIP="aarch64-linux-android-strip --strip-unneeded" | |
export READELF="aarch64-linux-android-readelf" | |
export MAKE="make -j4 CROSS_COMPILE_TARGET=yes" | |
rm -rf arm64build/ | |
rm Makefile.in | |
rm config.in | |
make clean | |
echo "Configuring protobuf-c ..." | |
./autogen.sh | |
./configure --host=aarch64-linux-android --target=aarch64-linux-android --build=x86_64-apple-darwin \ | |
--prefix=$(pwd)/arm64build \ | |
CFLAGS="$CFLAGS" \ | |
LDFAGS="$LDFLAGS" \ | |
CXXFLAGS="$CXXFLAGS" \ | |
protobuf_CXXFLAGS="$CXXFLAGS" \ | |
protobuf_CFLAGS="$CFLAGS" \ | |
protobuf_LIBS="$LDFLAGS" \ | |
ac_cv_c_bigendian=no | |
echo "Making protobuf-c ..." | |
$MAKE | |
echo "Installing protobuf-c to build directory ..." | |
make install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
export NDK_ROOT=/Users/"$(whoami)"/android-sdk/ndk-bundle | |
export ANDROID_NDK=${NDK_ROOT} | |
export ANDROID_NDK_ROOT=${NDK_ROOT} | |
export CXXSTL=$NDK_ROOT/sources/cxx-stl/gnu-libstdc++ | |
export ARCH="arm64-v8a" | |
export CFLAGS="-DANDROID -fpermissive -Wno-format -fPIC -fPIE -pie -g -O2" | |
export LDFLAGS="-Wl,--allow-shlib-undefined -fPIC -fPIE -pie -L$CXXSTL/libs/arm64-v8a/include -static-libstdc++" | |
export CXXFLAGS="-std=c++11 -I$CXXSTL/include $CFLAGS" | |
export CC="aarch64-linux-android-clang" | |
export CXX="aarch64-linux-android-clang++" | |
export AR="aarch64-linux-android-ar" | |
export RANLIB="aarch64-linux-android-ranlib" | |
export STRIP="aarch64-linux-android-strip --strip-unneeded" | |
export READELF="aarch64-linux-android-readelf" | |
export MAKE="make -j4 CROSS_COMPILE_TARGET=yes" | |
rm -rf arm64build/ | |
rm Makefile.in | |
make clean | |
echo "Configuring protobuf ..." | |
./autogen.sh | |
./configure --host=aarch64-linux-android --build=x86_64-apple-darwin \ | |
--with-sysroot=$SYSROOT \ | |
--enable-cross-compile \ | |
--prefix=$(pwd)/arm64build \ | |
--with-protoc=protoc | |
echo "Making protobuf ..." | |
$MAKE | |
echo "Installing protobuf to build directory ..." | |
make install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export NDK_ROOT=/Users/user/android-sdk/ndk-bundle | |
export ANDROID_NDK=${NDK_ROOT} | |
export ANDROID_SDK=/Users/user/android-sdk | |
export ANDROID_API24_TOOLCHAIN=/Users/user/android-arm64-api24-toolchain | |
export SYSROOT=$ANDROID_API24_TOOLCHAIN/sysroot | |
export PATH=/Users/user/android-sdk/platform-tools:$NDK_ROOT:$ANDROID_API24_TOOLCHAIN/bin:$PATH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tried this script to cross-compile protobuf-3.4.1 on ubuntu for arm64(android-api 26) but getting multiple errors about strchr, memchr, strpbrk being undeclared identifiers.