page.title=ICU4J Android Framework APIs page.image=images/cards/card-nyc_2x.jpg @jd:body
ICU4J is an open-source, widely used set of Java libraries providing Unicode and globalization support for software applications. Starting in Android 7.0 (API level 24), Android exposes a subset of the ICU4J APIs for app developers to use under the {@code android.icu} package. These APIs use localization data present on the device. As a result, you can reduce your APK footprint by not compiling the ICU4J libraries into your APK; instead, you can simply call out to them in the framework. (In this case, you may want to provide multiple versions of your APK, so users running versions of Android lower than Android 7.0 (API level 24) can download a version of the app that contains the ICU4J libraries.)
This document begins by providing some basic information on the minimum Android API levels required to support these libraries. It then explains what you need to know about the Android-specific implementation of ICU4J. Finally, it tells you how to use the ICU4J APIs in the Android framework.
Android exposes a subset of the ICU4J APIs via the
android.icu
package, rather than com.ibm.icu
. The
Android framework may choose not to
expose ICU4J APIs for various reasons; for example, Android does not expose
some deprecated APIs or those that the ICU team have not yet declared as
stable. As the ICU team deprecates APIs in the future, Android will also mark
them as deprecated but will continue to include them.
Table 1. ICU and CLDR versions used in Android].
Android API level | ICU version | CLDR version |
---|---|---|
Android 7.0 (API level 24) | 56 | 28 |
Here are a few important things to note:
If you are already using the ICU4J APIs in your app, and the
android.icu
APIs meet your requirements, then migrating to
the framework APIs requires you to change your Java imports
from com.ibm.icu
to android.icu
. You may then
remove your own copy of ICU4J files from the APK.
Note: The ICU4J framework APIs use the {@code android.icu} namespace instead of {@code com.ibm.icu}. This is to avoid namespace conflicts in APKs that contain their own {@code com.ibm.icu} libraries.
Some classes in the java
andandroid
packages have
equivalents to those found in ICU4J. However, ICU4J often provides broader
support for standards and languages.
Here are some examples to get you started:
Class | Alternatives |
---|---|
java.lang.Character |
android.icu.lang.UCharacter |
java.text.BreakIterator |
android.icu.text.BreakIterator |
java.text.DecimalFormat |
android.icu.text.DecimalFormat |
java.util.Calendar |
android.icu.util.Calendar |
android.text.BidiFormatter
|
android.icu.text.Bidi
|
android.text.format.DateFormat
|
android.icu.text.DateFormat
|
android.text.format.DateUtils |
android.icu.text.DateFormat
android.icu.text.RelativeDateTimeFormatter
|
ICU4J is released under the ICU license. For details, see the ICU User Guide.