pal*_*ogt 11 unicode android utf-8 icu android-ndk
我有一个大的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
Run Code Online (Sandbox Code Playgroud)
NuS*_*ler 11
我们在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的NDK版本:
我使用这样的东西传入(到步骤#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
Run Code Online (Sandbox Code Playgroud)
对于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/
Run Code Online (Sandbox Code Playgroud)
另外配置参数:
--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
Run Code Online (Sandbox Code Playgroud)
我暂时没有手动完成此操作,它目前都是基于Python的自定义构建脚本.如果你遇到任何其他问题,我可以告诉你问题是什么.
祝好运!