java-stellar-sdk
java-stellar-sdk copied to clipboard
0.36.0 Crash on Android <=9 -> okhttp3 ExceptionInInitializerError
What version are you using?
Newest version 0.36.0
What did you do?
Create the org.stellar.sdk.Server("https://horizon.stellar.co/")
object in any place of the project -> You will receive the crash: java.lang.ExceptionInInitializerError
on the Android version <=9
StandardAndroidSocketAdapter.kt line 61
....
java.lang.ExceptionInInitializerError
at shadow.okhttp3.OkHttpClient.<init>(OkHttpClient.kt:237)
at shadow.okhttp3.OkHttpClient$Builder.build(OkHttpClient.kt:1069)
at org.stellar.sdk.Server.<init>(Server.java:58)
Steps to reproduce:
- Create a new Kotlin project in the Android Studio.
- Apply Java Stellar SDK 0.36.0.
- Create
org.stellar.sdk.Server("https://horizon.stellar.co/")
object in any place. - Run the project on the Android <= 9 and immediately receive the
ExceptionInInitializerError
.
What did you expect to see?
No any crashes.
What did you see instead?
Crash on the Android <=9.
Thanks.
@let-it-snow , can you provide which version of Android Studio, I'm trying 2021.2.1, and how do you enact Run the project on Android <= 9
? What version is the 9
referring in Android Studio settings? thanks! I was starting with a new Basic Activity
project to replicate.
@sreuland Hi,
- Android Studio Chipmunk | 2021.2.1
- Set the Minimum SDK e.g. API 22.
- Create Basic Activity.
- Apply latest Stellar SDK to depedencies.
- Into Basic Activity apply the code like: org.stellar.sdk.Server("https://horizon.stellar.co/").
- Run the project on the Android 9 (Api Level 28) emulator.
@sreuland you can try this demo project that demonstrates this issue with the latest Java Stellar SDK.
Attached is a screen recording of what happened. The crash doesn't happen when using an emulator with API 30, but it crashes with API 21 (not sure what is the latest API version that works).
https://user-images.githubusercontent.com/7346473/191515800-bbaae45c-9c08-490b-8fe3-8f75d3be855b.mp4
@lijamie98 @marcelosalloum , any thoughts on this android runtime conflict as well, wondering if maybe it's time to just replace okhttp with a different lib like apache httpclient to avoid it
I remember seeing this. If I remember it correctly, it has some conflict with the library shipped with Kotlin.
I am not sure if replacing okhttp would avoid the problem though.
@lijamie98 is this still an issue or have you been able to resolve it?