Giphy / giphy-android-sdk

Home of the GIPHY SDK Android example app, along with Android SDK documentation, issue tracking, & release notes.
https://developers.giphy.com/
Mozilla Public License 2.0
94 stars 37 forks source link

ExceptionInInitializerError when calling Giphy.configure #178

Closed ffrenchm closed 2 years ago

ffrenchm commented 2 years ago

🐛 Bug Report

When I call Giphy.configure, some of my users get a java.lang.ExceptionInInitializerError. However, I can't reproduce this on my device or my emulator.

Here is the code I'm using to initialise the Giphy SDK:

class MainActivity: AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        Giphy.configure(this, BuildConfig.GIPHY_API_KEY)
    }
}

MainActivity is my first and only Activity since I'm using single activity architecture with fragments. So when users experience this crash, they can't open the app at all.

Here is the error stack trace from Google Play:

java.lang.ExceptionInInitializerError: 
  at okhttp3.OkHttpClient.<init> (OkHttpClient.kt:219)
  at okhttp3.OkHttpClient$Builder.build (OkHttpClient.kt:955)
  at com.giphy.sdk.ui.Giphy.initFresco (Giphy.kt:97)
  at com.giphy.sdk.ui.Giphy.configure (Giphy.kt:65)
  at com.giphy.sdk.ui.Giphy.configure$default (Giphy.kt:50)
  at <my bundle>.app.shared.MainActivity.onCreate (MainActivity.kt:80)
  at android.app.Activity.performCreate (Activity.java:8006)
  at android.app.Activity.performCreate (Activity.java:7990)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1329)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3584)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3775)
  at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:85)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2246)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:233)
  at android.app.ActivityThread.main (ActivityThread.java:8010)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:631)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:978)
Caused by: java.lang.IllegalStateException: 
  at okhttp3.internal.platform.AndroidPlatform$Companion.buildIfSupported (AndroidPlatform.kt:370)
  at okhttp3.internal.platform.Platform$Companion.findPlatform (Platform.kt:204)
  at okhttp3.internal.platform.Platform$Companion.access$findPlatform (Platform.kt:178)
  at okhttp3.internal.platform.Platform.<clinit> (Platform.kt:179)

So the app is crashing at Giphy.initFresco, when the okHttpClient is being built. When I decompile the Giphy class to Java, this is the initFresco function:

private final void initFresco(Context context) {
      DiskCacheConfig previewsDiskConfig = DiskCacheConfig.newBuilder(context).setMaxCacheSize(419430400L).build();
      DiskCacheConfig qualityDiskConfig = DiskCacheConfig.newBuilder(context).setMaxCacheSize(262144000L).build();
      HashSet requestListeners = new HashSet();
      requestListeners.add(new RequestLoggingListener());
      Builder okHttpClient = new Builder();
      GiphyFrescoHandler var10000 = frescoHandler;
      if (var10000 != null) {
         var10000.handle(okHttpClient);
      }

      okHttpClient.addInterceptor((Interceptor)null.INSTANCE); // <--- My compiler is telling me this will result in a null pointer exception
      com.facebook.imagepipeline.core.ImagePipelineConfig.Builder config = OkHttpImagePipelineConfigFactory.newBuilder(context, okHttpClient.build()).setSmallImageDiskCacheConfig(previewsDiskConfig).setMainDiskCacheConfig(qualityDiskConfig);
      var10000 = frescoHandler;
      if (var10000 != null) {
         Intrinsics.checkNotNullExpressionValue(config, "config");
         var10000.handle(config);
      }

      Fresco.initialize(context, config.build());
   }

Environment:

Giphy Android SDK version: 2.1.16 Gradle version: 7.0.2 Device info: OneNote 7 Pro (real device) running Android 11 (SDK 30)

ALexanderLonsky commented 2 years ago

Hey @ffrenchm, thanks for flagging this. It seems we need to update the OkHttp version:

Version 3.12.13
2021-01-30
Fix: Work around a crash in Android 10 and 11 that may be triggered when two threads concurrently close an SSL socket.
This would have appeared in crash logs as NullPointerException: bio == null.

I'll let you know when it's done.

ALexanderLonsky commented 2 years ago

@ffrenchm, Please try v2.1.17 Giphy SDK does not use okhttp, this is the Fresco dependency, so the only thing I could do was to update Fresco to the latest version.