moko-resources
moko-resources copied to clipboard
kotlin.native.internal.FileFailedToInitializeException: There was an error during file or class initialization
Strings.kt: package com.qvc.kmp.poc.shared
import dev.icerock.moko.resources.StringResource import dev.icerock.moko.resources.desc.Resource import dev.icerock.moko.resources.desc.StringDesc import dev.icerock.moko.resources.format
actual class Strings { actual fun get(id: StringResource, args: List<Any>): String { return if(args.isEmpty()) { StringDesc.Resource(id).localized() } else { id.format(*args.toTypedArray()).localized() } } }
SwiftUi: Text( Strings().get(id: SharedRes.strings().product_description, args: []) )
Function doesn't have or inherit @Throws annotation and thus exception isn't propagated from Kotlin to Objective-C/Swift as NSError. It is considered unexpected and unhandled instead. Program will be terminated. Uncaught Kotlin exception: kotlin.native.internal.FileFailedToInitializeException: There was an error during file or class initialization
Can someone help here ?
your error can be related to #796 that will be fixed in 0.24.5. or it can be just misconfiguration if you use static framework and not call copyResources task from xcode.
I assume @sunilhs1986 has the same problem as I do. The configuration of my modularized project is as follows:
- Core framework where I link static multiplatform framework
./gradlew :shared:embedAndSignAppleFrameworkForXcode - Application target where I run
"$SRCROOT/../gradlew" -p "$SRCROOT/../shared" :shared:copyFrameworkResourcesToApp
This configuration still crashes with 0.24.5 with the same error. When I move copyFrameworkResourcesToApp to Core framework it works.
@Alex009 Is this behaviour as intented?
@MartinStrambach looks like not intended. copyFrameworkResourcesToApp should be called for module that produce static framework. can you give me reproducer project to debug?
I am getting kotlin.native.internal.FileFailedToInitializeException when running iOS tests that use Moko-resources. I am not sure if this is related or it's something totally different.
Error Details
Stack Trace
kotlin.native.internal.FileFailedToInitializeException: There was an error during file or class initialization
kotlin.native.internal.FileFailedToInitializeException: There was an error during file or class initialization
at kotlin.Error#<init>(/opt/buildAgent/work/2d153abd4d2c0600/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:14)
at kotlin.native.internal.FileFailedToInitializeException#<init>(/opt/buildAgent/work/2d153abd4d2c0600/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt:122)
at <global>.ThrowFileFailedToInitializeException(/opt/buildAgent/work/2d153abd4d2c0600/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt:134)
at <global>.CallInitGlobalPossiblyLock(Unknown Source)
at com.thomaskioko.tvmaniac.i18n.MR.strings#<get-$instance>#static(/Users/kioko/Projects/tv-maniac/i18n/generator/build/generated/moko-resources/iosSimulatorArm64Main/src/com/thomaskioko/tvmaniac/i18n/MR.kt:19)
at com.thomaskioko.tvmaniac.i18n.StringResourceKey.CdShowPosterImage.<init>#internal(/Users/kioko/Projects/tv-maniac/i18n/generator/build/generated/resources/com/thomaskioko/tvmaniac/i18n/StringResourceKey.kt:108)
at com.thomaskioko.tvmaniac.i18n.StringResourceKey.CdShowPosterImage.$init_global#internal(/Users/kioko/Projects/tv-maniac/i18n/generator/build/generated/resources/com/thomaskioko/tvmaniac/i18n/StringResourceKey.kt:1)
at <global>.CallInitGlobalPossiblyLock(Unknown Source)
Project Structure
I have the following modular structure.
i18n/
├── api/ # API interfaces
├── generator/ # Moko-resources generator module with the configuration
├── implementation/ # Implementation with localizers
└── testing/ # Testing utilities
// i18n/generator/build.gradle.kts
.....
multiplatformResources {
resourcesPackage.set("com.thomaskioko.tvmaniac.i18n")
}
Test Setup
Test Class Structure
// MokoLocalizerTest.kt
class MokoLocalizerTest : BaseResourceTests() {
@Test
fun `should return localized string for valid key`() {
val result = localizer.getString(StringResourceKey.ButtonErrorRetry)
result shouldBe "Retry"
}
@Test
fun `should return formatted string when arguments are provided`() {
val result = localizer.getString(CdShowPosterImage, "Breaking Bad")
result shouldBe "Poster image for Breaking Bad"
}
}
iOS Test Implementation
// BaseResourceTests.kt (iOS)
actual abstract class BaseResourceTests : BaseLocalizerTest() {
actual val localizer: Localizer
get() = MokoResourcesLocalizer(PlatformLocalizer())
}
Additional Context
- The same tests work fine on Android and JVM targets
- The issue specifically affects iOS testing
I am having the same issue when upgraded to 0.25.0.
My libraries versions before the upgrade:
agp = "8.2.2" gradleTools = "7.2.2" kotlin = "2.0.21"
activityCompose = "1.9.2" androidXCore = "1.13.1" appCompat = "1.7.0" buildConfig = "5.3.5" coilCompose = "2.7.0" compose = "1.6.8" mapsCompose = "5.0.4" composeMultiplatform = "1.6.11" coroutines = "1.9.0" credentials = "1.3.0" fragmentKtx = "1.8.5" gmsAuth = "20.0.1" gmsAuthApiPhone = "17.4.0" googleMaterial = "1.12.0" imageLoader = "1.6.6" junit = "4.13.2" ktor = "2.3.13" kotlinxSerialization = "1.7.3" kotlinxDatetime = "0.6.0" libPhoneNumber = "8.13.52" lifecycle = "2.8.5" material3 = "1.3.1" mokoGeo = "0.7.0" mokoGraphics = "0.9.0" mokoParcelize = "0.9.0" mokoPermissions = "0.18.0" mokoResources = "0.24.3" okio = "3.9.1" precompose = "1.6.2"
realm = "2.3.0" swipeRefresh = "1.1.0" viewmodelCompose = "2.8.0" playServicesMaps = "19.0.0"
And after:
agp = "8.6.0" gradleTools = "7.2.2" kotlin = "2.2.0"
activityCompose = "1.10.1" androidXCore = "1.16.0" appCompat = "1.7.1" buildConfig = "5.6.8" coilCompose = "2.7.0" compose = "1.9.1" mapsCompose = "5.0.4" composeMultiplatform = "1.8.2" composeNavigation = "2.9.0" coroutines = "1.8.0" fragmentKtx = "1.8.9" gmsAuth = "21.4.0" gmsAuthApiPhone = "18.2.0" googleMaterial = "1.13.0" imageLoader = "1.10.0" junit = "4.13.2" ktor = "2.3.13" kotlinxSerialization = "1.9.0" kotlinxDatetime = "0.6.0" libPhoneNumber = "8.13.52" lifecycle = "2.9.3" lifecycleCompose = "2.9.4" material3 = "1.3.2" materialIcons = "1.7.8" mokoGeo = "0.8.0" mokoGraphics = "0.9.0" mokoParcelize = "0.9.0" mokoPermissions = "0.19.1" mokoResources = "0.25.0" okio = "3.10.2"
realm = "3.2.8-2" swipeRefresh = "1.1.0" viewmodelCompose = "2.9.4" playServicesMaps = "19.2.0"
But I tested a lot of options and it's always the same. For the imageLoader (io.github.qdsfdhvh:image-loader) and moko-graphics I tried also to remove them because I noticed that they depend on moko-resources but it's still the same so maybe it's about the library itself or something about my configuration. Let me know what can I check or if you need some additional information. It is about iOS, the android build works correctly