本文介绍了UNI美元的的Andr​​oid NDK C $ C ++支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

图书馆拥有条件编译能撑船到OS API来进行转换,但似乎没有任何Android的API,用于UTF8。 (mbstowcs等)

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

我想建立 ICU ,但因为它使用GNU自动工具,我不知道我可以把它一起工作NDK的工具链。 :/

有没有其他人遇到这个问题,并做了一些比使用其他JNI?

编辑:我试图让ICU编译失败在配置阶段:

 检查wchar.h可用性...没有
检查wchar.h presence ...是的
配置:警告:wchar.h:present,但不能编译
配置:警告:wchar.h:检查缺少prerequisite头?
配置:警告:wchar.h:看Autoconf的文档
配置:警告:wchar.h:部分present但不能编译
配置:警告:wchar.h:在继续preprocessor的结果
配置:警告:wchar.h:在未来,编译器将precedence
检查wchar.h ...是的
检查含wcscpy库...没有要求
检查wchar_t的大小... 0
配置:错误:有wchar.h但wchar_t的大小为0
 

解决方案

我们将在NDK使用ICU。按照在ICU交叉建筑物指令的步骤,你会没事的。基本上,你就会有一个ICU本地目录(例如Windows或Linux),一个ICU Cygwin的(如果使用这样的),但对ICU机器人(ARM)另一回事。听起来很疯狂,但它的作品!

下面是步骤,在Cygwin下构建。我现在用的是'CrystaXNDK R4,但它应该建立与开箱NDK为好。 ICU的版本4.4,但曾与previous版。

  1. 补丁:

  2. 建立ICU的主机版本(如Windows)按正常。 (我们称这个$ HOST_ICU)

  3. 建立Cygwin的ICU:

    • 创建一个ICU-cygwin目录(我们称这个$ ICU_CROSS_BUILD)
    • 从ICU-Cygwin的目录,运行$ HOST_ICU /源/ runConfigureICU Cygwin的
  4. 构建NDK版本ICU的:

    • 创建一个ICU-的Andr​​oid目录
    • 从ICU-机器人DIR:$ HOST_ICU /源/配置使用适当的命令行选项。 --with-交叉编译= $ ICU_CROSS_BUILD和主机=臂EABI是必需的。

我用这样的事情在过去(步骤#4)CPPFLAGS / CXXFLAGS / CFLAGS:

  -I $ NDK_ROOT /建设/平台/ Android为8 /弓臂/ usr / include目录/ -O3了-fno-short-WCHAR -DU_USING_ICU_NAMESPACE = 0 -DU_GNUC_UTF16_STRING = 0  - FNO-短枚举-nostdlib
 

和为LDFLAGS:

  -lc -Wl,-rpath链接= $ NDK_ROOT /编译/平台/ Android为8 /弓臂/ usr / lib中/ -L $ NDK_ROOT /编译/平台/机器人-8 /弓臂/ usr / lib中/
 

和附加配置PARAMS:

   - 启用 - 群众演员=无--enable-严格=无--enable-静态--enable-共享=无--enable-测试=没有--enable-样本=没有--enable-dyload =无--enable-工具=无主机=臂EABI --with数据包装=存档
 

我还没有在自定义的基于Python的构建脚本一会儿这样做手工,它是目前所有。如果您遇到任何其他麻烦,我可能会说你的问题是什么。

祝你好运!

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).

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)

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

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. :/

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

EDIT: 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
解决方案

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!

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. Patches:

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

  3. Build Cygwin ICU:

    • Create a icu-cygwin directory (We'll call this $ICU_CROSS_BUILD)
    • From icu-cygwin dir, run '$HOST_ICU/source/runConfigureICU Cygwin'
    • make
  4. Build NDK version of ICU:

    • Create a icu-android directory
    • From icu-android dir: '$HOST_ICU/source/configure' with appropriate command line options. --with-cross-build=$ICU_CROSS_BUILD and --host=arm-eabi is required.
    • make

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

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/

And additional configure params:

--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

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.

Good luck!

这篇关于UNI美元的的Andr​​oid NDK C $ C ++支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 18:52