Jake
09/08/2020, 7:10 PMUncaught Kotlin exception: kotlin.native.concurrent.FreezingException: freezing of com.ramseysolutions.proportalspike.shared.Globals.Companion@f13308 has failed, first blocker is HttpClient[io.ktor.client.engine.ios.IosClientEngine@f13488]The offending code was:
kotlin
val json = kotlinx.serialization.json.Json { ignoreUnknownKeys = true }
fun createHttpClient() = HttpClient() {
install(JsonFeature) {
serializer = KotlinxSerializer(json)
}
}
class Globals {
companion object {
client = createHttpClient()
}
}
The iOS application utilizes that client in its first view. I noticed in my debugging, that the breakpoints in my iOS project were never getting hit. So I determined the crash was happening before the class that was referencing client
was ever created. Working that theory, I was able to stop the crash from occurring and achieve the correct results on iOS and Android by removing that client
property from the companion object
and by creating a global variable in the iOS project:
// Kotlin Shared
class Globals {
client = createHttpClient()
}
// iOS
let globals = Globals()
After resolving that, I asserted that a simple global variable would fail also, and I was correct when I tested that. My questions are: what was causing the failure? Are Coroutines unavailable until a certain point in the iOS application lifecycle? And what resources or tools can I use to figure that type of thing out on my own?Ivann Ruiz
09/08/2020, 7:33 PM1.4.0
to 1.3.2-1.4.0-rc
works just finehttpClient
is not getting frozen anymore. Conclusion ktor 1.4.0
for iOS is broken.Jake
09/08/2020, 7:49 PMThe failure I’m getting was that it failed to freeze the client when initialized as a static/global property, But I get success when it’s not. I’m newer to the Kotlin freezing thing, but it seems to be working to me… But I would like to know how you’re checking if the freezes are successful or not. What tools do you use to inspect that?is not getting frozen anymore.httpClient
Ivann Ruiz
09/09/2020, 1:35 PMco.touchlab:stately-common:1.1.0
dambakk
09/10/2020, 1:15 PMobject
with the httpClient as a variable and that the object was not marked as @ThreadLocal
. Annotating the object fixed my issues.
I also had problems upgrading to kotlin 1.4 with the ios project using the Firebase Performance pod. Remove this resolved my issues.