我有一个大的C / C ++库,我需要将其用作Android NDK项目的一部分。该库需要能够智能地处理UTF8字符串(例如,转换为小写/大写)。
该库具有条件编译功能,可以通过OS API进行转换,但似乎没有任何适用于UTF8的Android API。 (mbstowcs等)
这个帖子 说使用JNI方法来做(!),这是一个相当重量级的解决方案。
我正在考虑建设 ICU,但由于它使用GNU Autotools,我不确定我是否可以使用NDK工具链。 :/
有没有其他人遇到过这个问题,除了使用JNI之外还做了什么?
编辑: 我在配置步骤中尝试使ICU编译失败:
checking wchar.h usability... no
checking wchar.h presence... yes
configure: WARNING: wchar.h: present but cannot be compiled
configure: WARNING: wchar.h: check for missing prerequisite headers?
configure: WARNING: wchar.h: see the Autoconf documentation
configure: WARNING: wchar.h: section "Present But Cannot Be Compiled"
configure: WARNING: wchar.h: proceeding with the preprocessor's result
configure: WARNING: wchar.h: in the future, the compiler will take precedence
checking for wchar.h... yes
checking for library containing wcscpy... none required
checking size of wchar_t... 0
configure: error: There is wchar.h but the size of wchar_t is 0
我们在NDK中使用ICU。按照ICU跨建筑说明中的步骤操作,您就可以了。基本上你将拥有一个ICU原生目录(例如Windows或Linux),一个ICU Cygwin(如果使用的话)和另一个ICU Android(ARM)。听起来很疯狂,但它确实有效!
以下是在Cygwin下构建的步骤。我正在使用'CrystaX'NDK r4,但它也应该使用开箱即用的NDK。 ICU版本4.4,但也与之前的版本一起使用。
补丁:
按照正常情况构建您的主机版ICU(例如Windows)。 (我们称之为$ HOST_ICU)
构建Cygwin ICU:
- 创建一个icu-cygwin目录(我们称之为$ ICU_CROSS_BUILD)
- 从icu-cygwin目录开始运行'$ HOST_ICU / source / runConfigureICU Cygwin'
- 使
构建ICU的NDK版本:
- 创建一个icu-android目录
- 从icu-android目录:'$ HOST_ICU / source / configure'以及相应的命令行选项。 --with-cross-build = $ ICU_CROSS_BUILD和--host = arm-eabi是必需的。
- 使
我使用这样的东西传入(到步骤#4)CPPFLAGS / CXXFLAGS / CFLAGS:
-I$NDK_ROOT/build/platforms/android-8/arch-arm/usr/include/ -O3 -fno-short-wchar -DU_USING_ICU_NAMESPACE=0 -DU_GNUC_UTF16_STRING=0 -fno-short-enums -nostdlib
对于LDFLAGS:
-lc -Wl,-rpath-link=$NDK_ROOT/build/platforms/android-8/arch-arm/usr/lib/ -L$NDK_ROOT/build/platforms/android-8/arch-arm/usr/lib/
另外配置参数:
--enable-extras=no --enable-strict=no --enable-static --enable-shared=no --enable-tests=no --enable-samples=no --enable-dyload=no --enable-tools=no --host=arm-eabi --with-data-packaging=archive
我有一段时间没有手动完成此操作,它目前都是基于自定义Python的构建脚本。如果你遇到任何其他问题,我可以告诉你问题是什么。
祝你好运!