Fixes#4863
Before this update, when a new `resource` value was passed to
`org.jetbrains.compose.resources.Font` composable, it kept the original
value.
Test sample code. `Res.font` here is autogenerated from
`commonMain/composeResources/font/` folder content.
```kt
var flag by remember {
mutableStateOf(false)
}
Column {
Text(
"hey",
fontFamily = FontFamily(Font(if (flag) Res.font.HelveticaNeueMedium else Res.font.COMICSANS, FontWeight.Normal))
)
Switch(checked = flag, onCheckedChange = { flag = it })
}
```
## Release Notes
### Fixes - Resources
- Fix a cached font if the resource acessor was changed
Changes:
- update all examples to Kotlin 2.0
- migrate to using kotlin("plugin.compose") for Compose compiler
configuration
- remove deprecated Compose Web gradle API usages
- added a workaround for
https://github.com/JetBrains/compose-multiplatform/issues/4848 in
Jetsnack example
Testing:
- `./gradlew build` in every example
- run some examples in simulators (or desktop, browser)
AGP 7 isn't supported by Jetpack Compose 1.7 (which we'll use in CMP
1.7) and by Lifecycle 2.8.
After this CI is merged, I will:
- revert the revert of [the skiko API
fix](https://github.com/JetBrains/compose-multiplatform-core/pull/1328)
in jb-main
- raise the AGP version on TeamCity
### Details
It was discovered after merging [the skiko API
fix](https://github.com/JetBrains/compose-multiplatform-core/pull/1328).
We had `D8: java.lang.NullPointerException` error on TeamCity. After
investigating dependencies, it appears that previous the dependencies
were incorrect:
```
org.jetbrains.compose.material:material -> androidx.compose.material:material:1.6.7 -> androidx.lifecycle:lifecycle-livedata-core:2.6.1
```
And the new are correct, but aren't supported by AGP 7:
```
org.jetbrains.compose.material:material -> org.jetbrains.compose.ui -> org.jetbrains.androidx.lifecycle:lifecycle-common -> androidx.lifecycle:lifecycle-common:2.8.0 -> androidx.lifecycle:lifecycle-livedata-core:2.8.0
```
The dependency chains was printed by this command on the
`commonResources` test project:
```
./gradlew dependencyInsight --configuration demoDebugRuntimeClasspath --dependency androidx.lifecycle:lifecycle-livedata-core
```
## Testing
1. Create a pure Jetpack Compose project via Android Studio Hedgehog |
2023.1.1 Patch 2
2. Set Jetpack Compose to 1.7.0-beta01
3. Downgrade AGP to 7.4.0
4. Run
5. See the error:
```
ERROR:C:\Users\igord\.gradle\caches\transforms-4\7fcc63c0892ce9266300d6463c3c751d\transformed\lifecycle-livedata-core-2.8.0-runtime.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
Execution failed for task ':app:mergeExtDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Failed to transform lifecycle-livedata-core-2.8.0.aar (androidx.lifecycle:lifecycle-livedata-core:2.8.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=24, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
> Execution failed for DexingNoClasspathTransform: C:\Users\igord\.gradle\caches\transforms-3\4aae1223695d47acd0b149bb5811ca5f\transformed\lifecycle-livedata-core-2.8.0-runtime.jar.
> Error while dexing.
```
6. Change AGP to 8.1.0
7. The run is successful.
## Release Notes
### Breaking changes - Android
- Minimal supported AGP raised to 8.1.0
Fixes: https://github.com/JetBrains/compose-multiplatform/issues/4823
In https://github.com/JetBrains/compose-multiplatform/pull/4796 we
intentionally started to configure the web app for all k/js and k/wasm
targets. The configuration involves adding a dependency on skiko-wasm
runtime and unpacking it.
Some projects don't need skiko-wasm-runtime (like those based on
compose.html or just compose.runtime).
**Solution:**
We check if there is a dependency on org.jetbrains.compose.ui libraries
(including transitive dependencies). If we find it, then we enable
skikoUnpack task. Otherwise it's disabled.
## Testing
- Build the gradle plugin locally (with this change)
- Used it in our html landing example:
https://github.com/JetBrains/compose-multiplatform/blob/master/examples/html/landing
- Run `./gradlew jsBrowserDistribution`, check
`.../compose-multiplatform/examples/html/landing/build/dist/js/productionExecutable`
and see NO skiko.* files added there
- Then add `implementation(compose.foundation)` dependency in
build.gradle.jts and run `./gradlew clean jsBrowserDistribution` again -
the build/dist contains skiko.* now
Before the fix we could cancel a coroutine and the cancelled deferred
was saved in cache.
## Release Notes
### Fixes - Resources
- _(prerelease fix)_ Fix a cached empty resource on a Compose for Web if
the resource loading was canceled during progress
Since 1.6.10 Compose for Web goes to Alpha and experimental
configuration is not needed anymore. We'll configure the web targets by
default when they're added to projects.
## Testing
- I built the plugin to mavenLocal. And used it in a couple of our
samples.
- After gradle sync completes, I observe the Deprecation warning in
build.gradle.kts on `compose.experimental.web` usages (see a screenshot
below)
<img width="1022" alt="Screenshot 2024-05-10 at 15 41 14"
src="https://github.com/JetBrains/compose-multiplatform/assets/7372778/e8ede073-8d34-4dd7-ae74-c83ca0ff5c96">
Then I remove deprecated API usages and test that the project works
without it:
- run `./gradlew clean` just in case
- run the app: `./gradlew wasmJsBrowserRun` and `./gradlew jsBrowserRun`
- both run fine
- build the production distribution: `./gradlew
wasmJsBrowserDistribution`
- `cd ..../build/dist/wasmJs/productionExecutable` and run `python -m
http.server`, open a browser at `http://localhost:8000` - the app should
work the same way it works with gradle tasks above
<!-- Optional -->
This should be tested by QA
## Release Notes
### Highlights - Web
- Compose for Web goes to Alpha!
Some experimental Compose Multiplatform Gradle plugin APIs for web app
configuration were deprecated. Their usage is not required anymore.
The PR sets a static path to the compose resources for the cocoapods
integration because there maybe only one integration framework for a
gradle module.
Fixes https://github.com/JetBrains/compose-multiplatform/issues/4720
## Release Notes
### Fixes - Resources
- _(prerelease fix)_ Fix resources with cocoapods integration
The Compose Multiplatform Resources with the mulimodule.publication
support is a new feature and may have some not found problems. The PR
introduces a gradle property to switch back to the previous behavior:
`org.jetbrains.compose.resources.multimodule.disable=true`
## Testing
After update to Kotlin 2.0.0 and CMP 1.6.10 all projects will be
switched to the new logic with the multimodule support.
Gradle info output should contain a message:
```
Configure KMP resources
```
If the new feature breaks user's projects they may add
`org.jetbrains.compose.resources.multimodule.disable=true` to the
`gradle.properties` to disable it. After that Gradle info output will
contain:
```
Configure compose resources
```
## Release Notes
### Resources
To disable the Compose Resources publication and the multimodule support
in cases of problems add
`org.jetbrains.compose.resources.multimodule.disable=true` to the root
`gradle.properties`.
The intermediate `iosMain` source was previously removed here:
https://github.com/JetBrains/compose-multiplatform/pull/3956 And it
worked fine.
According to the doc
https://kotlinlang.org/docs/whatsnew1920.html#set-up-the-target-hierarchy
:
> If you want to have additional source sets that the default hierarchy
template doesn't provide, for example, one that shares code between a
macOS and a JVM target, adjust the hierarchy by reapplying the template
explicitly with applyDefaultHierarchyTemplate() and configuring
additional source sets manually as usual with dependsOn()
Now we have an additional custom source set named 'jsWasmMain',
therefore we need to have `applyDefaultHierarchyTemplate()`.
- add imageviewer project to validateExamplesWithJs.sh
- update dmmy_map image and add a notice about using Open Data License
- update web app setup (index.html) and remove redundant files
- temporary disable configuration cache due to k/wasm issue
https://youtrack.jetbrains.com/issue/KT-64851 (fixed in 2.0)
- Apply window insets for UI containers
- Update the screenshot
- Align gradle.properties with other examples
- Add jetsnack to all example verification scripts
Implemented two new experimental functions:
```kotlin
/**
* Retrieves the byte array of the drawable resource.
*
* @param environment The resource environment, which can be obtained from [rememberResourceEnvironment] or [getSystemResourceEnvironment].
* @param resource The drawable resource.
* @return The byte array representing the drawable resource.
*/
@ExperimentalResourceApi
suspend fun getDrawableResourceBytes(
environment: ResourceEnvironment,
resource: DrawableResource
): ByteArray {...}
/**
* Retrieves the byte array of the font resource.
*
* @param environment The resource environment, which can be obtained from [rememberResourceEnvironment] or [getSystemResourceEnvironment].
* @param resource The font resource.
* @return The byte array representing the font resource.
*/
@ExperimentalResourceApi
suspend fun getFontResourceBytes(
environment: ResourceEnvironment,
resource: FontResource
): ByteArray {...}
```
fixes https://github.com/JetBrains/compose-multiplatform/issues/4360