1. 下載 libevent 2.1.8 版本android
2. 先在 win10 上用 wsl ubuntu 編譯 libeventgit
3. 在 wsl 上,準備須要的編譯環境github
sudo apt-get install automake
sudo apt-get install autoconf
sudo apt-get install libtoolubuntu
4. 在livevent目錄下運行 autogen.sh windows
./autogen.shdom
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I m4
autoreconf: configure.ac: tracing
autoreconf: running: libtoolize --copy --force
libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
autoreconf: running: /usr/bin/autoconf --force
autoreconf: running: /usr/bin/autoheader --force
autoreconf: running: automake --add-missing --copy --force-missing
configure.ac:25: installing './compile'
configure.ac:13: installing './missing'
Makefile.am: installing './depcomp'
autoreconf: Leaving directory `.'ide
5. ./configureui
6. makec++11
至此在 wsl ubuntu 上編譯libevent已經完成了
下面,就須要在android ndk 環境下編譯
1. 在windows上,下載最新版本的ndk
2. 編寫 Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_MODULE := libevent
LIB_SRC := event.c \
evthread.c \
buffer.c \
bufferevent.c \
bufferevent_filter.c \
bufferevent_pair.c \
listener.c \
bufferevent_ratelim.c \
evmap.c \
log.c \
evutil.c \
evutil_rand.c \
select.c \
poll.c \
epoll.c \
signal.c \
event_tagging.c \
http.c \
evdns.c \
evrpc.c \
bufferevent_sock.cLOCAL_SRC_FILES := $(LIB_SRC)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include \
$(LOCAL_PATH)/compat
LOCAL_CFLAGS += -pie -fPIE -static -fPIC
include $(BUILD_STATIC_LIBRARY)
3. 編譯 Application.mk
APP_STL := c++_static
APP_CPPFLAGS := -frtti -std=c++11
APP_ABI := armeabi-v7a arm64-v8a x86
#APP_ABI := armeabi-v7a
4. 調用 ndk-build.cmd 就能夠編譯了
編譯過程當中遇到的問題, 須要修改 ./include/event2/event-config.h 中的定義
1. error: 'sys/sysctl.h' file not found
註釋定義 #define EVENT__HAVE_SYS_SYSCTL_H 1
2. error: static declaration of 'arc4random_addrandom' follows non-static declaration
增長定義 #define EVENT__HAVE_ARC4RANDOM 1
3. error: use of undeclared identifier 'fd_mask'
註釋定義 #define EVENT__HAVE_FD_MASK 1
4. error: 'sys/timerfd.h' file not found
註釋定義 #define EVENT__HAVE_SYS_TIMERFD_H 1
5. error: use of undeclared identifier 'EPOLL_CLOEXEC'
註釋定義 #define EVENT__HAVE_EPOLL_CREATE1 1
基本上就對event-config.h中的一些配置作調整就能夠在ndk環境當中編譯了,很是簡單!