I'm trying to compile libnice (v0.18 to be specific) for Android, but have run into some troubles. How can I compile libnice for Android? I have listed my attempts so far below.
1st Attempt
My first try was using a custom Android.mk makefile but I got an error stating AI_NUMERICHOST undeclared
(adding #include <netdb.h>
did not resolve this and I'm out of ideas here). See my Android.mk below
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := glib
LOCAL_SRC_FILES := lib/libglib-2.0.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gobject
LOCAL_SRC_FILES := lib/libgobject-2.0.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gmodule
LOCAL_SRC_FILES := lib/libgmodule-2.0.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gio
LOCAL_SRC_FILES := lib/libgio-2.0.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gthread
LOCAL_SRC_FILES := lib/libgthread-2.0.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ffi
LOCAL_SRC_FILES := lib/libffi.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := iconv
LOCAL_SRC_FILES := lib/libiconv.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := intl
LOCAL_SRC_FILES := lib/libintl.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := xml2
LOCAL_SRC_FILES := lib/libxml2.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := z
LOCAL_SRC_FILES := lib/libz.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
NICE := libnice-0.1.8
LOCAL_MODULE := ice_jni
LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := glib gobject gmodule gio gthread ffi iconv intl xml2 z
NICE_INCLUDES := $(LOCAL_PATH)/include \
$(LOCAL_PATH)/lib/glib-2.0/include \
$(LOCAL_PATH)/lib/libffi-3.0.13/include \
$(wildcard $(LOCAL_PATH)/include/*) \
$(LOCAL_PATH)/$(NICE)/nice \
$(LOCAL_PATH)/$(NICE)/agent \
$(LOCAL_PATH)/$(NICE)/random \
$(LOCAL_PATH)/$(NICE)/socket \
$(LOCAL_PATH)/$(NICE)/stun
NICE_SRC := $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/$(NICE)/agent/*.c)) \
$(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/$(NICE)/random/*.c)) \
$(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/$(NICE)/socket/*.c)) \
$(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(LOCAL_PATH)/$(NICE)/stun/*.c))
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
$(NICE_INCLUDES)
LOCAL_SRC_FILES := ICE.cpp \
$(NICE_SRC)
include $(BUILD_SHARED_LIBRARY)
The static libraries are copied over from the gstreamer 1.4.1 debug version and are selected in accordance with the guide mentioned below.
2nd Attempt
I then tried to compile a static library referring to this guide, which is again causing trouble:
export PKG_CONFIG_PATH=`pwd`/../gstreamer/lib/pkgconfig
export CFLAGS="--sysroot=`pwd`/../toolchain/sysroot"
./configure --prefix=`pwd`/../build --host=arm-linux-androideabi
This results in the error below. Adding -mthumb
or -marm
to CFLAGS yields a C compiler cannot create executables
error during configure.
stunagent.c: Assembler messages:
stunagent.c:160: Error: no such instruction: `rev %eax,%eax'
stunagent.c:676: Error: no such instruction: `rev16 %ax,%ax'
The mentioned lines do not contain ASM but calls to htons
and ntohl
, so I guess I did something wrong...
I used make_standalone_toolchain
from the NDK using various Android versions to create the toolchain.
Can anybody help? Thanks in advance! ~
FINALLY! This took me way too long. The problem was that libnice creates a
config.h
file during configure which defines some macros (HAVE_NETDB_H
among others). Although I was not able to compile libnice with my toolchain I was able to generate a valid config.h which I could use. After this I had to make some additional adjustments to myAndroid.mk
. I'll post both files below for others in search of answers.(Note: you still need glib. As my project uses gstreamer I was able to use the shared library created by the gstreamer build script which contains glib.)
Cheers!
========================
Android.mk
config.h
(This should not differ across platforms and Android versions. I left the comments in it intentionally for future reference)