icerockdev / moko-resources

Resources access for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
1.11k stars 123 forks source link

Gradle sync fails after upgrading from 0.23.0 to 0.24.x #784

Open vojta-horanek opened 2 weeks ago

vojta-horanek commented 2 weeks ago

Our project fails to be synced (specifically the KMP module) after updating moko-resources to 0.24.3 from 0.23.0. As I've tested, the same happens when using any of the other 0.24.x versions. The build (Android and iOS) is working fine, however android studio fails to sync and thus indexing is not working correctly. What is strange is that if XCode runs the copyResourcesKMMSharedDomainDebugXCFrameworkToApp task, it completes successfully and resources are indeed copied to the iOS application.

The following issue is displayed when trying to sync:

Unable to build Kotlin project configuration
Failed building KotlinMPPGradleModel

org.gradle.api.internal.tasks.DefaultTaskContainer$TaskCreationException: Could not create task ':shared:copyResourcesKMMSharedDomainXCFrameworkToApp'.

...

Caused by: java.lang.ClassCastException: class org.gradle.api.DefaultTask_Decorated cannot be cast to class org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask (org.gradle.api.DefaultTask_Decorated is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @277c0f21; org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @5fb60b55)

The name KMMSharedDomain comes from using configureCopyXCFrameworkResources("KMMSharedDomain") in the configuration.

I've experimented a bit and found out that when I don't use configureCopyXCFrameworkResources in the configuration, the sync actually completes just fine -> obvious since the task does not get registered 😄

I suspect the cast in SetupAppleUtils:registerCopyXCFrameworkResourcesToAppTask is the cause of the issue.

This is a screenshot from the debugger evaluating this.project.tasks.getByName("assemble$xcFrameworkName") right before the sync crashes.

Snímek obrazovky 2024-11-07 v 14 04 58

Thanks in advance.