unicode support in android ndk

后端 未结 1 739
-上瘾入骨i
-上瘾入骨i 2020-12-28 09:58

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

相关标签:
1条回答
  • 2020-12-28 10:21

    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:

      • source/configure (http://pastebin.com/kDEbYdMe)
      • source/Makefile.in (http://pastebin.com/785Lnsb5)
      • source/config/ (copy mh-linux to mh-unknown)
      • source/tools/pkgdata/pkgdata.cpp (http://pastebin.com/ZiRexjkp)
    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!

    0 讨论(0)
提交回复
热议问题