Skeptick / libres

Resources generation in Kotlin Multiplatform
Apache License 2.0
210 stars 12 forks source link

Problems with resources loading in iOS #30

Closed aenadgrleey closed 1 year ago

aenadgrleey commented 1 year ago

Getting this error when launching KMP and Compose MP multimodule project on iOS:

Uncaught Kotlin exception: kotlin.native.internal.FileFailedToInitializeException: There was an error during file or class initialization
    at 0   iosApp                              0x1041b0773        kfun:kotlin.Error#<init>(kotlin.String?;kotlin.Throwable?){} + 147 
    at 1   iosApp                              0x1041e9377        kfun:kotlin.native.internal.FileFailedToInitializeException#<init>(kotlin.String?;kotlin.Throwable?){} + 147 
    at 2   iosApp                              0x1041e879b        ThrowFileFailedToInitializeException + 275 
    at 3   iosApp                              0x104f6d937        CallInitGlobalPossiblyLock + 763 
    at 4   iosApp                              0x104bd1273        kfun:kr.hipopo.hipopo.images.MainScreenResImages#<get-$instance>#static(){}kr.hipopo.hipopo.images.MainScreenResImages + 99 
    at 5   iosApp                              0x104bd144b        kfun:kr.hipopo.hipopo.MainScreenRes#<init>(){} + 211 
    at 6   iosApp                              0x104bd1343        kfun:kr.hipopo.hipopo.MainScreenRes.$init_global#internal + 151 
    at 7   iosApp                              0x104f6d857        CallInitGlobalPossiblyLock + 539 
    at 8   iosApp                              0x104bd167b        kfun:kr.hipopo.hipopo.MainScreenRes#<get-$instance>#static(){}kr.hipopo.hipopo.MainScreenRes + 99 

I have a multimodule project with resources stored in each module, bt while trying to launch it on iOS I'm getting this. On Android it works great with no problems

Skeptick commented 1 year ago

Hello. Interesting error, I haven't seen it before. At what point in application is the image accessed? I mean at the very start or a little later. If you can show the code where it crashes and at what point this code is called that will be great :) I'll try to reproduce this error

aenadgrleey commented 1 year ago

What do I have: I have a project where I'm trying to build multimodule structure project. There's one "shared" module that depends on another module called "api" which depends on module called "impl", which has libres directory and holds resources. cocoapods are set up only at "shared" module. The result doesn't change regardless shared has libreы-plugin or doesn't. I have tried to postpone resource init by some sometime using LaunchedEffect - nothing has changed, it still crashes on initialization of res. My images are all SVG, and I'm trying to launch app on iOS 16.4 simulator

Skeptick commented 1 year ago

I think the error isn't directly related to resources. I think it's some Kotlin/Native related issue, regarding class initialization. Images object initializes bundle at the moment of access, that's why I wanted to clarify at what point this access occurs.

aenadgrleey commented 1 year ago

I have fixed this issue by adding one more build phase in Xcode as it is done here: https://github.com/icerockdev/moko-resources#iosmacos-static-kotlin-frameworks-support

Skeptick commented 1 year ago

This phase is needed to copy resources into application. It is specific to moko. With Libres cocoapods does this. I also can’t imagine how it could be related to the runtime error in K/N. Mystery...

yumiki commented 1 year ago

Hi I have the same issue and the images are access at the first application screen (compose).

@aenadgrleey can you please share what you have add to your build phase in Xcode please?