moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

Can't find MR bundle in iOS app

Open babew opened this issue 2 years ago • 5 comments

Hello Team!

I'm using your library for sharing resources in compose multiplatform project. Everything was working great until I have created a separated module for my common logic (let's call it featureCommon). So I moved all the moko implementation and resources to that module. After that added this module as dependency to my 'shared' module. Since then my iOS app crashes when trying to access any resource from moko. I've tried everything.. made the framework static, added the build phases from the documentation but nothing worked... Before creating the common module when all the logic and resources were in shared module everything worked as expected.

build.gradle.kts(:shared)

plugins {
    alias(libs.plugins.multiplatform.application)
    alias(libs.plugins.android.application.flavors)
}

kotlin {

    listOf(
        iosX64(),
        iosArm64(),
        //iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
            baseName = "shared"
            export(project(":featureCommon"))
            export(project(":SharedModels"))

        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                api(project(":featureCommon"))
                api(project(":featureIdentification"))
            }
        }
    }
}

android {
    namespace = "***"

    defaultConfig {
        applicationId   = "***"
        versionCode     = 1
        versionName     = "1.0"
    }
}

build.gradle.kts(:featureCommon)

plugins {
    alias(libs.plugins.common.feature)
}

kotlin {
    sourceSets {
        androidMain {
            dependencies {
                some dependencies ...
            }
        }
    }
}

multiplatformResources {
    multiplatformResourcesPackage = "***.common.resources"
    multiplatformResourcesClassName = "SR"
}

android {
    namespace = "***.common"
    sourceSets["main"].resources.exclude("**/MR/*")
}

crash stacktrace

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
    at 0   shared                              0x10756ce9f        kfun:kotlin.Error#<init>(kotlin.String?;kotlin.Throwable?){} + 143 
    at 1   shared                              0x1075aa1ab        kfun:kotlin.native.internal.FileFailedToInitializeException#<init>(kotlin.String?;kotlin.Throwable?){} + 143 
    at 2   shared                              0x1075a9407        ThrowFileFailedToInitializeException + 275 
    at 3   shared                              0x107711b57        CallInitGlobalPossiblyLock + 759 
    at 4   shared                              0x106d6426b        kfun:***.feature.common.resources.SR.fonts.carossoft#<get-$instance>#static(){}***.feature.common.resources.SR.fonts.carossoft + 75 
    at 5   shared                              0x106ec0453        kfun:***.feature.common.ui.theme.AppTheme#<init>(){} + 663 
    at 6   shared                              0x106ec0187        kfun:***.feature.common.ui.theme.AppTheme.$init_global#internal + 131 
    at 7   shared                              0x107711a7b        CallInitGlobalPossiblyLock + 539 
    at 8   shared                              0x106ec148b        kfun:***.feature.common.ui.theme.AppTheme#<get-$instance>#static(){}***.feature.common.ui.theme.AppTheme + 75 
    at 9   shared                              0x1070effeb        objc2kotlin_kclass:***.feature.common.ui.theme.AppTheme#shared + 103 
    at 10  iCard ID                            0x1009cc5db        $s8iCard_ID11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0k6LaunchJ3KeyaypGSgtF + 179 
    at 11  iCard ID                            0x1009cc9ff        $s8iCard_ID11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0k6LaunchJ3KeyaypGSgtFTo + 195 
    at 12  SwiftUI                             0x1cbbd82c7        <redacted> + 2843 
    at 13  SwiftUI                             0x1cbbcba23        <redacted> + 659 
    at 14  UIKitCore                           0x1ca63ec53        <redacted> + 299 
    at 15  UIKitCore                           0x1ca63e377        <redacted> + 2847 
    at 16  UIKitCore                           0x1ca63d353        <redacted> + 855 
    at 17  UIKitCore                           0x1ca63cfcb        <redacted> + 175 
    at 18  UIKitCore                           0x1ca6877ef        <redacted> + 47 
    at 19  UIKitCore                           0x1ca686847        <redacted> + 851 
    at 20  UIKitCore                           0x1ca6864cf        UIApplicationMain + 339 
    at 21  SwiftUI                             0x1cbc9f367        <redacted> + 2423 
    at 22  SwiftUI                             0x1cbc0039b        <redacted> + 387 
    at 23  SwiftUI                             0x1cbbe974f        <redacted> + 2819 
    at 24  iCard ID                            0x1009cec7f        $s8iCard_ID6iOSAppV5$mainyyFZ + 39 
    at 25  iCard ID                            0x1009cf04b        main + 11 
    at 26  dyld                                0x1e69b295f        <redacted> + 2527 
Caused by: kotlin.IllegalArgumentException: bundle with identifier ***.feature.common.resources.MR not found
    at 0   shared                              0x107573b53        kfun:kotlin.Throwable#<init>(kotlin.String?){} + 119 
    at 1   shared                              0x10756cf93        kfun:kotlin.Exception#<init>(kotlin.String?){} + 115 
    at 2   shared                              0x10756d1b3        kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 115 
    at 3   shared                              0x10756d533        kfun:kotlin.IllegalArgumentException#<init>(kotlin.String?){} + 115 
    at 4   shared                              0x108786c4b        kfun:dev.icerock.moko.resources.utils#loadableBundle__at__platform.Foundation.NSBundle.Companion(kotlin.String){}platform.Foundation.NSBundle + 3355 
    at 5   shared                              0x106d655bb        kfun:***.feature.common.resources.SR.<init>$lambda$0#internal + 183 
    at 6   shared                              0x106d6563f        kfun:***.feature.common.resources.SR.$<init>$lambda$0$FUNCTION_REFERENCE$1.invoke#internal + 63 
    at 7   shared                              0x107697aa3        kfun:kotlin.Function0#invoke(){}1:0-trampoline + 99 
    at 8   shared                              0x1075861b3        kfun:kotlin.native.concurrent.SynchronizedLazyImpl#<get-value>(){}1:0 + 707 
    at 9   shared                              0x10769a307        kfun:kotlin.Lazy#<get-value>(){}1:0-trampoline + 99 
    at 10  shared                              0x106bf9cb7        kfun:***.feature.common.resources.SR.<get-bundle>#internal + 191 
    at 11  shared                              0x106d6414b        kfun:***.feature.common.resources.SR.fonts.carossoft#<init>(){} + 211 
    at 12  shared                              0x106d64043        kfun:***.feature.common.resources.SR.fonts.carossoft.$init_global#internal + 131 
    at 13  shared                              0x107711a7b        CallInitGlobalPossiblyLock + 539 
    at 14  shared                              0x106d6426b        kfun:***.feature.common.resources.SR.fonts.carossoft#<get-$instance>#static(){}***.feature.common.resources.SR.fonts.carossoft + 75 
    ... and 22 more common stack frames skipped

Could you please help me resolve this issue?

Regards, Lyubo

babew avatar Dec 15 '23 12:12 babew

I believe the answer is here. This is because of the current KMM iOS limitation - you can't have your modules completely separated, you need to have the code/resources in 1 resulting framework instead. On Android your setup should work just fine, so I'm considering this is as iOS limitation

iuriipleskach avatar Dec 15 '23 16:12 iuriipleskach

you should enable moko-resources plugin in your gradle module that compiled into framework. i.e. build.gradle.kts(:shared)

Alex009 avatar Dec 18 '23 04:12 Alex009

you should enable moko-resources plugin in your gradle module that compiled into framework. i.e. build.gradle.kts(:shared)

@Alex009 I faced with this error. When adding the moko-resources plugin into my shared module.

plugins {
    id("dev.icerock.mobile.multiplatform-resources")
}   


multiplatformResources {   
    multiplatformResourcesPackage = "**.shared.resources"   
}   

It still does not work. Then got error

error: Compilation failed: IrClassPublicSymbolImpl for*.shared.resources/MR|null[0] is already bound: CLASS OBJECT name:MR modality:FINAL visibility:public superTypes:[kotlin.Any]

tamnguyenhuy avatar Dec 22 '23 10:12 tamnguyenhuy

Hi @tamnguyenhuy, did you figure out a way fix to this issue?

rdsarna avatar Jan 08 '24 15:01 rdsarna

Hi @tamnguyenhuy, did you figure out how to fix this issue?

Yes. I have to keep the multiplatformResourcesPackage value in other module resource. Then in shared module, I change multiplatformResourcesPackage value to other one.

tamnguyenhuy avatar Jan 09 '24 07:01 tamnguyenhuy