Invoking ICU from Adobe AIR Applications

This article was originally written in English. Text in other languages was provided by machine translation.

Adobe Flash and AIR are ubiquitous platforms to develop rich internet applications. Flash is used for browser based applications and AIR is used for developing native platform applications. Both platforms have considerable support for globalization. Globalization enablement features like locale aware formatting/parsing, collation, case transforms, localization and multi-lingual text rendering are supported by both these platforms. But some more globalization features like text normalization, transliteration, Unicode character properties, encoding conversions, charset detections, Unicode string utilities etc are still missing in the Adobe AIR and Flash platforms. One of the primary reasons for not adding all these features inside the Adobe runtime platforms is the size of the software.

To overcome the size limitation issue, Adobe AIR and Flash can invoke the services of external dynamic libraries through ActionScript. There are some well known external libraries which have rich globalization support like ICU, GNU glib, Verisign IDN library to name a few. Fortunately the upcoming Adobe AIR 3.0 (now available as Adobe pre-release) has a wonderful feature called ActionScript native extensions, which is about ActionScript programming interface for a native code library like MS Windows DLL, Os X FrameWork, Android JAR or shared library or iOS static library. Please see Adobe AIR3 beta site http://labs.adobe.com/technologies/flashplatformruntimes/air3/ on how to download and take part in the Adobe AIR pre-release. Please make a note that this native extensions feature is available _only_ in Adobe AIR platform, not in the Flash platform.

In this blog, I demonstrate a sample (Download air_icu ) application to invoke ICU from an Adobe AIR application on Windows platform. Readers are reminded that this is only illustration sample software and by no means production quality software. Hence readers must exhibit discretion in using this software as it is. The sample illustrates ICU word breaking, sentence breaking, utf-conversion and Unicode character property verification.

You will need the following software to build an ICU extension for AIR platform.

The file AirIcuExtension.as in the folder srccomadobeextensions has the public class AirIcuExtension which calls the ICU routines. In this sample, calling ICU sentence breaker, word breaker, normalizer, utf-conversion and Unicode character property have been illustrated.

1.3 Packaging ActionScript native extension

Open the binAirIcuExtension.swc is a zipped archive. Open it using WinRAR or WinZip program and extract the library.swf file in the swc package into the AirIcuExtension/bin folder.

For simplicity, place the AirIcuExtension.dll, ICU dlls and extension.xml files in AirIcuExtensionbin folder. All these files are packaged into a zipped archive called AiricuExtension.ane using the following command.

Using Adobe FlashBuilder4.x or C:air3_beta2binadt program, one can make an AIR certificate.

The output is an archive file AirIcuExtension.ane in the AirIcuExtension/bin folder.

1.4 Building the Test program AirIcuExtensionTest.mxml

Now that we built and packaged the native extension package AiricuExtension.ane, we are readu to use this and call ICU services in a test program.

The folder AirIcuExtensionTestsrc contains the test file AirIcuExtensionTest.mxml. The descriptor file AirIcuExtensionTest-app.xml has the details of native extension. Using the mxml compiler, AirIcuExtensionTest.swf is built as follows in AirIcuExtensionTest folder.

The output of the above command is a folder AirIcuExtensionTest.air. Inside the folder, thereis AirIcuExtensionTest.exe. You can execute and see the output.

2 Conclusion

The sample illustrated how to invoke ICU from ActionScript. The AIR ICU extension is easy to build using the publicly available Adobe Flex SDK and AIR3 Beta 2 SDKs. It will be much easier to do all this in the future Adobe Flash Builder IDE using GUI. The advantages of this feature are

AIR developers looking to develop international applications for desktop or mobile have the full power of ICU at hand. Many Unicode features, encoding conversions, IDN conversion utilities, string processing, transforms and many more international features can be easily coded.

The native ICU extension once built can be used any any developer as it is a library.

The Actionscript APIs calling ICU can be coded using the same signatures as ICU C++ API. This eliminates the learning curve.

Since ICU is in native code, performance is not compromised.

Since it is ICU, developers can expect cross-platform behavior in AIR programs.

Since the extension is a AIR library, ICU updates can be easily re-packaged in to the ane file.

In the future once AIR3 is released, a full fledged ICU native extension with proper API definitions will be a great globalization project.

Thanks for the comment.
You are right. ICU 64bit dlls donot work in AIR 3.0. I remember I could not build the extension DLL in VS2010. AIR 3.0 does not yet support 64bit.
We have to wait until it supports. Let us wait for post-Air3.0.

I can’t build ane using adt. I ran adt at C:air3_RC1samplesair_icuAirIcuExtensionbin after setting “set path=c:air3_RC1bin;%PATH%”. I have following files under AirIcuExtensionbin directory, but i got “system can not find the file specified.” Did I miss anything?

Harish, thanks for help.
Error message was not detail enough to see which file was missing. ADT runs okay. What is air license file? I can’t see any instruction about license file. Does it mean AIR certificate? This error is raised from adt run in step 1.3.

This is powerfull, I hope we will see more of ANEs in near future 🙂
Nicely build on win7 x64 following steps of your research.
I just needed to manually copy the *48.dll files into air dir, I must of have missed something regarding packaging…

Hi James,
Sorry, my example only illustrated C++/C but not C#.
One way to try C# dll is you should invoke C# dll from a C++ dll using interop (Just google for calling C# from C++). The C++ dll must implement all AIR needed framework glue as in my sample here. This is only my guess.

After I finish all steps, I got a problem when I execute the .exe file in the folder air
It jumps a message e.g. ” can’t find the icuuc48.dll componet”
but I have found the file “icuuc45.dll” in the folder Windows-x86~ just like the following