Skip to content

Commit

Permalink
Fix ClassNotFound exception in Android during Release builds (#25912)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thecodrr authored and janicduplessis committed Aug 2, 2019
1 parent eec4dc6 commit ffdf3f2
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,12 +15,15 @@
// 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) {
Expand All @@ -34,6 +38,7 @@ public static String dateFormat(double unixtimeMs, boolean formatDate, boolean f
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;
Expand All @@ -52,6 +57,7 @@ public static String convertToCase(String input, int targetCase, boolean useCurr
}
}

@DoNotStrip
public static String normalize(String input, int form) {
// Values must match NormalizationForm in PlatformUnicode.h.
final int formC = 0;
Expand Down

0 comments on commit ffdf3f2

Please sign in to comment.