Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Android Preview #18

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ kotlin {
api("androidx.activity:activity-compose:1.6.1")
api("androidx.appcompat:appcompat:1.6.1")
api("androidx.core:core-ktx:1.9.0")
api(compose.preview)
api(compose.uiTooling)
}
}
val iosX64Main by getting
Expand All @@ -62,6 +64,13 @@ kotlin {
}

android {
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move Compose compiler version to gradle.properties?
Or even reuse Compose Multilatform Compiler?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even reuse Compose Multilatform Compiler?

the versions usually don't match, we can't reuse them

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, there are issues when we add this to our template:

  1. we apply 2 Compose compiler plugins (androidx one, and jetbrains one). It is not obvious, which will be applied
  2. the jetbrains Gradle plugin applies compiler plugin depending on the Kotlin version. If we downgrade Kotlin to 1.8.21, the Gradle plugin will apply jetbrains compose compiler 1.4.*, but because the android compiler is hardcoded now, android won't compile
  3. it adds an additional action when we need to update templates - we should map the compilers and add an appropriate version.

So, we can't officially recommend this approach yet. Only as a workaround if users need this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible reliable solutions:

  1. add an internal mapping Kotlin -> androidx compiler, and apply buildFeatures + composeOptions implicitly in the Gradle plugin
  2. exclude applying androidx compiler somehow, and always apply jetbrains compiler

Both require changes in our Gradle plugin

Copy link
Member

@eymar eymar Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do other target work with this change? I'm wondering if different compose compiler plugins don't mixup.

Or even reuse Compose Multilatform Compiler?

Ideally, Compose Multilatform Compiler should work for anroid too. I'm just not sure if we can configure it in android.composeOptions....

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, Compose Multilatform Compiler should work for anroid too

I even say - must work, and it is how it works for Android now.

}

compileSdk = (findProperty("android.compileSdk") as String).toInt()
namespace = "com.myapplication.common"

Expand Down
10 changes: 9 additions & 1 deletion shared/src/androidMain/kotlin/main.android.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview

actual fun getPlatformName(): String = "Android"

@Composable fun MainView() = App()
@Composable
fun MainView() = App()

@Preview
@Composable
private fun AndroidPreview() {
MainView()
}