Amplitude-Android
Amplitude-Android copied to clipboard
issue crash on kitkat 4.4
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.
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
Have you set up okhttp dependency? https://developers.amplitude.com/docs/android#1-add-dependencies
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
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
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?
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
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.
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?
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.