为Android编译libnice

为Android编译libnice,android,android-ndk,stun,turn,libnice,Android,Android Ndk,Stun,Turn,Libnice,我试图为Android编译libnice(具体来说是v0.18),但遇到了一些麻烦。如何为Android编译libnice?我在下面列出了我迄今为止的尝试 第一次尝试 我的第一次尝试是使用一个定制的Android.mk makefile,但我得到了一个错误,指出AI_numericost undeclared(添加#include并没有解决这个问题,我在这里没有想法)。请参阅下面的my Android.mk LOCAL_PATH := $(call my-dir) include $(CLE

我试图为Android编译libnice(具体来说是v0.18),但遇到了一些麻烦。如何为Android编译libnice?我在下面列出了我迄今为止的尝试

第一次尝试

我的第一次尝试是使用一个定制的Android.mk makefile,但我得到了一个错误,指出
AI_numericost undeclared
(添加
#include
并没有解决这个问题,我在这里没有想法)。请参阅下面的my Android.mk

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)
静态库是从gstreamer 1.4.1调试版本复制过来的,并根据以下所述进行选择

第二次尝试

然后,我尝试编译一个引用的静态库,这再次导致了问题:

export PKG_CONFIG_PATH=`pwd`/../gstreamer/lib/pkgconfig  
export CFLAGS="--sysroot=`pwd`/../toolchain/sysroot"
./configure --prefix=`pwd`/../build --host=arm-linux-androideabi
这将导致以下错误。将
-mthumb
-marm
添加到CFLAGS会导致
C编译器在配置期间无法创建可执行文件
错误

stunagent.c: Assembler messages:
stunagent.c:160: Error: no such instruction: `rev %eax,%eax'
stunagent.c:676: Error: no such instruction: `rev16 %ax,%ax'
上面提到的行不包含ASM,而是调用
htons
ntohl
,所以我想我做错了什么

我使用NDK中的
make_standalone_工具链
,使用各种Android版本创建工具链

有人能帮忙吗?提前谢谢!
~

终于!这花了我太长时间。问题是libnice在configure期间创建了一个
config.h
文件,该文件定义了一些宏(
HAVE\u NETDB\u h
)。虽然我不能用我的工具链编译libnice,但我能够生成一个有效的config.h,我可以使用它。在此之后,我不得不对我的
Android.mk
做一些额外的调整。我将在下面为其他人发布这两个文件以搜索答案

(注意:您仍然需要glib。由于我的项目使用gstreamer,所以我能够使用由包含glib的gstreamer构建脚本创建的共享库。)

干杯

========================

Android.mk

LOCAL_PATH  := $(call my-dir)

include $(CLEAR_VARS)
NICE                    := libnice-0.1.8
LOCAL_MODULE            := nice_jni
LOCAL_LDLIBS            := -llog 

LOCAL_SHARED_LIBRARIES  := gstreamer_android
LOCAL_CFLAGS            += -DHAVE_CONFIG_H

NICE_DIRS               := $(LOCAL_PATH)/$(NICE)/ \
                            $(LOCAL_PATH)/$(NICE)/agent/ \
                            $(LOCAL_PATH)/$(NICE)/nice/ \
                            $(LOCAL_PATH)/$(NICE)/random/ \
                            $(LOCAL_PATH)/$(NICE)/socket/ \
                            $(LOCAL_PATH)/$(NICE)/stun/ \
                            $(LOCAL_PATH)/$(NICE)/stun/usages/
#                           $(LOCAL_PATH)/$(NICE)/stun/tools/ \

NICE_INCLUDES           := $(NICE_DIRS)
NICE_SRC                := $(filter-out %test.c, $(foreach dir, $(NICE_DIRS), $(patsubst $(LOCAL_PATH)/%, %, $(wildcard $(addsuffix *.c, $(dir)))) ))

LOCAL_C_INCLUDES        := $(NICE_INCLUDES) #add your own headers if needed

LOCAL_SRC_FILES         := [YOUR_SRC_FILES] \
                            $(NICE_SRC)

include $(BUILD_SHARED_LIBRARY)
config.h

(这在不同平台和Android版本之间应该没有区别。我特意在其中留下了评论供将来参考)

/*config.h。由configure从config.h.in生成*/
/*config.h.in。由autoheader从configure.ac生成*/
/*如果有头文件,则定义为1*/
#定义HAVE_ARPA_INET_H 1
/*如果C支持可变长度数组,则定义为1*/
#定义HAVE_C_vararray 1
/*如果有头文件,则定义为1*/
#定义HAVE_DLFCN_H 1
/*GetIFADRS()是否在系统上可用*/
/*#未定义已获得地址*/
/*拥有GUPnP IGD库*/
/*#未定义有#GUPNP*/
/*如果有头文件,则定义为1*/
/*#undef拥有(如果地址)*/
/*如果有头文件,则定义为1*/
#定义有\u INTTYPES\u H 1
/*如果有头文件,则定义为1*/
#定义有\u内存\u H 1
/*如果有头文件,则定义为1*/
#定义HAVE_NETDB_H 1
/*如果有头文件,则定义为1*/
/*#未定义有"净"在"H*/
/*如果有“poll”函数,则定义为1*/
#定义HAVE_POLL 1
/*如果系统具有“size\t”类型,则定义为1*/
#定义有\u大小\u T 1
/*如果系统的类型为“ssize\u t”,则定义为1*/
#定义HAVE_SSIZE_T 1
/*如果stdbool.h符合C99,则定义为1*/
#定义HAVE_STDBOOL_H 1
/*如果有头文件,则定义为1*/
#定义有力1
/*如果有头文件,则定义为1*/
#定义HAVE_STDLIB_H 1
/*如果有头文件,则定义为1*/
#定义HAVE_STRINGS_H 1
/*如果有头文件,则定义为1*/
#定义HAVE_STRING_H 1
/*如果有头文件,则定义为1*/
#定义HAVE_SYS_STAT_H 1
/*如果有头文件,则定义为1*/
#定义系统类型1
/*如果有头文件,则定义为1*/
#定义具有统一的1
/*如果系统的类型为“\u Bool”,则定义为1*/
#定义“拥有”布尔1
/*定义libtool存储已卸载库的子目录。
*/
#定义LT_OBJDIR“.libs/”
/*如果应禁用断言,则定义为1*/
/*#未定义NDEBUG*/
/*公共图书馆职能的实施*/
#定义API_导出
/*包裹名称*/
#定义包“libnice”
/*定义此包的错误报告应发送到的地址*/
#定义包“”错误报告“”
/*定义此包的全名*/
#定义包名称“libnice”
/*定义此包的全名和版本*/
#定义包_字符串“libnice 0.1.8”
/*定义此包的一个符号短名称*/
#定义包名称“libnice”
/*定义此包的主页*/
#定义包的URL“”
/*定义此包的版本*/
#定义包_版本“0.1.8”
/*如果有ANSI C头文件,则定义为1*/
#定义STDC_头1
/*在AIX3、Interix上启用扩展*/
#ifndef\u所有源
#定义所有源1
#恩迪夫
/*在具有GNU扩展的系统上启用GNU扩展*/
#ifndef\u GNU\u源
#定义_GNU_源1
#恩迪夫
/*在Solaris上启用线程扩展*/
#ifndef\u POSIX\u PTHREAD\u语义
#定义_POSIX_PTHREAD_语义1
#恩迪夫
/*在HP NonStop上启用扩展*/
#ifndef\u串联\u源
#定义_串联_源1
#恩迪夫
/*在Solaris上启用常规扩展*/
#ifndef\uuu扩展__
#定义扩展名1
#恩迪夫
/*软件包的版本号*/
#定义版本“0.1.8”
/*定义为“2”以获取GNU/libc警告*/
/*仅当启用了-O1或更多时定义*/
#如果定义了uuu优化uuu&uuuu优化uuu>0
#定义_加强_源2
#恩迪夫
/*如果在MINIX上,则定义为1*/
/*#未定义#MINIX*/
/*如果系统不提供POSIX.1功能,则定义为2
这定义了*/
/*#未定义_POSIX_1_来源*/
/*如果需要,请定义为1,以使“stat”和其他内容正常工作*/
/*#未定义(POSIX)源*/
/*需要在Solaris上获取msg_control和msg_controllen的声明*/
/*#未定义_XOPEN_源*/
/*需要在Solaris上获取msg_control和msg_controllen的声明*/
#定义扩展名1
/*蔑视
/* config.h.  Generated from config.h.in by configure.  */
/* config.h.in.  Generated from configure.ac by autoheader.  */

/* Define to 1 if you have the <arpa/inet.h> header file. */
#define HAVE_ARPA_INET_H 1

/* Define to 1 if C supports variable-length arrays. */
#define HAVE_C_VARARRAYS 1

/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1

/* Whether getifaddrs() is available on the system */
/* #undef HAVE_GETIFADDRS */

/* Have the GUPnP IGD library */
/* #undef HAVE_GUPNP */

/* Define to 1 if you have the <ifaddrs.h> header file. */
/* #undef HAVE_IFADDRS_H */

/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1

/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1

/* Define to 1 if you have the <netdb.h> header file. */
#define HAVE_NETDB_H 1

/* Define to 1 if you have the <net/in.h> header file. */
/* #undef HAVE_NET_IN_H */

/* Define to 1 if you have the `poll' function. */
#define HAVE_POLL 1

/* Define to 1 if the system has the type `size_t'. */
#define HAVE_SIZE_T 1

/* Define to 1 if the system has the type `ssize_t'. */
#define HAVE_SSIZE_T 1

/* Define to 1 if stdbool.h conforms to C99. */
#define HAVE_STDBOOL_H 1

/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1

/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1

/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1

/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1

/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1

/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1

/* Define to 1 if the system has the type `_Bool'. */
#define HAVE__BOOL 1

/* Define to the sub-directory in which libtool stores uninstalled libraries.
   */
#define LT_OBJDIR ".libs/"

/* Define to 1 if assertions should be disabled. */
/* #undef NDEBUG */

/* Public library function implementation */
#define NICEAPI_EXPORT 

/* Name of package */
#define PACKAGE "libnice"

/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""

/* Define to the full name of this package. */
#define PACKAGE_NAME "libnice"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "libnice 0.1.8"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "libnice"

/* Define to the home page for this package. */
#define PACKAGE_URL ""

/* Define to the version of this package. */
#define PACKAGE_VERSION "0.1.8"

/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1

/* Enable extensions on AIX 3, Interix.  */
#ifndef _ALL_SOURCE
# define _ALL_SOURCE 1
#endif
/* Enable GNU extensions on systems that have them.  */
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
#endif
/* Enable threading extensions on Solaris.  */
#ifndef _POSIX_PTHREAD_SEMANTICS
# define _POSIX_PTHREAD_SEMANTICS 1
#endif
/* Enable extensions on HP NonStop.  */
#ifndef _TANDEM_SOURCE
# define _TANDEM_SOURCE 1
#endif
/* Enable general extensions on Solaris.  */
#ifndef __EXTENSIONS__
# define __EXTENSIONS__ 1
#endif


/* Version number of package */
#define VERSION "0.1.8"

/* Define to `2' to get GNU/libc warnings. */
/* Only define if -O1 or more is enabled */
#if defined __OPTIMIZE__ && __OPTIMIZE__ > 0
# define _FORTIFY_SOURCE 2
#endif

/* Define to 1 if on MINIX. */
/* #undef _MINIX */

/* Define to 2 if the system does not provide POSIX.1 features except with
   this defined. */
/* #undef _POSIX_1_SOURCE */

/* Define to 1 if you need to in order for `stat' and other things to work. */
/* #undef _POSIX_SOURCE */

/* Needed to get declarations for msg_control and msg_controllen on Solaris */
/* #undef _XOPEN_SOURCE */

/* Needed to get declarations for msg_control and msg_controllen on Solaris */
#define __EXTENSIONS__ 1

/* Define to the equivalent of the C99 'restrict' keyword, or to
   nothing if this is not supported.  Do not define if restrict is
   supported directly.  */
#define restrict __restrict
/* Work around a bug in Sun C++: it does not support _Restrict or
   __restrict__, even though the corresponding Sun C compiler ends up with
   "#define restrict _Restrict" or "#define restrict __restrict__" in the
   previous line.  Perhaps some future version of Sun C++ will work with
   restrict; if so, hopefully it defines __RESTRICT like Sun C does.  */
#if defined __SUNPRO_CC && !defined __RESTRICT
# define _Restrict
# define __restrict__
#endif