android ndk 中的 unicode 支持 [英] unicode support in android ndk

查看:20
本文介绍了android ndk 中的 unicode 支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大型 C/C++ 库,我需要将其用作 Android NDK 项目的一部分.此库需要能够智能处理 UTF8 字符串(例如,转换为小写/大写).

I have a large C/C++ library that I need to use as part of an Android NDK project. This library needs to be able to intelligently process UTF8 strings (for example, conversion to lowercase/uppercase).

该库具有条件编译功能,可将其发送到 OS API 进行转换,但似乎没有任何适用于 UTF8 的 Android API.(mbstowcs等)

The library has conditional compilation to punt to an OS API to do the conversion, but there don't seem to be any Android APIs for UTF8. (mbstowcs, etc)

这个线程说使用JNI方法来做(!),这是一个相当重量级的解决方案.

This thread says to use JNI methods to do it (!), which is a rather heavy-weight solution.

我正在考虑构建 ICU,但由于它使用 GNU Autotools,我不确定我是否可以使它与 NDK 工具链一起工作.:/

I was thinking about building ICU, but as it uses GNU Autotools I'm not sure I can make it work with the NDK toolchain. :/

有没有其他人遇到过这个问题并做过除了使用 JNI 之外的其他事情?

Has anyone else confronted this problem and done something other than use JNI?

我试图让 ICU 编译在配置步骤失败:

My attempts to get ICU to compile fail at the configure step:

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) 的目录.听起来很疯狂,但它确实有效!

We are using ICU in the NDK. Follow the steps in the ICU cross building instructions and you'll be OK. Basically you'll have a ICU native directory (for example Windows or Linux), a ICU Cygwin (if using such) and yet another for ICU Android (ARM). Sounds crazy, but it works!

以下是在 Cygwin 下构建的步骤.我正在使用CrystaX"NDK r4,但它也应该使用开箱即用的 NDK 构建.ICU 版本 4.4,但也适用于以前的版本.

Here are the steps for building under Cygwin. I am using the 'CrystaX' NDK r4, but it should build with the out of the box NDK as well. ICU version 4.4, but has worked with previous versions as well.

  1. 补丁:

照常构建您的 ICU 主机版本(例如 Windows).(我们称之为 $HOST_ICU)

Build your host version of ICU (e.g. Windows) as per normal. (We'll call this $HOST_ICU)

构建 Cygwin ICU:

Build Cygwin ICU:

  • 创建一个 icu-cygwin 目录(我们称之为 $ICU_CROSS_BUILD)
  • 从 icu-cygwin 目录,运行$HOST_ICU/source/runConfigureICU Cygwin"
  • 制作

构建 ICU 的 NDK 版本:

Build NDK version of ICU:

  • 创建 icu-android 目录
  • 来自 icu-android 目录:$HOST_ICU/source/configure",带有适当的命令行选项.--with-cross-build=$ICU_CROSS_BUILD 和 --host=arm-eabi 是必需的.
  • 制作

我使用这样的东西来传递(到第 4 步)CPPFLAGS/CXXFLAGS/CFLAGS:

I use something like this for passed in (to step #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:

And for 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 的自定义构建脚本中.如果您遇到任何其他问题,我可能会告诉您问题所在.

I haven't done this manually for a while, it's currently all in a custom Python based build script. If you run into any other troubles, I can probably tell you what the issue is.

祝你好运!

这篇关于android ndk 中的 unicode 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆