I am developing an Android application with Android Studio and I have a class with a static property like this:
public static final Pattern DIACRITICS_AND_FRIENDS = Pattern.compile("[\\p{InCombiningDiacriticalMarks}\\p{IsLm}\\p{IsSk}]+");
Everything is working fine when I debug the app on my physical device - API32.
But when I try to debug on an emulator API28, I get an exception whenever I try to reference any static property of the 'static' class.
FATAL EXCEPTION: main Process: com.example.myapp, PID: 10635
java.lang.ExceptionInInitializerError
at com.example.myapp.MainActivity.onCreate(MainActivity.java:40)
at android.app.Activity.performCreate(Activity.java:7136)
...
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.util.regex.PatternSyntaxException: U_ILLEGAL_ARGUMENT_ERROR
[\p{InCombiningDiacriticalMarks}\p{IsLm}\p{IsSk}]+
at java.util.regex.Pattern.compileImpl(Native Method)
at java.util.regex.Pattern.compile(Pattern.java:1344)
at java.util.regex.Pattern.<init>(Pattern.java:1328)
at java.util.regex.Pattern.compile(Pattern.java:950)
at com.example.myapp.MyStaticClass.<clinit>(MyStaticClass.java:21)
... 16 more
How can I fix this?
EDIT: with an emulator API30 it does not throw an exception, but this line is not working as expected anymore (it is not removing diactricts, but everything):
str = DIACRITICS_AND_FRIENDS.matcher(str).replaceAll("")