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

Enable multiplatform building for iOS #579

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plugins {
kotlin("android") version "1.9.20" apply false
kotlin("multiplatform") version "1.9.20" apply false
kotlin("plugin.serialization") version "1.9.20" apply false
id("org.jetbrains.compose") version "1.5.10" apply false
id("com.android.library") version "8.1.3" apply false
id("com.android.test") version "8.1.3" apply false
id("androidx.baselineprofile") version "1.2.0" apply false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,21 @@ class IconsGenerator {
.addMember("%S", "unused")
.build(),
)
iconClass.addAnnotation(
AnnotationSpec.builder(ClassName("kotlin", "OptIn"))
.addMember("%L::class", MemberName("org.jetbrains.compose.resources", "ExperimentalResourceApi"))
.build(),
)

icons.sortedBy { it.name }.forEach { icon ->
val property = PropertySpec.builder(icon.name, painterType)
.getter(
FunSpec.getterBuilder()
.addAnnotation(composableAnnotation)
.addStatement(
"return %M(%L)",
MemberName("androidx.compose.ui.res", "painterResource"),
"R.drawable.${icon.resourceName}",
"return %M(%S)",
MemberName("org.jetbrains.compose.resources", "painterResource"),
"${icon.resourceName}.xml",
)
.build(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ fun main() {
val processor = IconsGenerator()

val root = Paths.get(Paths.get("").toAbsolutePath().toFile().absolutePath.removeSuffix("generator"))
val kotlinOutDir = root / "icons/src/androidMain/kotlin/"
val resourceOutDir = root / "icons/src/androidMain/res/drawable/"
val kotlinOutDir = root / "icons/src/commonMain/kotlin/"
val resourceOutDir = root / "icons/src/commonMain/resources/"
val urlIcons = "https://unpkg.com/@kiwicom/orbit-components%40latest/orbit-svgs.zip"

processor.build(urlIcons, kotlinOutDir, resourceOutDir)
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ android-sdkCommon = { module = "com.android.tools:sdk-common", version.ref = "an
android-lint-api = { module = "com.android.tools.lint:lint-api", version.ref = "android-lint" }
android-lint-impl = { module = "com.android.tools.lint:lint", version.ref = "android-lint" }
android-lint-tests = { module = "com.android.tools.lint:lint-tests", version.ref = "android-lint" }
androidx-annotation = "androidx.annotation:annotation:1.7.0"
androidx-activityCompose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
androidx-activityComposeCatalog = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityComposeCatalog" }
androidx-benchmark-macro = { module = "androidx.benchmark:benchmark-macro-junit4", version = "1.2.0" }
Expand Down
24 changes: 22 additions & 2 deletions icons/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,31 @@
plugins {
kotlin("multiplatform")
id("com.android.library")
id("org.jetbrains.compose")
id("androidx.baselineprofile")
id("org.jetbrains.dokka")
id("org.jmailen.kotlinter")
id("com.vanniktech.maven.publish.base")
}

kotlin {
applyDefaultHierarchyTemplate()

explicitApi()
androidTarget {}

androidTarget()
iosArm64()
iosSimulatorArm64()

sourceSets {
val androidMain by getting {}
val commonMain by getting {
dependencies {
implementation(compose.runtime)
implementation(compose.ui)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
}
}
}
}

Expand Down Expand Up @@ -49,6 +63,12 @@ android {
abortOnError = true
warningsAsErrors = true
}

sourceSets {
named("main") {
resources.srcDirs("src/commonMain/resources")
}
}
}

kotlinter {
Expand Down
Loading