android 增加第三方库,在android中增加 第三方库

目前只是在收集资料, 整理验证过后,会再来修改blog.

在android中增加curl

curl是一个著名的开源文件传输协议实现软件,其中包括了HTTP、HTTPS、FTP等多种常用不常用协议的实现。

在curl最新版本的官方源代码中其实已经包括了android的编译文件(Android.mk),不过要想编译通过还需要做一些工作。

我所使用的curl版本是7.20.1,android源代码版本是 eclair 2.1。

首先将curl解压到external目录下,将目录名称改为curl(不改也可以,不过android的习惯是不带版本号,入乡随俗吧)。

(1)首先要创建一个头文件curl_config.h。创建方法在curl/Android.mk文件头部的注释里有说明。根据这个说明运行 configure。

我所使用的命令行如下(我是编译成x86版本的,不过我们的目的只是要生成curl_config.h文件,所以x86还是arm其实是一样的):

ANDROID_ROOT=`realpath ../..` && PATH="$ANDROID_ROOT/prebuilt/linux-x86/toolchain/i686-unknown-linux-gnu-4.2.1/bin:$PATH" ./configure --host=x86-linux CC=i686-unknown-linux-gnu-gcc CPPFLAGS="-I $ANDROID_ROOT/external/curl/include/   -I $ANDROID_ROOT/external/curl   -I $ANDROID_ROOT/out/target/product/eeepc/obj/STATIC_LIBRARIES/libcurl_intermediates   -I $ANDROID_ROOT/system/core/include   -I $ANDROID_ROOT/hardware/libhardware/include   -I $ANDROID_ROOT/hardware/libhardware_legacy/include   -I $ANDROID_ROOT/hardware/ril/include   -I $ANDROID_ROOT/dalvik/libnativehelper/include   -I $ANDROID_ROOT/frameworks/base/include   -I $ANDROID_ROOT/frameworks/base/opengl/include   -I $ANDROID_ROOT/external/skia/include   -I $ANDROID_ROOT/out/target/product/eeepc/obj/include   -I $ANDROID_ROOT/bionic/libc/arch-x86/include   -I $ANDROID_ROOT/bionic/libc/include   -I $ANDROID_ROOT/bionic/libstdc++/include   -I $ANDROID_ROOT/bionic/libc/kernel/common   -I $ANDROID_ROOT/bionic/libc/kernel/arch-x86   -I $ANDROID_ROOT/bionic/libm/include   -I $ANDROID_ROOT/bionic/libm/include/i387   -I $ANDROID_ROOT/bionic/libthread_db/include -I $ANDROID_ROOT/external/openssl/include" CFLAGS="-fno-exceptions -Wno-multichar -march=i686 -m32 -fPIC -include $ANDROID_ROOT/system/core/include/arch/target_linux-x86/AndroidConfig.h -m32 -DANDROID -fmessage-length=0 -fno-strict-aliasing -Wno-unused -Winit-self -Wpointer-arith -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wpointer-arith -Wwrite-strings -Wunused -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wno-long-long -Wfloat-equal -Wno-multichar -Wsign-compare -Wno-format-nonliteral -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement -Wno-system-headers" LIB="$ANDROID_ROOT/prebuilt/linux-x86/toolchain/i686-unknown-linux-gnu-4.2.1/lib/gcc/i686-unknown-linux-gnu/4.2.1/libgcc.a $ANDROID_ROOT/prebuilt/linux-x86/toolchain/i686-unknown-linux-gnu-4.2.1/lib/gcc/i686-unknown-linux-gnu/4.2.1/crtbegin.o $ANDROID_ROOT/prebuilt/linux-x86/toolchain/i686-unknown-linux-gnu-4.2.1/lib/gcc/i686-unknown-linux-gnu/4.2.1/crtend.o"

(2) configure找不到openssl,所以所生成的配置文件是不使用openssl的。要想使用ssl,需要手动修改 lib/curl_config.h和src/curl_config.h,打开宏定义HAVE_LIBSSL、 HAVE_OPENSSL_CRYPTO_H、HAVE_OPENSSL_ERR_H、HAVE_OPENSSL_PEM_H、 HAVE_OPENSSL_PKCS12_H、HAVE_OPENSSL_RSA_H、HAVE_OPENSSL_SSL_H、 HAVE_OPENSSL_X509_H、USE_OPENSSL、USE_SSLEAY(但是注意android没有编译openssl中的 engine,因此不要打开宏定义HAVE_OPENSSL_ENGINE_H),同时注释掉宏定义HAVE_MALLOC_H和HAVE_IOCTL,这两个宏定义在Android_config.h中有定义,不注释的话在编译过程中会有很多警告(但是能正确编译通过)

(3)修改curl/Android.mk文件,在LOCAL_C_INCLUDES变量的值中增加external/openssl/include,在 LOCAL_SYSTEM_SHARED_LIBRARIES变量的值中增加 libssl libz libcrypto。

好了现在可以编译了:

make curl ONE_SHOT_MAKEFILE=external/curl/Android.mk TARGET_PRODUCT=<...>

不过上述Android.mk文件会将libcurl编译为静态库,要想编译为动态库还需要修改一下Android.mk文件

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

移植wireless tools 到android

1.      从www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html 下载wireless_tools.30.pre8.tar.gz, 此版本支持non-ASCII char in ESSID

2.      解压到mydroid/external/wireless-tools目录

3.      创建Android.mk,内容如下

LOCAL_PATH:= $(call my-dir)

################## build iwlib ###################

include $(CLEAR_VARS)

LOCAL_SRC_FILES := iwlib.c

LOCAL_CFLAGS += -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Winline -MMD -fPIC

LOCAL_MODULE:= libiw

LOCAL_STATIC_LIBRARIES := libcutils libc libm

include $(BUILD_STATIC_LIBRARY)

################## build iwconfig ###################

include $(CLEAR_VARS)

LOCAL_SRC_FILES := iwconfig.c

LOCAL_CFLAGS += -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Winline -MMD -fPIC

LOCAL_MODULE:= iwconfig

LOCAL_STATIC_LIBRARIES := libcutils libc libm libiw

#LOCAL_FORCE_STATIC_EXECUTABLE := true

LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) # install to system/xbin

#LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)

#LOCAL_MODULE_TAGS := eng user

include $(BUILD_EXECUTABLE)

################## build iwlist ###################

include $(CLEAR_VARS)

LOCAL_SRC_FILES := iwlist.c iwlib.h

LOCAL_CFLAGS += -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual -Winline -MMD -fPIC

LOCAL_MODULE:= iwlist

LOCAL_STATIC_LIBRARIES := libcutils libc libm libiw

#LOCAL_FORCE_STATIC_EXECUTABLE := true

LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) # install to system/xbin

#LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)

#LOCAL_MODULE_TAGS := eng user

include $(BUILD_EXECUTABLE)

4.      修改

将wireless.22.h 更名为wireless.h

修改ifrename.c 增加getline的函数,代码可以从external/genext2fs/genext2fs.c中获得

修改iwlib.h,将#include 改为#include

5.      编译

***首先编译libm***这一点是按照网上其他例子做不成功的关键

$cd mydroid/bionic/libm

$source build/envsetup.sh

$mm

$cd mydroid/external/wireless-tools

$mm

下面是编译成功的输出

fisher@fisher-desktop:~/android/external/wireless_tools.30$ mm

make: Entering directory `/home/fisher/android'

build/core/product_config.mk:261: WARNING: adding test OTA key

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

TARGET_PRODUCT=generic

TARGET_BUILD_VARIANT=eng

TARGET_SIMULATOR=

TARGET_BUILD_TYPE=release

TARGET_ARCH=arm

HOST_ARCH=x86

HOST_OS=linux

HOST_BUILD_TYPE=release

BUILD_ID=

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

target thumb C: libiw <= /home/fisher/android/external/wireless_tools.30/iwlib.c

In file included from /home/fisher/android/external/wireless_tools.30/iwlib.h:27,

from /home/fisher/android/external/wireless_tools.30/iwlib.c:14:

bionic/libc/include/stdlib.h:84: warning: declaration of 'abs' shadows a built-in function

bionic/libc/include/stdlib.h:88: warning: declaration of 'labs' shadows a built-in function

bionic/libc/include/stdlib.h:92: warning: declaration of 'llabs' shadows a built-in function

target StaticLib: libiw (out/target/product/generic/obj/STATIC_LIBRARIES/libiw_intermediates/libiw.a)

target Executable: iwconfig (out/target/product/generic/obj/EXECUTABLES/iwconfig_intermediates/LINKED/iwconfig)

target Non-prelinked: iwconfig (out/target/product/generic/symbols/system/bin/iwconfig)

target Strip: iwconfig (out/target/product/generic/obj/EXECUTABLES/iwconfig_intermediates/iwconfig)

target thumb C: iwlist <= /home/fisher/android/external/wireless_tools.30/iwlist.c

In file included from /home/fisher/android/external/wireless_tools.30/iwlib.h:27,

from /home/fisher/android/external/wireless_tools.30/iwlist.c:14:

bionic/libc/include/stdlib.h:84: warning: declaration of 'abs' shadows a built-in function

bionic/libc/include/stdlib.h:88: warning: declaration of 'labs' shadows a built-in function

bionic/libc/include/stdlib.h:92: warning: declaration of 'llabs' shadows a built-in function

target Executable: iwlist (out/target/product/generic/obj/EXECUTABLES/iwlist_intermediates/LINKED/iwlist)

target Non-prelinked: iwlist (out/target/product/generic/symbols/system/bin/iwlist)

target Strip: iwlist (out/target/product/generic/obj/EXECUTABLES/iwlist_intermediates/iwlist)

Install: out/target/product/generic/system/xbin/iwconfig

Install: out/target/product/generic/system/xbin/iwlist

Finding NOTICE files: out/target/product/generic/obj/NOTICE_FILES/hash-timestamp

Combining NOTICE files: out/target/product/generic/obj/NOTICE.html

gzip -c out/target/product/generic/obj/NOTICE.html > out/target/product/generic/obj/NOTICE.html.gz

make: Leaving directory `/home/fisher/android'

fisher@fisher-desktop:~/android/external/wireless_tools.30$

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值