Why does this crash on iOS? ```Image(painter = pai...
# compose-ios
s
Why does this crash on iOS?
Copy code
Image(painter = painterResource("image.jpg"), contentDescription = null)
It works fine on Android. Loading xml vectors also work fine on both platforms.
a
Is there a stack trace of the crash?
s
from Android studio I don’t see a stack trace
I’ll try xcode
got it. Uncaught Kotlin exception: org.jetbrains.compose.resources.MissingResourceException: Missing resource with path: image.jpg
somehow it’s not passing the image.jpg file
It works if I copy the image to xcode iOS project. Did I miss some step?
a
Try to run pod install on the iOS app project. I had similar issue
If you do a search for the file, you should see it added to the Xcode project after running pod install
s
That worked! thanks Andrew.
The xml vector file was already added without this extra step. Jetbrains team should check if this can be done for image files too.
a
Np! I feel like the iOS assemble task should look at resource file changes and do a pod install if they’ve changed. I imagine it will come in future
n
Of course!
s
great
j
I wasn't clear from above if there's some dependency on using cocoapods to ensure image file gets copied over? I've tried a few different things but still getting
MissingResourceException
using following from JB sample as starting point...I've put that file in
commonMain/resources
as per sample
Copy code
Image(
   painterResource("compose-multiplatform.xml"),
   null
)
ah, if I manually copy it in to the iOS project then it works
s
pod install is the correct way
j
What if project isn't using cocospods? Or is there dependency on using it?
s
Good question, haven’t tried another method, the sample is using cocoapods and it’s the most common and used dependency manager on iOS
a
(For now) I believe SPM is the way of the future. But for now, pod install scripts will copy the resources into your Xcode project, thus why the step is necessary. It’s certainly somethingJB is probably going to add to the main assemble (if resource files change, recopy over)
q
Hey all, I am trying to pod install but it's not working... any ideas?
i
i have the same issue with cococapods, pod install does not work for me,
a
Not sure what “doesn’t work” means. May help to be more specific 😊
i
Yes, sorry, it finally works, but only if the resources are located in a shared module. I have another module for share resources only and for desktop and android it works but not for iOS (I am consuming this shareResources module in my share module)
j
Is there a fix for this without using pod install? When copying the template from Github it didn’t come with a pod file.
n
We moved the template to regular frameworks instead of CocoaPods. You may find CocoaPods example here -- https://github.com/JetBrains/compose-multiplatform/tree/master/examples/cocoapods-ios-example (should work without pod install anytime you update resources)
BTW, just updating the version to 1.5.x in your existing project should fix the problem as well.
q
Yes I noticed that pod install command is auto run
When I update the version
j
I guess I’m using the template that uses regular frameworks. Adding my PNG to the resources folder under my shared module crashes on iOS. Using xml files works without issue. I’m using the following version
Compose: “1.5.10-beta02”
Kotlin: “1.9.20-Beta2"
Is this functionality not supported for beta versions?
n
PNG resources should work as well. Please file the issue and reproducible example.
j
Before I file a issue, does the isStatic flag need to be set to
true
in the
iosTarget.binaries.framework
block of
build.gradle.kts
to get this functionality?
@Nikita Lipsky I’ve cloned the compose-mobile template and was able to add png file without issue. It appears to be something wrong with the configuration with my current problem. Do you know what would cause resources to fail to be copied into the iOS project?
n
does the isStatic flag need to be set to
true
in the
iosTarget.binaries.framework
block of
build.gradle.kts
to get this functionality?
It is not required for Compose Multiplatform starting with 1.5.0
It appears to be something wrong with the configuration with my current problem
If you can strip down your project to reproduce the problem and share it, we can look at it.
Do you know what would cause resources to fail to be copied into the iOS project?
No. Currently, Compose Multiplatform Gradle plugin copies all resources to final iOS bundle that should be accessible by our resource library, providing that you use the same version for our resource library as for Gradle plugin (1.5.x)
j
Thanks for the response. The error was related to using the moko-resources plugin. Switching over to libres I was able to achieve the same goal without issue.
n
Ah! moko-resources, libres and Compose Multiplatform resource library all have Gradle plugin machinery for copying resources for iOS that are incompatible with each other. So you should use only one approach.
291 Views