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

Cannot access 'dev.icerock.moko.resources.ResourceContainer'

Open Egi10 opened this issue 1 year ago • 3 comments
trafficstars

I encountered an error in my multimodule project after updating to Moko Resources version 0.24.1. The error occurs when using strings in the actual class on the iOS platform (iosMain).

Cannot access 'dev.icerock.moko.resources.ResourceContainer' which is a supertype of 
'id.example.common.resources.FeederRes.strings'. 
Check your module classpath for missing or conflicting dependencies

Project Structure: -shared --common ---resource --core

Example Code:

Common (expect):

expect class CSVGenerate {
fun generateBody()
}
fun getMyFormatDesc(input: String): StringDesc {
    return StringDesc.ResourceFormatted(MR.strings.my_string_formatted, input)
}

iOS (actual):

actual class CSVGenerate {
actual fun generateBody() {
val string = getMyFormatDesc(input: "hello").localized()
}
}

Android (actual):

actual class CSVGenerate {
actual fun generateBody() {
val string = getMyFormatDesc("hello").toString(context = this)
}

Note: This error was encountered during a rebuild in Android Studio, but the project still runs when executed on Android and iOS.

Egi10 avatar Jun 21 '24 04:06 Egi10

hi. can you create small reproducer project?

Alex009 avatar Jun 21 '24 05:06 Alex009

I've tried replicating the issue by creating a sample project, but the same error doesn't occur.

Previously, I was using version 0.23.0 and everything was working smoothly. When the latest version came out and I wanted to upgrade Kotlin, I tried to update. However, I encountered the error.

Egi10 avatar Jun 22 '24 15:06 Egi10

I haven't encountered this issue before, but my project is not working properly. For now, I have downgraded to version 0.23.0 and implemented the solution from https://github.com/icerockdev/moko-resources/issues.

Egi10 avatar Jun 23 '24 16:06 Egi10

After further investigation, I discovered that the root cause of the issue lies in the module naming convention within my project:

-shared --common ---resources --core

This naming structure triggers an error during the execution of compileIosMainKotlinMetadata. However, if I change the module name to anything other than resources, the error disappears.

Example project: https://github.com/Egi10/resources

cc @Alex009

Egi10 avatar Jul 21 '24 11:07 Egi10

I'm now encountering an issue when running the app on iOS with the error: kotlin.IllegalArgumentException: bundle with identifier ***.main not found. I've also added a new configuration, but the problem persists :

"$SRCROOT/../gradlew" -p "$SRCROOT/../" :yourframeworkproject:copy`YourFrameworkName`FrameworkResourcesToApp \
    -Pmoko.resources.BUILT_PRODUCTS_DIR="$BUILT_PRODUCTS_DIR" \
    -Pmoko.resources.CONTENTS_FOLDER_PATH="$CONTENTS_FOLDER_PATH" \
    -Pkotlin.native.cocoapods.platform="$PLATFORM_NAME" \
    -Pkotlin.native.cocoapods.archs="$ARCHS" \
    -Pkotlin.native.cocoapods.configuration="$CONFIGURATION" 

Egi10 avatar Jul 21 '24 16:07 Egi10

This naming structure triggers an error during the execution of compileIosMainKotlinMetadata. However, if I change the module name to anything other than resources, the error disappears.

i think it's kotlin bug with module names clash. https://youtrack.jetbrains.com/issue/KT-57914

Alex009 avatar Jul 22 '24 03:07 Alex009

I've also added a new configuration, but the problem persists

please show full code of your xcode resources build phase and also logs from build process

Alex009 avatar Jul 22 '24 03:07 Alex009

I added the following script to the Build Phase:

"$SRCROOT/../gradlew" -p "$SRCROOT/../" :shared:core:copyPodFrameworkResourcesToApp \
  -Pmoko.resources.BUILT_PRODUCTS_DIR="$BUILT_PRODUCTS_DIR" \
  -Pmoko.resources.CONTENTS_FOLDER_PATH="$CONTENTS_FOLDER_PATH" \
  -Pkotlin.native.cocoapods.platform="$PLATFORM_NAME" \
  -Pkotlin.native.cocoapods.archs="$ARCHS" \
  -Pkotlin.native.cocoapods.configuration="$CONFIGURATION"

However, I encountered this error at runtime when trying to access the resources.

Screenshot 2024-07-22 at 13 33 25

I got the copyPodFrameworkResourcesToApp from a warning.

linkPodDebugFrameworkIosArm64 is found.
If you use a static framework, Xcode should have Build Phase with copyPodFrameworkResourcesToApp gradle task call. 
Please read readme on https://github.com/icerockdev/moko-resources
-
To hide this message, add 'moko.resources.disableStaticFrameworkWarning=true' to the Gradle properties.

Egi10 avatar Jul 22 '24 06:07 Egi10

Issue resolved, it turned out there was a problem with my custom plugin.

Egi10 avatar Jul 22 '24 10:07 Egi10