Fix ClassNotFound exception in Android during Release builds (#25912)

* Add DoNotStrip annotation for Hermes

This adds the @DoNotStrip annotation to disallow Proguard/R8 from stripping the AndroidUnicodeUtils class during release build and causing a `ClassNotFound` crash.

* Add @DoNotStrip annotations on all methods

* Update AndroidUnicodeUtils.java
This commit is contained in:
thecodrr
2019-08-02 15:29:36 -04:00
committed by Janic Duplessis
parent eec4dc6b72
commit ffdf3f22c6
@@ -6,6 +6,7 @@
*/
package com.facebook.hermes.unicode;
import com.facebook.proguard.annotations.DoNotStrip;
import java.text.Collator;
import java.text.DateFormat;
import java.text.Normalizer;
@@ -14,12 +15,15 @@ import java.util.Locale;
// TODO: use com.facebook.common.locale.Locales.getApplicationLocale() as the current locale,
// rather than the device locale. This is challenging because getApplicationLocale() is only
// available via DI.
@DoNotStrip
public class AndroidUnicodeUtils {
@DoNotStrip
public static int localeCompare(String left, String right) {
Collator collator = Collator.getInstance();
return collator.compare(left, right);
}
@DoNotStrip
public static String dateFormat(double unixtimeMs, boolean formatDate, boolean formatTime) {
DateFormat format;
if (formatDate && formatTime) {
@@ -34,6 +38,7 @@ public class AndroidUnicodeUtils {
return format.format((long) unixtimeMs).toString();
}
@DoNotStrip
public static String convertToCase(String input, int targetCase, boolean useCurrentLocale) {
// These values must match CaseConversion in PlatformUnicode.h
final int targetUppercase = 0;
@@ -52,6 +57,7 @@ public class AndroidUnicodeUtils {
}
}
@DoNotStrip
public static String normalize(String input, int form) {
// Values must match NormalizationForm in PlatformUnicode.h.
final int formC = 0;