1. 下载并解压最新的代码pjproject-2.10.tar.gz;
2. 设置编译NDK路径,例如:
export ANDROID_NDK_ROOT=/Users/everglow/Library/Android/sdk/ndk/21.0.6113669
3. 创建config_site.h并放到路径pjlib/include/pj/下
#define PJ_CONFIG_ANDROID 1
#include <pj/config_site_sample.h>
4. 编辑pjlib/include/pj/config.h文件:
diff -Naur pjproject-2.10~/pjlib/include/pj/config.h pjproject-2.10/pjlib/include/pj/config.h
--- pjproject-2.10~/pjlib/include/pj/config.h 2020-02-14 17:48:27.000000000 +0800
+++ pjproject-2.10/pjlib/include/pj/config.h 2020-02-26 16:17:08.391915999 +0800
@@ -255,15 +255,17 @@
# define PJ_IS_LITTLE_ENDIAN 0
# define PJ_IS_BIG_ENDIAN 1
-#elif defined(ARM) || defined(_ARM_) || defined(__arm__) || defined(_M_ARM)
+#elif defined(ARM) || defined(_ARM_) || defined(__arm__) || defined(_M_ARM) || defined(__aarch64__)
# define PJ_HAS_PENTIUM 0
+# define PJ_IS_LITTLE_ENDIAN 1
+# define PJ_IS_BIG_ENDIAN 0
/*
* ARM, bi-endian, so raise error if endianness is not configured
*/
# if !PJ_IS_LITTLE_ENDIAN && !PJ_IS_BIG_ENDIAN
# error Endianness must be declared for this processor
# endif
-# if defined (PJ_M_ARMV7) || defined(ARMV7)
+# if defined (PJ_M_ARMV7) || defined(ARMV7) || defined(__aarch64__)
# undef PJ_M_ARMV7
# define PJ_M_ARM7 1
# define PJ_M_NAME "armv7"
5. make configuration,这里需要指定sdk版本和支持的abi('armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'),例如:
APP_PLATFORM=android-23 TARGET_ABI=arm64-v8a ./configure-android --use-ndk-cflags --enable-static --disable-resample --disable-sound --disable-video --disable-small-filter --disable-large-filter --disable-speex-aec --disable-g711-codec --disable-l16-codec --disable-gsm-codec --disable-g722-codec --disable-g7221-codec --disable-speex-codec --disable-ilbc-codec --disable-sdl --disable-ffmpeg --disable-v4l2 --disable-openh264
6. make pjsip
make dep && make -j$(nproc)
7. 输出编译后的文件:
mkdir out
make install DESTDIR=$(pwd)/out
cd ./out/usr/local/lib
for i in *.a; do mv "$i" "${i//-aarch64-unknown-linux-android}"; done
8. 在路径./out/usr/local/include中的头文件和./out/usr/local/lib/*.a静态库文件就是我们针对安卓特定abi编译出来的pj版本。
9. 引入项目中:
(1)将include的头文件放到main/jni/include/pj-2.10/下;
(2)将不同abi版本的静态库文件放到main/jni/lib/${abiType} 下(abiType是'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64');
(3)修改Android.mk文件,按需链接对应的静态库文件,引入头文件:
PJSIP_VER=2.10
LOCAL_CFLAGS := \
-DMG_WEBSOCKET_PING_INTERVAL_SECONDS=11 \
-DMG_ENABLE_HTTP=1 \
-DMG_ENABLE_HTTP_WEBSOCKET=1 \
-DMG_ENABLE_BROADCAST=1 \
-DMG_ENABLE_SSL=1 \
-DPJ_DEBUG=1 \
-DPJ_IS_BIG_ENDIAN=0 \
-DPJ_IS_LITTLE_ENDIAN=1 \
-DPJ_HAS_PENTIUM=0 \
-DLTUN_LIB \
-DZLOG \
-I$(LOCAL_PATH)/include \
-I$(LOCAL_PATH)/include/pj-$(PJSIP_VER) \ <-- 引入头文件
-I$(LOCAL_PATH)/cJSON \
-I$(LOCAL_PATH)/uthash/src \
-I$(LOCAL_PATH)/libzlog/src \
-I$(LOCAL_PATH)/libltun \
-I$(LOCAL_PATH)/libev \
-I$(LOCAL_PATH)/mongoose \
-I$(LOCAL_PATH)/libp2p \
-I$(LOCAL_PATH)/include/openssl -g
LOCAL_LDFLAGS += \
$(LOCAL_PATH)/lib/$(TARGET_ARCH_ABI)/pj-$(PJSIP_VER)/libpjnath.a \
$(LOCAL_PATH)/lib/$(TARGET_ARCH_ABI)/pj-$(PJSIP_VER)/libpjlib-util.a \
$(LOCAL_PATH)/lib/$(TARGET_ARCH_ABI)/pj-$(PJSIP_VER)/libpj.a \