libevent android编译

ndk目录

/usr/local/android-ndk-r10e

libevent版本

libevent-2.0.22-stable

下载地址   https://github.com/libevent/libevent/archive/release-2.0.22-stable.tar.gz

cd /usr/local/libevent-2.0.22-stable

1. 生成event-config.h

SYSROOT=/usr/local/android-ndk-r10e/platforms/android-8/arch-arm
./configure --host=arm-linux-androideabi CC=/usr/local/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc CFLAGS=--sysroot=$SYSROOT

 make  后会生成 event-config.h 

 2. 如果要在android上使用注意修改

include/event2/event-config.h

//#define _EVENT_HAVE_ISSETUGID 1

Android 下面没有   issetugid 函数

 

evutil_rand.c

在 evutil_secure_rng_add_bytes  之前 加上 #ifdef HAVE_ARC4RANDOM_ADDRANDOM

#ifdef HAVE_ARC4RANDOM_ADDRANDOM 
void
evutil_secure_rng_add_bytes(const char *buf, size_t n)
{
    arc4random_addrandom((unsigned char*)buf,
        n>(size_t)INT_MAX ? INT_MAX : (int)n);
}
#endif

 

3. 配置Android.mk文件

vi Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
SRC_DIR :=  /usr/local/libevent-2.0.22-stable
LOCAL_ARM_MODE := arm
LOCAL_MODULE := libevent
LIB_SRC := ${SRC_DIR}/event.c \
        ${SRC_DIR}/evthread.c \
        ${SRC_DIR}/buffer.c \
        ${SRC_DIR}/bufferevent.c \
        ${SRC_DIR}/bufferevent_filter.c \
        ${SRC_DIR}/bufferevent_pair.c \
        ${SRC_DIR}/listener.c \
        ${SRC_DIR}/bufferevent_ratelim.c \
        ${SRC_DIR}/evmap.c \
        ${SRC_DIR}/log.c \
        ${SRC_DIR}/evutil.c \
        ${SRC_DIR}/evutil_rand.c \
        ${SRC_DIR}/select.c \
        ${SRC_DIR}/poll.c \
        ${SRC_DIR}/epoll.c \
        ${SRC_DIR}/signal.c \
        ${SRC_DIR}/event_tagging.c \
        ${SRC_DIR}/http.c \
        ${SRC_DIR}/evdns.c \
        ${SRC_DIR}/evrpc.c \
        ${SRC_DIR}/bufferevent_sock.c \
        ${SRC_DIR}/evthread_pthread.c

LOCAL_SRC_FILES := $(LIB_SRC)
LOCAL_C_INCLUDES := \
        $(SRC_DIR)/include \
        $(SRC_DIR)/compat

LOCAL_CFLAGS += -static -fPIC
include $(BUILD_STATIC_LIBRARY)

mkdir -pv jni

vi jni/Android.mk

include $(CLEAR_VARS)
include $(APP_PROJECT_PATH)/Android.mk

vi jni/Application.mk

APP_PROJECT_PATH := $(call my-dir)/../

APP_STL:=c++_static   # 根据自己的需要修改
APP_CPPFLAGS := -frtti -std=c++11

APP_ABI := armeabi armeabi-v7a arm64-v8a x86
APP_PLATFORM := android-8

4.编译

ndk-build

 

参考

https://blog.csdn.net/phil_gu/article/details/90478721

https://developer.aliyun.com/article/252861

 

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页