Search code examples
androidfacebook-graph-apitimezoneandroid-facebook

Android facebook sdk internal utility java.lang.AssertionError


I have been using version 4.27.0 of facebook sdk for android. I have been getting a crash only for android 8+ devices. The stack trace is as follows:

Fatal Exception: java.lang.AssertionError: No NameTypeIndex match for SHORT_DAYLIGHT
       at android.icu.impl.TimeZoneNamesImpl$ZNames.getNameTypeIndex(TimeZoneNamesImpl.java:724)
       at android.icu.impl.TimeZoneNamesImpl$ZNames.getName(TimeZoneNamesImpl.java:790)
       at android.icu.impl.TimeZoneNamesImpl.getTimeZoneDisplayName(TimeZoneNamesImpl.java:183)
       at android.icu.text.TimeZoneNames.getDisplayName(TimeZoneNames.java:261)
       at java.util.TimeZone.getDisplayName(TimeZone.java:405)
       at java.util.TimeZone.getDisplayName(TimeZone.java:370)
       at com.facebook.internal.Utility.refreshTimezone(Utility.java:1066)
       at com.facebook.internal.Utility.refreshPeriodicExtendedDeviceInfo(Utility.java:1056)
       at com.facebook.internal.Utility.setAppEventExtendedDeviceInfoParameters(Utility.java:707)
       at com.facebook.internal.AppEventsLoggerUtility.getJSONObjectForGraphAPICall(AppEventsLoggerUtility.java:68)
       at com.facebook.FacebookSdk.publishInstallAndWaitForResponse(FacebookSdk.java:568)
       at com.facebook.FacebookSdk$4.run(FacebookSdk.java:547)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:764)

I have searched for this over the web but couldn't get anything useful. Please provide some pointers here.


Solution

  • I am facing this issue too, upgrade the Facebook SDK to the latest (Facebook Android SDK 4.35), they have added a workaround for this issue:

     private static void refreshTimezone() {
        try {
            TimeZone tz = TimeZone.getDefault();
            deviceTimezoneAbbreviation = tz.getDisplayName(
                    tz.inDaylightTime(new Date()),
                    TimeZone.SHORT
            );
            deviceTimeZoneName = tz.getID();
        } catch (AssertionError e) {
          // Workaround for a bug in Android that can cause crashes on Android 8.0 and 8.1
        } catch (Exception e) {
        }
    }