JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.24k stars 1.11k forks source link

Pack all resources to assets on the android target. #4965

Closed terrakok closed 6 days ago

terrakok commented 1 week ago

The PR changes the android resources packaging. Now all resources are packed to the android assets (not only fonts). It unblocks usage android URIs to the resources in a WebView or other external resource consumers. Additionally the PR fixes Android Studio Compose Previews work with multiplatform resources:

For a backward compatibility the resources library tries to read resources in java resources if assets were not found.

Fixes https://github.com/JetBrains/compose-multiplatform/issues/4877 Fixes https://github.com/JetBrains/compose-multiplatform/issues/4503 Fixes https://github.com/JetBrains/compose-multiplatform/issues/4932 Fixes https://github.com/JetBrains/compose-multiplatform/issues/4476 Fixes https://github.com/JetBrains/compose-multiplatform/issues/3828

Release Notes

Features - Resources

sergeshustoff commented 1 week ago

I might be wrong here, but it looks like it might lead to fixing android previews with multiplatform resources (#4932, #4476) eventually... If CopyResourcesToAndroidAssetsTask is run before whatewer Android Studio does to render previews and AndroidContextProvider.ANDROID_CONTEXT is set somehow from the preview (or ContextLocal is used instead)

terrakok commented 1 week ago

I checked a preview with the new packaging but it doesn't work because android assets is semi available in the preview mode. It works strange for a regular android project too: 1) Assets are not available unless you run the project first time. 2) Assets are only available in the same module where your preview is.

UPDATE: the problem is addGeneratedSourceDirectory function doesn't work with AS Compose Preview :feelsgood:

ISSUE: https://issuetracker.google.com/348208777

terrakok commented 6 days ago

Now Android Studio Compose Preview works :godmode:

image
AhmedTawfek commented 2 days ago

Now Android Studio Compose Preview works :godmode:

image

Sorry for the question, but Iam currently having these versions in my compose multiplaform project, what versions do I need to use in case of solving the preview issues in AS ?

compose-plugin = "1.6.11" androidx-compose = "1.6.8" kotlin = "1.9.23" jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" } androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "androidx-compose" } androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "androidx-compose" }