为android编译libsocket的脚本

Posted yuanxiaoping_21cn_com

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为android编译libsocket的脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash
U32=0 #编译64位arm时 U32=0   编译32位arm时 U32=1 其他参数不需要变动
TARGET=android-24
HOST=darwin-x86_64
TOOL=aarch64-linux-android #arm-linux-androideabi  aarch64-linux-android

ARCH=arch-arm64 #arch-arm arch-arm64
if [ $U32 -ne 0 ]; then
    echo "32位arm"
    TOOL=arm-linux-androideabi
    ARCH=arch-arm
fi
TOOLCHAIN=$TOOL-4.9

export NDK_ROOT=/Users/musictom/Library/Android/sdk/ndk-bundle/
export SYSROOT="$NDK_ROOT/platforms/$TARGET/$ARCH"
export CPPFLAGS="-I$NDK_ROOT/platforms/$TARGET/$ARCH/usr/include -I$NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/user/include"
export LDFLAGS="-L$NDK_ROOT/platforms/$TARGET/$ARCH/usr/lib --sysroot=$SYSROOT"

rm -f *.so *.o
$NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/bin/$TOOL-gcc -Wall -fPIC -O2 -c ../c/inet/libinetsocket.c $CPPFLAGS
$NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/bin/$TOOL-gcc -Wall -fPIC -O2 -c ../c/unix/libunixsocket.c $CPPFLAGS
$NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/bin/$TOOL-gcc -shared -o libsocket.so libinetsocket.o libunixsocket.o $LDFLAGS
rm -f *.o

cp *.so $NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/user/lib/
mkdir $NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/user/include/socket
cp ../headers/*.hpp $NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/user/include/socket/
cp ../headers/*.h $NDK_ROOT/toolchains/$TOOLCHAIN/prebuilt/$HOST/user/include/socket/

参考https://github.com/gcesarmza/curl-android-ios/blob/master/curl-compile-scripts/build_Android.sh

以上是关于为android编译libsocket的脚本的主要内容,如果未能解决你的问题,请参考以下文章

错误记录Kotlin 编译报错 ( Class ‘Xxx‘ is not abstract and does not implement abstract member )

Unity编译Android的原理解析和apk打包分析

Android编译系统介绍

Android NDK——源码编译脚本之Makefile 基础语法和Android.mk小结

Android NDK——源码编译脚本之Makefile 基础语法和Android.mk小结

为 Android 编译最新的 OpenSSL