android 编译 icu,使用NDK构建ICU

博主尝试为Android支持实施ICU库,用NDK编译ICU源,将其放在jni位置并在Android.mk文件添加相关内容。但在Windows机器上构建时遇到诸多错误,如找不到文件、无法使用typeid等,还展示了jni目录中主要Android.mk文件内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在过去的几天里,我一直在努力弄清楚如何为Android支持实施ICU库。 我坚持不懈,试图用NDK编译ICU源。 我从这里得到它们: https : //android.googlesource.com/platform/external/icu/

我把它放在我的jni位置并在我的Android.mk文件中添加了这一行:include $(call all-subdir-makefiles)

并添加到本地标志:

-DSQLITE_ENABLE_ICU

我在尝试构建它时遇到了很多错误(在Windows机器上)。 这是我的输出:

c:/ndk/build/core/build-binary.mk:457: warning: overriding commands for target ` "----my android project location----"//obj/local/armeabi/objs/icui1 8n/smpdtfst.o' c:/ndk/build/core/build-binary.mk:457: warning: ignoring old commands for target `"----my android project location----"//obj/local/armeabi/objs/icu i18n/smpdtfst.o' c:/ndk/build/core/build-binary.mk:457: warning: overriding commands for target ` "----my android project location----"//obj/local/armeabi/objs/icui1 8n_static/smpdtfst.o' c:/ndk/build/core/build-binary.mk:457: warning: ignoring old commands for target `"----my android project location----"//obj/local/armeabi/objs/icu i18n_static/smpdtfst.o' [armeabi] Compile thumb : icui18n <= decContext.c [armeabi] Compile thumb : icui18n <= ucln_in.c [armeabi] Compile thumb : icui18n <= ulocdata.c [armeabi] Compile++ thumb: icui18n <= indiancal.cpp [armeabi] Compile++ thumb: icui18n <= dtptngen.cpp [armeabi] Compile thumb : icui18n <= decNumber.c [armeabi] Compile thumb : icui18n <= utmscale.c [armeabi] Compile++ thumb: icui18n <= dtrule.cpp In file included from "----my android project location----"//jni/ic u/icu4c/source/i18n/../common/unicode/unistr.h:31:0, from "----my android project location----"//jni/ic u/icu4c/source/i18n/../common/unicode/locid.h:34, from "----my android project location----"//jni/ic u/icu4c/source/i18n/unicode/calendar.h:37, from "----my android project location----"//jni/ic u/icu4c/source/i18n/indiancal.h:18, from "----my android project location----"//jni/ic u/icu4c/source/i18n/indiancal.cpp:10: "----my android project location----"//jni/icu/icu4c/source/i18n/.. /common/unicode/std_string.h:33:18: fatal error: string: No such file or directo ry #include ^ compilation terminated. make.exe: *** ["----my android project location----"//obj/local/arm eabi/objs/icui18n/indiancal.o] Error 1 make.exe: *** Waiting for unfinished jobs.... In file included from "----my android project location----"//jni/ic u/icu4c/source/i18n/../common/unicode/unistr.h:31:0, from "----my android project location----"//jni/ic u/icu4c/source/i18n/../common/unicode/strenum.h:14, from "----my android project location----"//jni/ic u/icu4c/source/i18n/../common/unicode/uenum.h:24, from "----my android project location----"//jni/ic u/icu4c/source/i18n/unicode/ucal.h:12, from "----my android project location----"//jni/ic u/icu4c/source/i18n/unicode/udat.h:16, from "----my android project location----"//jni/ic u/icu4c/source/i18n/unicode/datefmt.h:26, from "----my android project location----"//jni/ic u/icu4c/source/i18n/dtptngen.cpp:15: "----my android project location----"//jni/icu/icu4c/source/i18n/.. /common/unicode/std_string.h:33:18: fatal error: string: No such file or directo ry #include ^ compilation terminated. make.exe: *** ["----my android project location----"//obj/local/arm eabi/objs/icui18n/dtptngen.o] Error 1 "----my android project location----"//jni/icu/icu4c/source/i18n/dt rule.cpp: In member function 'UBool icu_54::DateTimeRule::operator==(const icu_5 4::DateTimeRule&) const': "----my android project location----"//jni/icu/icu4c/source/i18n/dt rule.cpp:85:22: error: cannot use typeid with -fno-rtti (typeid(*this) == typeid(that) && ^ "----my android project location----"//jni/icu/icu4c/source/i18n/dt rule.cpp:85:38: error: cannot use typeid with -fno-rtti (typeid(*this) == typeid(that) && ^ make.exe: *** ["----my android project location----"//obj/local/arm eabi/objs/icui18n/dtrule.o] Error 1

这是我在jni目录中的主要Android.mk文件:

LOCAL_PATH:= $(call my-dir) include $(call all-subdir-makefiles) include $(CLEAR_VARS) LOCAL_MODULE:= sqlitenative LOCAL_SRC_FILES := sqlite3.c sqlite3_native.cpp # NOTE the following flags, # SQLITE_TEMP_STORE=3 causes all TEMP files to go into RAM. and thats the behavior we want # SQLITE_ENABLE_FTS3 enables usage of FTS3 - NOT FTS1 or 2. # SQLITE_DEFAULT_AUTOVACUUM=1 causes the databases to be subject to auto- vacuum # SQLITE_HAS_CODEC enables crypto support for database LOCAL_CFLAGS += -DHAVE_USLEEP=1 \ -DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 \ -DSQLITE_THREADSAFE=1 \ -DNDEBUG=1 \ -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 \ -DSQLITE_DEFAULT_AUTOVACUUM=1 \ -DSQLITE_TEMP_STORE=3 \ -DSQLITE_ENABLE_FTS3 \ -DSQLITE_ENABLE_FTS3_PARENTHESIS \ -DSQLITE_ENABLE_COLUMN_METADATA \ -DSQLITE_ENABLE_ICU \ -DHAVE_STRCHRNUL=0 LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lc LOCAL_C_INCLUDES += $(call include-path-for, system-core)/cutils LOCAL_SHARED_LIBRARIES += libicuuc \ libicui18n \ libutils LOCAL_SHARED_LIBRARIES += libicuuc-host libicui18n-host LOCAL_STATIC_LIBRARIES := liblog libutils libcutils include $(BUILD_SHARED_LIBRARY) include $(BUILD_HOST_SHARED_LIBRARY)

### 编译 Boost 库用于 Android NDK 为了在 Android NDK编译 Boost 库,可以遵循以下方法: #### 准备工作 确保安装并配置好 Android NDK 和必要的工具链。设置 Linux 的环境变量来指定 NDK 路径[^3]: ```bash export NDK=/path/to/android-ndk export PATH=${PATH}:${NDK} ``` #### 获取源码 从 GitHub 上获取适用于 Android 的 Boost 版本之一。可以选择由 Moritz Wundke 维护的版本[^1] 或 madadam 提供的仓库[^2]。 对于前者: ```bash git clone https://github.com/moritz-wundke/Boost-for-Android.git cd Boost-for-Android ``` 对于后者: ```bash git clone git://github.com/madadam/Boost-for-Android.git cd Boost-for-Android ``` #### 配置构建选项 根据需求调整 `project-config.jam` 文件中的参数以适应特定的目标架构和 ABI (Application Binary Interface),比如 arm64-v8a、armeabi-v7a 等。也可以通过命令行传递这些选项而不修改文件。 #### 开始编译过程 使用 b2 工具执行实际的编译操作。下面是一个典型的调用例子,它会创建静态链接库,并针对 ARM 架构优化[^4]: ```bash ./bootstrap.sh --with-libraries=all --without-icu ./b2 link=static threading=multi toolset=gcc architecture=arm target-os=android --stagedir=android_build --prefix=android_build ``` 注意这里选择了所有的子项目 (`--with-libraries=all`) 并排除了 ICU 支持 (`--without-icu`);如果只需要某些特定模块,则可以根据实际情况更改此部分。 此外,在较新的 NDK 版本中推荐采用 LLVM Clang 作为默认编译器而不是 GCC。因此可能需要相应地更新 `toolset` 参数值为 clang 或者其他支持的形式。 完成上述步骤之后应该能够在指定目录下找到所需的预编译二进制文件以及头文件资源包。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值