Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: Include resources without needing to run pod install #3113

Closed
alexzaitsev opened this issue Apr 30, 2023 · 3 comments
Closed

iOS: Include resources without needing to run pod install #3113

alexzaitsev opened this issue Apr 30, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@alexzaitsev
Copy link

Describe the bug
Using a compose-multiplatform-ios-android-template, try to add a new resource and use it in Composable function in shared module. It successfully works for Android but crashes for iOS.

Affected platforms

  • iOS

Versions

  • Kotlin version*: 1.8.20
  • Compose Multiplatform version*: 1.4.0
  • OS version(s)* (required for Desktop and iOS issues): 16.4
  • OS architecture (x86 or arm64):
  • JDK (for desktop issues):

To Reproduce

  1. Clone the repo.
  2. Run the project on iOS simulator.
  3. Press the button on the screen to display the image.
  4. Observe crash stacktrace.

The resource I'm using:

<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp"
    android:autoMirrored="true" android:tint="#FFFFFF" android:viewportWidth="24"
    android:viewportHeight="24">
    <path android:fillColor="#ffffffff"
        android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />
</vector>

I cloned a fresh template and added this commit to demonstrate the issue.
Stacktrace:

Uncaught Kotlin exception: org.jetbrains.compose.resources.MissingResourceException: Missing resource with path: ic_arrow_back.xml
    at 0   My application                      0x100cec877        kfun:kotlin.Throwable#<init>(kotlin.String?){} + 123 
    at 1   My application                      0x100ce51d3        kfun:kotlin.Exception#<init>(kotlin.String?){} + 119 
    at 2   My application                      0x1014dec97        kfun:org.jetbrains.compose.resources.MissingResourceException#<init>(kotlin.String){} + 195 
    at 3   My application                      0x1014de877        kfun:org.jetbrains.compose.resources.UIKitResourceImpl.readBytes#internal + 1907 
    at 4   My application                      0x1014cbdef        kfun:org.jetbrains.compose.resources.$readBytesSync$lambda$0COROUTINE$0.invokeSuspend#internal + 455 
    at 5   My application                      0x100cf0b07        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 599 
    at 6   My application                      0x100e70287        kfun:kotlinx.coroutines.DispatchedTask#run(){} + 2603 
    at 7   My application                      0x100e10a3f        kfun:kotlinx.coroutines.EventLoopImplBase#processNextEvent(){}kotlin.Long + 1279 
    at 8   My application                      0x100e8efe3        kfun:kotlinx.coroutines.BlockingCoroutine.joinBlocking#internal + 467 
    at 9   My application                      0x100e8e857        kfun:kotlinx.coroutines#runBlocking(kotlin.coroutines.CoroutineContext;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,0:0>){0§<kotlin.Any?>}0:0 + 1335 
    at 10  My application                      0x100e8e9f3        kfun:kotlinx.coroutines#runBlocking$default(kotlin.coroutines.CoroutineContext?;kotlin.coroutines.SuspendFunction1<kotlinx.coroutines.CoroutineScope,0:0>;kotlin.Int){0§<kotlin.Any?>}0:0 + 271 
    at 11  My application                      0x1014cbad7        kfun:org.jetbrains.compose.resources#readBytesSync__at__org.jetbrains.compose.resources.Resource(){}kotlin.ByteArray + 203 
    at 12  My application                      0x1014ce70f        kfun:org.jetbrains.compose.resources.rememberImageVectorSync#internal + 1359 
    at 13  My application                      0x1014d0e87        kfun:org.jetbrains.compose.resources.painterResource$lambda$3#internal + 547 
    at 14  My application                      0x1014d352b        kfun:org.jetbrains.compose.resources.$painterResource$lambda$3$FUNCTION_REFERENCE$5.invoke#internal + 183 
    at 15  My application                      0x1014d3663        kfun:org.jetbrains.compose.resources.$painterResource$lambda$3$FUNCTION_REFERENCE$5.$<bridge-NNNNNNB>invoke(org.jetbrains.compose.resources.Resource;androidx.compose.ui.unit.Density;androidx.compose.runtime.Composer;kotlin.Int){}androidx.compose.ui.graphics.vector.ImageVector#internal + 259 
    at 16  My application                      0x1014cd357        kfun:org.jetbrains.compose.resources.painterResource#internal + 1383 
    at 17  My application                      0x1014cc9cb        kfun:org.jetbrains.compose.resources#painterResource(kotlin.String;androidx.compose.runtime.Composer?;kotlin.Int){}androidx.compose.ui.graphics.painter.Painter + 787 
    at 18  My application                      0x1014e3c2b        kfun:ComposableSingletons$AppKt.<init>$lambda$0#internal + 679 
    at 19  My application                      0x1014e778f        kfun:ComposableSingletons$AppKt.$<init>$lambda$0$FUNCTION_REFERENCE$1.invoke#internal + 147 
    at 20  My application                      0x1014e787f        kfun:ComposableSingletons$AppKt.$<init>$lambda$0$FUNCTION_REFERENCE$1.$<bridge-UNNNNB>invoke(androidx.compose.animation.AnimatedVisibilityScope;androidx.compose.runtime.Composer;kotlin.Int){}#internal + 219 
    at 21  My application                      0x100fc99cb        kfun:androidx.compose.runtime.internal.ComposableLambdaImpl#invoke(kotlin.Any?;androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any? + 927 
    at 22  My application                      0x100fdb897        kfun:androidx.compose.runtime.internal.ComposableLambdaImpl#$<bridge-NNNNNB>invoke(kotlin.Any?;androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any?(kotlin.Any?;androidx.compose.runtime.Composer;kotlin.Any?){}kotlin.Any? + 223 
    at 23  My application                      0x1013e1bbf        kfun:androidx.compose.animation.AnimatedEnterExitImpl#internal + 16171 
    at 24  My application                      0x1013dd21b        kfun:androidx.compose.animation#AnimatedVisibility__at__androidx.compose.foundation.layout.ColumnScope(kotlin.Boolean;androidx.compose.ui.Modifier?;androidx.compose.animation.EnterTransition?;androidx.compose.animation.ExitTransition?;kotlin.String?;kotlin.Function3<androidx.compose.animation.AnimatedVisibilityScope,androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){} + 5055 
    at 25  My application                      0x1014e6e2f        kfun:ComposableSingletons$AppKt.<init>$lambda$7#internal + 9163 
    at 26  My application                      0x1014e792b        kfun:ComposableSingletons$AppKt.$<init>$lambda$7$FUNCTION_REFERENCE$2.invoke#internal + 119 
    at 27  My application                      0x1014e79f7        kfun:ComposableSingletons$AppKt.$<init>$lambda$7$FUNCTION_REFERENCE$2.$<bridge-UNNNB>invoke(androidx.compose.runtime.Composer;kotlin.Int){}#internal + 183 
    at 28  My application                      0x100fc9393        kfun:androidx.compose.runtime.internal.ComposableLambdaImpl#invoke(androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any? + 875 
    at 29  My application                      0x100fdb783        kfun:androidx.compose.runtime.internal.ComposableLambdaImpl#$<bridge-NNNNB>invoke(androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any?(androidx.compose.runtime.Composer;kotlin.Any?){}kotlin.Any? + 187 
    at 30  My application                      0x100ef4497        kfun:androidx.compose.runtime.RecomposeScopeImpl#compose(androidx.compose.runtime.Composer){} + 399 
    at 31  My application                      0x100eac4d7        kfun:androidx.compose.runtime.ComposerImpl.recomposeToGroupEnd#internal + 1295 
    at 32  My application                      0x100eae6d3        kfun:androidx.compose.runtime.ComposerImpl#skipCurrentGroup(){} + 635 
    at 33  My application                      0x100ec033b        kfun:androidx.compose.runtime.ComposerImpl.doCompose$lambda$27#internal + 851 
    at 34  My application                      0x100ec5e8b        kfun:androidx.compose.runtime.ComposerImpl.$doCompose$lambda$27$FUNCTION_REFERENCE$33.invoke#internal + 103 
    at 35  My application                      0x100ec601f        kfun:androidx.compose.runtime.ComposerImpl.$doCompose$lambda$27$FUNCTION_REFERENCE$33.$<bridge-UNN>invoke(){}#internal + 95 
    at 36  My application                      0x100ee82b7        kfun:androidx.compose.runtime#observeDerivedStateRecalculations(kotlin.Function1<androidx.compose.runtime.State<*>,kotlin.Unit>;kotlin.Function1<androidx.compose.runtime.State<*>,kotlin.Unit>;kotlin.Function0<0:0>){0§<kotlin.Any?>} + 1015 
    at 37  My application                      0x100eb3b83        kfun:androidx.compose.runtime.ComposerImpl.doCompose#internal + 2247 
    at 38  My application                      0x100eb315f        kfun:androidx.compose.runtime.ComposerImpl#recompose(androidx.compose.runtime.collection.IdentityArrayMap<androidx.compose.runtime.RecomposeScopeImpl,androidx.compose.runtime.collection.IdentityArraySet<kotlin.Any>?>){}kotlin.Boolean + 775 
    at 39  My application                      0x100ed9643        kfun:androidx.compose.runtime.CompositionImpl#recompose(){}kotlin.Boolean + 495 
    at 40  My application                      0x100eff72b        kfun:androidx.compose.runtime.Recomposer.performRecompose#internal + 1575 
    at 41  My application                      0x100f074df        kfun:androidx.compose.runtime.Recomposer.runRecomposeAndApplyChanges$lambda$4$lambda$3#internal + 2567 
    at 42  My application                      0x100f0e2b3        kfun:androidx.compose.runtime.Recomposer.$runRecomposeAndApplyChanges$lambda$4$lambda$3$FUNCTION_REFERENCE$7.invoke#internal + 131 
    at 43  My application                      0x100f0e543        kfun:androidx.compose.runtime.Recomposer.$runRecomposeAndApplyChanges$lambda$4$lambda$3$FUNCTION_REFERENCE$7.$<bridge-UNNB>invoke(kotlin.Long){}#internal + 147 
    at 44  My application                      0x100e9acc7        kfun:androidx.compose.runtime.BroadcastFrameClock.FrameAwaiter.resume#internal + 459 
    at 45  My application                      0x100e9b843        kfun:androidx.compose.runtime.BroadcastFrameClock#sendFrame(kotlin.Long){} + 635 
    at 46  My application                      0x101329bb7        kfun:androidx.compose.ui.ComposeScene#render(org.jetbrains.skia.Canvas;kotlin.Long){} + 1019 
    at 47  My application                      0x10132069b        kfun:androidx.compose.ui.native.ComposeLayer.ComponentImpl#onRender(org.jetbrains.skia.Canvas;kotlin.Int;kotlin.Int;kotlin.Long){} + 231 
    at 48  My application                      0x10106aeaf        kfun:org.jetbrains.skiko.SkiaLayer#draw(org.jetbrains.skia.Canvas){} + 2055 
    at 49  My application                      0x101091edb        kfun:org.jetbrains.skiko.context.MetalContextHandler.$draw$FUNCTION_REFERENCE$0.invoke#internal + 123 
    at 50  My application                      0x1010922f3        kfun:org.jetbrains.skiko.context.MetalContextHandler.$draw$FUNCTION_REFERENCE$0.$<bridge-UNNN>invoke(org.jetbrains.skia.Canvas){}#internal + 123 
    at 51  My application                      0x1010658af        kfun:org.jetbrains.skiko.context.ContextHandler#draw(){} + 791 
    at 52  My application                      0x101095673        kfun:org.jetbrains.skiko.redrawer.MetalRedrawer.draw#internal + 339 
    at 53  My application                      0x101095dc7        kfun:org.jetbrains.skiko.redrawer.MetalRedrawer.<init>$lambda$0#internal + 347 
    at 54  My application                      0x101095eb3        kfun:org.jetbrains.skiko.redrawer.MetalRedrawer.$<init>$lambda$0$FUNCTION_REFERENCE$0.invoke#internal + 95 
    at 55  My application                      0x101095fc7        kfun:org.jetbrains.skiko.redrawer.MetalRedrawer.$<init>$lambda$0$FUNCTION_REFERENCE$0.$<bridge-UNN>invoke(){}#internal + 95 
    at 56  My application                      0x101098207        kfun:org.jetbrains.skiko.redrawer.FrameTickListener.onDisplayLinkTick#internal + 227 
    at 57  My application                      0x10109830b        kfun:org.jetbrains.skiko.redrawer.FrameTickListener.$imp:onDisplayLinkTick#internal + 155 
    at 58  QuartzCore                          0x187c5b84b        _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 807 
    at 59  QuartzCore                          0x187d62083        _ZL22display_timer_callbackP12__CFMachPortPvlS1_ + 335 
    at 60  CoreFoundation                      0x1803664ef        __CFMachPortPerform + 171 
    at 61  CoreFoundation                      0x18039b35b        __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 55 
    at 62  CoreFoundation                      0x18039a97b        __CFRunLoopDoSource1 + 495 
    at 63  CoreFoundation                      0x180394ed3        __CFRunLoopRun + 2151 
    at 64  CoreFoundation                      0x180394253        CFRunLoopRunSpecific + 583 
    at 65  GraphicsServices                    0x188eb7c9b        GSEventRunModal + 159 
    at 66  UIKitCore                           0x104542fef        -[UIApplication _run] + 867 
    at 67  UIKitCore                           0x104546f3b        UIApplicationMain + 123 
    at 68  SwiftUI                             0x1085ef34b        OUTLINED_FUNCTION_54 + 499 
    at 69  SwiftUI                             0x1085ef1eb        OUTLINED_FUNCTION_54 + 147 
    at 70  SwiftUI                             0x107de7473        OUTLINED_FUNCTION_16 + 87 
    at 71  My application                      0x100cd5d9b        $s14My_application6iOSAppV5$mainyyFZ + 39 (/Users/p3ngu1n/Documents/Develop/test-resource-bug/iosApp/iosApp/iOSApp.swift:<unknown>)
    at 72  My application                      0x100cd5e47        main + 11 
    at 73  dyld                                0x103445513        0x0 + 4349777171 
    at 74  ???                                 0x1035c9f27        0x0 + 4351368999 
    at 75  ???                                 0x8d15ffffffffffff 0x0 + -8280430864874078209 

Process finished with exit code 0

Expected behavior
Resource should be displayed.

Additional context
So weird, this should be a basic thing...

@alexzaitsev alexzaitsev added bug Something isn't working submitted labels Apr 30, 2023
@m-sasha
Copy link
Contributor

m-sasha commented Apr 30, 2023

It has been suggested in slack to run pod install on the iOS app project: https://kotlinlang.slack.com/archives/C0346LWVBJ4/p1682449910246879

@alexzaitsev
Copy link
Author

Ok, running cd iosApp followed by pod install fixes the issue. This is still unintuitive though.

@m-sasha m-sasha added enhancement New feature or request and removed bug Something isn't working submitted labels May 3, 2023
@m-sasha m-sasha changed the title New resource in template is causing MissingResourceException: Missing resource with path iOS: Include resources without needing to run pod install May 3, 2023
@dima-avdeev-jb
Copy link
Contributor

You can follow this Issue: #3073

AlexeyTsvetkov added a commit that referenced this issue Jul 11, 2023
Introduces new a new task 'sync<FRAMEWORK_CLASSIFIER>ComposeIosResources',
which collects resources from all source sets, included in iOS targets.

With this change:
* CocoaPods integration does not require any configuration or calling 'pod install' after changing resources.
    * Important: existing projects need to remove 'extraSpecAttributes["resources"] = ...' from build scripts, and rerun `./gradlew podInstall` once!
* Without CocoaPods, the resource directory should be added to XCode build phases once.

Resolves #3073
Resolves #3113
Resolves #3066
AlexeyTsvetkov added a commit that referenced this issue Jul 18, 2023
* Simplify resource management for iOS

Introduces new a new task 'sync<FRAMEWORK_CLASSIFIER>ComposeIosResources',
which collects resources from all source sets, included in iOS targets.

With this change:
* CocoaPods integration does not require any configuration or calling 'pod install' after changing resources.
    * Important: existing projects need to remove 'extraSpecAttributes["resources"] = ...' from build scripts, and rerun `./gradlew podInstall` once!
* Without CocoaPods, the resource directory should be added to XCode build phases once.

Resolves #3073
Resolves #3113
Resolves #3066
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants