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

[1.6.0-beta01] unable to access resources #4189

Closed
Kashif-E opened this issue Jan 27, 2024 · 15 comments
Closed

[1.6.0-beta01] unable to access resources #4189

Kashif-E opened this issue Jan 27, 2024 · 15 comments
Labels
bug Something isn't working resources

Comments

@Kashif-E
Copy link

I updated my project to the latest beta to use the new resources using the generated Res classes i am unable to access and resource. I have tested drawable and fonts and its not a multimodule project.

Affected Platforms.

  • Android
  • Desktop
  • iOS

Versions

  • Kotlin version: 1.9.21
  • Compose Multiplatform version: 1.6.0-beta01

To Reproduce
Can be reproduced in this branch https://github.com/Kashif-E/KMPMovies/tree/14-remove-seperate-android-app-and-desktop-app

Screenshots
Screenshot 2024-01-27 at 1 53 01 PM

.

@Kashif-E Kashif-E added bug Something isn't working submitted labels Jan 27, 2024
@mahramane
Copy link

mahramane commented Jan 27, 2024

Hi
i have the same problem
how can we generate the Res.kt class?

@Kashif-E
Copy link
Author

@mahramane you are supposed to re-import the project after applying the resources plugin and create the top level composeResources directory with your resources

@mahramane
Copy link

@Kashif-E can you please help me how can i add resources plugin?

@terrakok
Copy link
Collaborator

apply the compose plugin after the android
https://github.com/Kashif-E/KMPMovies/blob/d389251c26d99591b94048d6568276ca1a61ac7d/MoviesApp/build.gradle.kts#L8
it was fixed already in the master: 3040ea8

@Kashif-E
Copy link
Author

fonts not loading if they are in ttf format only otf is working, what can be the reason for that? @terrakok

@mahramane
Copy link

mahramane commented Jan 28, 2024

GenerateResClassTask was failed:
.DS_Store is not directory! Raw files should be placed in 'composeResources/files' directory.

also i get this error in mac
please fix it

@Kashif-E
Copy link
Author

@mahramane i have added a comment on the issue you created it will solve it for now

@terrakok
Copy link
Collaborator

@Kashif-E check your ttf fonts. it should work
image

@Kashif-E
Copy link
Author

Hey @terrakok ill check this in the morning

@ctn-mobile-innovation
Copy link

After updating to 1.6.0-beta1 and migrating resources getting crash in android but iOS working fine.

Crash Log :
Process: com.example.app.android, PID: 9465
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:558)
at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.reflect.InvocationTargetException
at
java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 
Caused by: org.jetbrains.compose.resources.MissingResourceException: Missing resource with path: drawable/up_icon.xml
at org.jetbrains.compose.resources.ResourceReader_jvmAndAndroidKt.readResourceBytes(ResourceReader.jvmAndAndroid.kt:9)
at org.jetbrains.compose.resources.ResourceReaderKt$DefaultResourceReader$1.read(ResourceReader.kt:23)
at org.jetbrains.compose.resources.ImageResourcesKt$loadImage$2$deferred$1$1$1.invokeSuspend(ImageResources.kt:134)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:281)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:1)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source:1)
at org.jetbrains.compose.resources.ResourceState_blockingKt.rememberResourceState(ResourceState.blocking.kt:15)
at org.jetbrains.compose.resources.ImageResourcesKt.vectorResource(ImageResources.kt:99)
at org.jetbrains.compose.resources.ImageResourcesKt.painterResource(ImageResources.kt:56)
at com.example.app.utility.ImageViewKt.FromLocalDrawable(ImageView.kt:24)

@nicolasf
Copy link

nicolasf commented Apr 5, 2024

Similar issue here.
Trying to load a font resource from composeResources fails on Android but works on iOS and Desktop.

After investigating further, it seems like the build process is caching the resources after the first build, and if you add/change the TTF files on composeResources, the next builds use the previously cached resources instead of the new ones.

A workaround is to clean the build files when you change these resources and rebuilding.

I'm not familiar with the code that handles the resources at build time, so I won't be able to to help fixing the code, but I hope this info helps.

Here's a step by step to reproduce and identify the issue:

  1. Create a project template with one font (https://terrakok.github.io/Compose-Multiplatform-Wizard/)
  2. Do a first build
./gradlew task assembleDebug
  1. Check the generated APK
binwalk ./composeApp/build/outputs/apk/debug/composeApp-debug.apk | grep -i ttf
11135653      0xA9EAA5        Zip archive data, v0.0 compressed size: 38709, uncompressed size: 73332, name: assets/font/MyFont-Bold.ttf
  1. Add another font (copy/paste the same one with different name), rebuild and check apk. Font is not on APK.
./gradlew task assembleDebug

binwalk ./composeApp/build/outputs/apk/debug/composeApp-debug.apk | grep -i ttf
11135653      0xA9EAA5        Zip archive data, v0.0 compressed size: 38709, uncompressed size: 73332, name: assets/font/MyFont-Bold.ttf

Workaround:
5) Clean, Rebuild and Check

./gradlew task clean

./gradlew task assembleDebug

binwalk ./composeApp/build/outputs/apk/debug/composeApp-debug.apk | grep -i ttf
11135939      0xA9EBC3        Zip archive data, v0.0 compressed size: 38709, uncompressed size: 73332, name: assets/font/MyFont-Bold.ttf
11174705      0xAA8331        Zip archive data, v0.0 compressed size: 38709, uncompressed size: 73332, name: assets/font/MyFont2-Bold.ttf

@terrakok
Copy link
Collaborator

terrakok commented Apr 5, 2024

@nicolasf what a compose version do you use?

@nicolasf
Copy link

nicolasf commented Apr 5, 2024

[versions]

kotlin = "1.9.23"
compose = "1.6.1"

@terrakok
Copy link
Collaborator

terrakok commented Apr 5, 2024

It was fixed here: c43b64d

You can use compose = "1.6.10-dev1523" or newer

@nicolasf
Copy link

nicolasf commented Apr 5, 2024

Did a quick test with 1.6.10-dev1561 and it's fixed.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resources
Projects
None yet
Development

No branches or pull requests

6 participants