"java.lang.NoSuchMethodError: No static method" error when using Android NumberFormatter

"java.lang.NoSuchMethodError: No static method" error when using Android NumberFormatter

根据 documentation 此行应产生“// 1,234 in en-US”的输出:

println(NumberFormatter.withLocale(ULocale.ENGLISH).format(123).toString())

相反,它抛出了这个错误:

java.lang.NoSuchMethodError: No static method withLocale(Landroid/icu/util/ULocale;)Landroid/icu/number/LocalizedNumberFormatter; in class Landroid/icu/number/NumberFormatter; or its super classes (declaration of 'android.icu.number.NumberFormatter' appears in /apex/com.android.runtime/javalib/core-libart.jar)

Added in API level 30

适用于 android 11+。你是什​​么版本?