Amplitude-Android icon indicating copy to clipboard operation
Amplitude-Android copied to clipboard

issue crash on kitkat 4.4

Open kadaluarsa opened this issue 4 years ago • 8 comments

Expected Behavior

not crash and work normally like others sdk

Current Behavior

i got crash report from google console vitals here is the stacktrace java.lang.ExceptionInInitializerError: at okhttp3.internal.platform.Platform$Companion.findAndroidPlatform (Platform.java:219) at okhttp3.internal.platform.Platform$Companion.findPlatform (Platform.java:212) at okhttp3.internal.platform.Platform$Companion.access$findPlatform (Platform.java:169) at okhttp3.internal.platform.Platform. (Platform.java:170) at okhttp3.OkHttpClient. (OkHttpClient.java:237) at okhttp3.OkHttpClient. (OkHttpClient.java:222) at com.amplitude.api.AmplitudeClient$1.run (AmplitudeClient.java:266) at android.os.Handler.handleCallback (Handler.java:733) at android.os.Handler.dispatchMessage (Handler.java:95) at android.os.Looper.loop (Looper.java:146) at android.os.HandlerThread.run (HandlerThread.java:61) Caused by: java.lang.IllegalStateException: at okhttp3.internal.platform.AndroidPlatform. (AndroidPlatform.java:153) at okhttp3.internal.platform.Platform$Companion.findAndroidPlatform (Platform.java:219) at okhttp3.internal.platform.Platform$Companion.findPlatform (Platform.java:212) at okhttp3.internal.platform.Platform$Companion.access$findPlatform (Platform.java:169) at okhttp3.internal.platform.Platform. (Platform.java:170) at okhttp3.OkHttpClient. (OkHttpClient.java:237) at okhttp3.OkHttpClient. (OkHttpClient.java:222) at com.amplitude.api.AmplitudeClient$1.run (AmplitudeClient.java:266) at android.os.Handler.handleCallback (Handler.java:733) at android.os.Handler.dispatchMessage (Handler.java:95) at android.os.Looper.loop (Looper.java:146) at android.os.HandlerThread.run (HandlerThread.java:61)

Possible Solutionu

I have no idea why this error happens because on SDK above 19 it works normally.

Steps to Reproduce

Environment

  • SDK Version: 10.0.02
  • Android API Level: SDK 19 kitkat
  • Device: All device with SDK 19

kadaluarsa avatar Dec 31 '20 02:12 kadaluarsa

Have you set up okhttp dependency? https://developers.amplitude.com/docs/android#1-add-dependencies

haoliu-amp avatar Jan 11 '21 17:01 haoliu-amp

Have you set up okhttp dependency? https://developers.amplitude.com/docs/android#1-add-dependencies

yes okhttp has been set but the problem still exist

kadaluarsa avatar Jan 13 '21 17:01 kadaluarsa

I see the same (or very very similar) on KitKat (4.4.4 and 4.4.2 primarily). I'm integrated through Unity, I haven't explicitly downgraded okhttp as required for kitkat, sounds like I could fix it via https://developers.amplitude.com/docs/unity#6-android-api-compatibility

java.lang.ExceptionInInitializerError

Platform.kt:211 okhttp3.internal.platform.Platform$Companion.findPlatform	
Platform.kt:179 okhttp3.internal.platform.Platform$Companion.access$findPlatform	
Platform.kt:180 okhttp3.internal.platform.Platform.<clinit>	
OkHttpClient.kt:219 okhttp3.OkHttpClient.<init>	
OkHttpClient.kt:211 okhttp3.OkHttpClient.<init>	
lambda:-1 com.amplitude.api.-$$Lambda$iEmU3psnaPI6bh5_pSglQ7pSGnc.get	
DoubleCheck.java:28 com.amplitude.util.DoubleCheck.get	
AmplitudeClient.java:347 com.amplitude.api.AmplitudeClient.lambda$null$0	
lambda:-1 com.amplitude.api.-$$Lambda$AmplitudeClient$fA9cZprCGw0DAi-FOkvviXMs1Sw.newCall	
AmplitudeClient.java:2081 com.amplitude.api.AmplitudeClient.makeEventUploadPostRequest	
AmplitudeClient.java:1946 com.amplitude.api.AmplitudeClient$12.run	
Handler.java:733 android.os.Handler.handleCallback	
Handler.java:95 android.os.Handler.dispatchMessage	
Looper.java:136 android.os.Looper.loop	
HandlerThread.java:61 android.os.HandlerThread.run

pfay-fc avatar Dec 02 '21 19:12 pfay-fc

I confirm this crash on Android 4.4

Amplitude sdk 2.31.1 Okhttp 4.2.2

Has it been fixed with the new versions or is there a workaround?

DonMizzi avatar Jan 09 '22 20:01 DonMizzi

Hi @DonMizzi it's possible this is a compatibility issue with OkHttp. OkHttp uses reflection to access some parts of the Android SDK so is strongly coupled with the version of Android. Can you please try another version of OkHttp and see if that fixes the issue?

More information here: https://github.com/amplitude/Amplitude-Android/issues/309#issuecomment-994186622

justin-fiedler avatar Jan 10 '22 15:01 justin-fiedler

okhttp3 4.2.2 requires API Level 21+

https://square.github.io/okhttp/#requirements

OkHttp works on Android 5.0+ (API level 21+) and Java 8+.

To support older devices could be challenging ...

The OkHttp 3.12.x branch supports Android 2.3+ (API level 9+) and Java 7+. These platforms lack support for TLS 1.2 and should not be used. But because upgrading is difficult, we will backport critical fixes to the 3.12.x branch through December 31, 2021.

chrisvire avatar Mar 25 '22 13:03 chrisvire

v2.24.0 switch from okhttp3 3.10 (used in v.2.23.2) to okhttp3 4.2.2 which has a requirement on API 21. okhttp3 3.12.2 has an API 9+ requirement. That is quite a change in dependencies without any notice in the release notes!

@haoliu-amp, if a developer want to support API 19, then they should use Amplitude 2.23.2 and okhttp3 3.12.2?

chrisvire avatar Mar 28 '22 18:03 chrisvire

We now have a new Android Kotlin SDK now! Feel free to check it out and let us know if any feedback! That library is not using okhttp as part of dependency now.

qingzhuozhen avatar May 05 '22 23:05 qingzhuozhen