According to https://developer.android.com/build/jdks we should:
1. [use JDK 17 for API 34](https://developer.android.com/build/jdks#compileSdk)
2. [use toolchain](https://developer.android.com/build/jdks#toolchain):
```
We recommend that you always specify the Java toolchain, and either ensure that the specified JDK is installed, or add a toolchain resolver to your build.
```
As we don't want to force people to have JDK 17 on their machine, we apply toolchain resolver that is recommended by Gradle:
```
id("org.gradle.toolchains.foojay-resolver-convention") version("0.4.0")
```
## Test
1. Remove JDK 17 from the computer, remove `jvmToolchain(17)`
2. Run `./gradlew assembleDebug`
3. It should fail with:
```
> Could not create task ':androidApp:compileDebugJavaWithJavac'.
> Failed to calculate the value of task ':androidApp:compileDebugJavaWithJavac' property 'javaCompiler'.
> No matching toolchains found for requested specification: {languageVersion=17, vendor=any, implementation=vendor-specific} for WINDOWS on x86_64.
> No locally installed toolchains match and toolchain download repositories have not been configured.
```
4. restore `jvmToolchain(17)`
5. Run `./gradlew assembleDebug` again
6. It should succeed
## Issues
Fixes https://github.com/JetBrains/compose-multiplatform/issues/3615
* Update versions to CM 1.5.1 and kotlin 1.9.10
* Add explicit dependencies on compose.ui and compose.foundation in examples/chat/jsApp
* Update CHANGELOG.md
* fix typo
* Add Dependencies for 1.5.1 Changelog
Sometimes we need to report warnings during the configuration phase.
For example, when Androidx Compose Compiler is used with
non-JVM targets (e.g. iOS/js), we want to warn users
that using non-JB compiler with non-JVM targets is not supported.
The default way of reporting warnings in Gradle is using a logger.
For example we could write something like:
```
abstract class ComposePlugin : Plugin<Project> {
override fun apply(project: Project) {
if (project.hasNonJvmTargets() && project.usesNonJBComposeCompiler()) {
project.logger.warn("...")
}
}
}
```
This approach has a few issues:
1. When the Configuration Cache is enabled, project's configuration might
get skipped altogether, and the warning won't be printed.
2. If a project contains multiple Gradle modules (subprojects),
the warning might be printed multiple times. That might be OK
for some warnings. But repeating exactly the same warning
10s or 100s is unnecessary.
The only way to share the state between Gradle modules,
while preserving compatibility with the Configuration Cache,
is to define Gradle Build Service.
In 1.5.0 we used Gradle Build Service mechanism for both warnings.
However, I did not know that:
* only the service's parameters are persisted in the Configuration Cache.
The service itself is not persisted.
* if a service instance is materialized during the configuration
phase, then all changes made to its parameters will not be
visible to that particular instance (but they will be visible to the
next instance).
So the only way to report diagnostics with configuration cache without
repetition is to define a service that is not materialized
during the configuration phase (i.e. serviceProvider.get() is not called),
add to add warnings to a set property of the service.
This change implements that.
Resolves#3595
The new android multiplatform plugin will have type `jvm` but doesn't
inherit from the KotlinJvmTarget type, which makes the compose
multiplatform gradle plugin not useable with the new android gradle
plugin for multiplatforms builds.
It crashes on Android, because it doesn't have slice method yet (only starting from API 34):
```
java.lang.NoSuchMethodError: No virtual method slice(II)Ljava/nio/MappedByteBuffer; in class Ljava/nio/MappedByteBuffer; or its super classes (declaration of 'java.nio.MappedByteBuffer' appears in /apex/com.android.art/javalib/core-oj.jar)
at org.jetbrains.codeviewer.platform.JvmFileKt$toProjectFile$1$readLines$2.get(JvmFile.kt:68)
at org.jetbrains.codeviewer.ui.editor.EditorKt$Editor$1.invoke$content(Editor.kt:47)
at org.jetbrains.codeviewer.ui.editor.EditorKt$Editor$1.access$invoke$content(Editor.kt:37)
at org.jetbrains.codeviewer.ui.editor.EditorKt$Editor$1$1.get(Editor.kt:57)
at org.jetbrains.codeviewer.ui.editor.EditorViewKt$Lines$1$1$1$1.invoke(EditorView.kt:84)
at org.jetbrains.codeviewer.ui.editor.EditorViewKt$Lines$1$1$1$1.invoke(EditorView.kt:82)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:138)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.foundation.lazy.LazyListItemProviderImpl$Item$1.invoke(LazyListItemProvider.kt:79)
at androidx.compose.foundation.lazy.LazyListItemProviderImpl$Item$1.invoke(LazyListItemProvider.kt:77)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
at androidx.compose.foundation.lazy.layout.LazyLayoutPinnableItemKt.LazyLayoutPinnableItem(LazyLayoutPinnableItem.kt:54)
at androidx.compose.foundation.lazy.LazyListItemProviderImpl.Item(LazyListItemProvider.kt:77)
at androidx.compose.foundation.lazy.layout.LazyLayoutItemContentFactoryKt$SkippableItem$1.invoke(LazyLayoutItemContentFactory.kt:135)
at androidx.compose.foundation.lazy.layout.LazyLayoutItemContentFactoryKt$SkippableItem$1.invoke(LazyLayoutItemContentFactory.kt:134)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
```
The regression was introduced in Update experimental Codeviewer with changes from non-experimental one (#2975).
Replacing with code that is available for Android
* The camera should stop working after leaving CameraView on Android.
* Update examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/CameraView.android.kt
* Fix cache kind management with nested subprojects
Previously, cache kind property management
worked incorrectly when Compose Gradle plugin
was applied to both parent and child subprojects,
e.g. :compose-subproject-1:compose-subproject-2.
With this example the plugin would successfully
set the property for compose-subproject-1,
but then for compose-subproject-2 the following snippet
would fail:
```
if (project.hasProperty(targetCacheKindPropertyName)) {
project.setProperty(targetCacheKindPropertyName, NONE_VALUE)
}
```
because project.hasProperty would have return true
(because it checks parent subproject properties too),
but project.setProperty would fail, because
parent project's properties are read only.
Warnings were also handled incorrectly in this case,
because during the configuration of compose-subproject-1 we might set
`kotlin.native.cacheKind.ios*=none`,
which would then cause a warning during the configuration of compose-subproject-2.
To avoid incorrect warnings, we now
record the snapshot of relevant properties
during Compose Multiplatform build service initialization
Resolves#3515
* Fix issues from code review