Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 469|回复: 0

开发交流:Android: 正则表达式pcre在Android下的移植

[复制链接]

该用户从未签到

发表于 2011-10-24 10:24:03 | 显示全部楼层 |阅读模式
因为项目需要在android的NDK开发中使用pcre正则表达式库,而android系统中并没有自带该库,所以就得另外移植了, 下面是移植的详细步骤:


1. 下载pcre源码,可以到http://sourceforge.net/projects/pcre/下载源码。
我这里使用的是pcre-7.8.tar.gz 。

2. 将pcre-7.8 的源码拷贝至android源码树下的external/pcre目录下。

3. 将下面的Android.mk文件拷贝到external/pcre目录下。
Android.mk:
#

02

#  Android makefile for libpcre

03

#

04

#  This makefile generates libpcre.a, pcregrep and pcre.h ONLY.

05

#  It should be amended to build libpcreposix.a, libpcrecpp.a

06

#  and tests.

07



08



09

LOCAL_PATH := $(call my-dir)

10



11

###

12

### Build libpcre.a and pcre.h

13

###

14



15

include $(CLEAR_VARS)

16



17

#step 1:

18

# to generate the files  config.h pcre.h pcre_chartables.c

19

#

20

GEN := $(LOCAL_PATH)/config.h

21

$(GEN): $(LOCAL_PATH)/config.h.generic

22

    $(hide) cp $(LOCAL_PATH)/config.h.generic $@

23

LOCAL_GENERATED_SOURCES += $(GEN)

24



25

GEN := $(LOCAL_PATH)/pcre.h

26

$(GEN): $(LOCAL_PATH)/pcre.h.generic

27

    $(hide) cp $(LOCAL_PATH)/pcre.h.generic $@

28

LOCAL_GENERATED_SOURCES += $(GEN)

29



30

GEN := $(LOCAL_PATH)/pcre_chartables.c

31

$(GEN): $(LOCAL_PATH)/pcre_chartables.c.dist

32

    $(hide) cp $(LOCAL_PATH)/pcre_chartables.c.dist $@

33

LOCAL_GENERATED_SOURCES += $(GEN)

34



35

#step 2:

36

#clear the vars generated by the step 1

37

#

38

include $(CLEAR_VARS)

39



40

LOCAL_SRC_FILES :=  \

41

  pcre_compile.c \

42

  pcre_config.c \

43

  pcre_dfa_exec.c \

44

  pcre_exec.c \

45

  pcre_fullinfo.c \

46

  pcre_get.c \

47

  pcre_globals.c \

48

  pcre_info.c \

49

  pcre_internal.h \

50

  pcre_maketables.c \

51

  pcre_newline.c \

52

  pcre_ord2utf8.c \

53

  pcre_refcount.c \

54

  pcre_study.c \

55

  pcre_tables.c \

56

  pcre_try_flipped.c \

57

  pcre_ucd.c \

58

  pcre_valid_utf8.c \

59

  pcre_version.c \

60

  pcre_xclass.c \

61

  pcre_chartables.c \

62

  ucp.h \

63

  pcre.h \

64

  config.h

65



66

#copy the pcre.h to out/target/product/generic/obj/include/libpcre

67

#

68

LOCAL_COPY_HEADERS := pcre.h

69

LOCAL_COPY_HEADERS_TO := libpcre

70



71

LOCAL_CFLAGS += -O3 -I. -DHAVE_CONFIG_H

72



73

LOCAL_MODULE := libpcre

74

LOCAL_MODULE_CLASS := STATIC_LIBRARIES

75

LOCAL_PRELINK_MODULE := false

76



77

include $(BUILD_STATIC_LIBRARY)

78



79

###

80

### Build pcregrep

81

###

82



83

include $(CLEAR_VARS)

84



85

LOCAL_MODULE := pcregrep

86

LOCAL_SRC_FILES := pcregrep.c

87

LOCAL_CFLAGS += -O3 -I. -DHAVE_CONFIG_H

88

LOCAL_STATIC_LIBRARIES := libpcre

89



90

include $(BUILD_EXECUTABLE)
复制代码4. cd 到 android的源码树的根目录下,输入命令: . build/envsetup.sh

chooseproduct

mmm external/pcre
复制代码从下面的log可以看到生成了libpcre.a库: make: Entering directory `/home/braincol/workspace/android/android_build/android_sdk_froyo'

Header: out/target/product/generic/obj/include/libpcre/pcre.h

target thumb C: pcregrep <= external/pcre/pcregrep.c

target thumb C: libpcre <= external/pcre/pcre_compile.c

target thumb C: libpcre <= external/pcre/pcre_config.c

target thumb C: libpcre <= external/pcre/pcre_dfa_exec.c

target thumb C: libpcre <= external/pcre/pcre_exec.c

target thumb C: libpcre <= external/pcre/pcre_fullinfo.c

target thumb C: libpcre <= external/pcre/pcre_get.c

target thumb C: libpcre <= external/pcre/pcre_globals.c

target thumb C: libpcre <= external/pcre/pcre_info.c

target thumb C: libpcre <= external/pcre/pcre_maketables.c

target thumb C: libpcre <= external/pcre/pcre_newline.c

target thumb C: libpcre <= external/pcre/pcre_ord2utf8.c

target thumb C: libpcre <= external/pcre/pcre_refcount.c

target thumb C: libpcre <= external/pcre/pcre_study.c

target thumb C: libpcre <= external/pcre/pcre_tables.c

target thumb C: libpcre <= external/pcre/pcre_try_flipped.c

target thumb C: libpcre <= external/pcre/pcre_ucd.c

target thumb C: libpcre <= external/pcre/pcre_valid_utf8.c

target thumb C: libpcre <= external/pcre/pcre_version.c

target thumb C: libpcre <= external/pcre/pcre_xclass.c

target thumb C: libpcre <= external/pcre/pcre_chartables.c

target StaticLib: libpcre (out/target/product/generic/obj/STATIC_LIBRARIES/libpcre_intermediates/libpcre.a)

target Executable: pcregrep (out/target/product/generic/obj/EXECUTABLES/pcregrep_intermediates/LINKED/pcregrep)

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

target Strip: pcregrep (out/target/product/generic/obj/EXECUTABLES/pcregrep_intermediates/pcregrep)

Install: out/target/product/generic/system/bin/pcregrep

make: Leaving directory `/home/braincol/workspace/android/android_build/android_sdk_froyo'


复制代码然后只要把libpcre.a库和头文件pcre.h拷贝到你的android应用工程中,然后就可以在ndk中使用这个pcre库了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

GMT+8, 2025-1-11 02:18 , Processed in 0.364301 second(s), 46 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表