Share
Embed
Kotlin Multiplatform Library 배포하기
2023년 05/13 (토) KotlinConf'23 Global in Songdo 행사에서의 발표자료입니다.
https://festa.io/events/3416
Sungyong An
May 13, 2023
Transcript
74 slides
-
KOTLINCONF’23 SONGDO Sungyong An NAVER WEBTOON Android GDE @fornewid ⚠
Ӓېࢲ য়ט ߊب Android ѐߊ ҙਵ۽ ೯ؾפ! ⚠ -
KOTLINCONF’23 SONGDO য়ט ߊח KotlinConf’23 ࣁ࣌ ղਊਸ ଵҊೞৈ ٜ݅णפ. •
How to Publish Your First Kotlin Multipla tf orm • Kotlin Multipla tf orm Conversions at Android Jetpack Scale Library • Compose Multipla tf orm on iOS Link: https://kotlinconf.com/talks/ -
KOTLINCONF’23 SONGDO Kotlin Multiplatform? नӏ জ ӝઓ জ Link: https://kotlinlang.org/lp/multiplatform/
নೠ ۖಬী ೧ زੌೠ ٘ܳ ҕਬೞৈ ѐߊೡ ࣻ . -
KOTLINCONF’23 SONGDO ৵ Ӓۡө? ܲ ۖಬ ѐߊо Kotlinਸ ण೧ঠ ೠ.
ఋੋਸ ࢸٙೞח Ѫ য۵. Link: https://kotlinlang.org/docs/multiplatform-mobile-introduce-your-team.html -
KOTLINCONF’23 SONGDO Ӓۧ݅… 🚀 Android ୭न UI ోఉ, Jetpack Compose!
Link: https://goo.gle/compose -
KOTLINCONF’23 SONGDO ঌҊ ח Compose APIܳ ਊ೧ ৈ۞ ۖಬী
زೞח UIܳ ٜ݅ ࣻ . ≈ Link: https://www.jetbrains.com/lp/compose-multiplatform/ -
KOTLINCONF’23 SONGDO Link: https://www.jetbrains.com/lp/compose-multiplatform/ ݃ஜղ ױੌ ٘݅ਵ۽ب Kotlin Multipla tf
orm জਸ ٜ݅ ࣻ . Kotlin Multipla tf orm Library ژ ܲ оמࢿ! -
KOTLINCONF’23 SONGDO Kotlin Multiplatform ѐ֛ਸ ೧ೞҊ, Library۽ ߓನೡ ٸ
Ҋ۰ೡ ਸ ঌইࠇפ. ݾ Multiplatform জਸ ٜ݅ ࣻ ח ജ҃ਸ оԼࠁ! -
KOTLINCONF’23 SONGDO expect / actual Kotlin Multipla tf orm ݽٕী
ۖಬ APIܳ োѾೞח ߑߨ. Link: https://kotlinlang.org/docs/multiplatform-connect-to-apis.html -
KOTLINCONF’23 SONGDO expect / actual زੌೠ ܴਸ оݴ, زੌೠ ಁఃী
ਤ೧ঠ ೠ. Link: https://kotlinlang.org/docs/multiplatform-connect-to-apis.html -
KOTLINCONF’23 SONGDO expect / actual п ۖಬ ٘ח ೞա ݽٕ
উীࢲ Source Setsਵ۽ ҳ࠙ೡ ࣻ . Link: https://kotlinlang.org/docs/multiplatform-connect-to-apis.html -
KOTLINCONF’23 SONGDO Get started ѐߊജ҃ਸ ળ࠺ೠ. • ਃೠ بҳܳ ࢸೠ:
Android Studio, XCode, JDK, KMM plugin, Kotlin plugin, CocoaPods dependency manager • ѐߊജ҃ ੜ ҳࢿغח ഛੋೠ: KDoctor Link: https://kotlinlang.org/docs/multiplatform-mobile-setup.html -
KOTLINCONF’23 SONGDO Get started Kotlin Multipla tf orm জ ۽ંܳ
݅ٚ. • Project Templateਵ۽ KMM ۽ંܳ ࢤࢿೠ. • ۽ં ҳઑܳ ഛੋೡ ࣻ ѱ Androidীࢲ Project۽ ജೠ. Link: https://kotlinlang.org/docs/multiplatform-mobile-create-first-app.html -
KOTLINCONF’23 SONGDO Get started Kotlin Multipla tf orm জਸ प೯೧ࠄ.
Link: https://kotlinlang.org/docs/multiplatform-mobile-create-first-app.html#run-your-application -
KOTLINCONF’23 SONGDO Source Sets р ױ҅ Source Setsਸ ٜ݅ ࣻ
. Link: https://kotlinlang.org/docs/multiplatform-hierarchy.html#target-shortcuts -
KOTLINCONF’23 SONGDO Restrictions • IntelliJ ژח Android Studio, Gradle ӝ߈ۄࢲ
iOS ѐߊח Ӕࢿ ڄয. • ߈۽ iOS ۖಬীࢲ ѐߊೞ۰ݶ ݓ ਃೞ. • ৈ۞ Targetਸ ਗೞח Multipla tf orm ۄ࠳۞ܻо . • kotlinx ۄ࠳۞ܻب Target ੌࠗ݅ ਗೞח Ѫٜ ݆. • Logging ۄ࠳۞ܻب ઑӘ গݒೞ. h tt ps://tonisives.com/blog/2021/03/03/kotlin-multipla tf orm-logging-libraries/ • non-JVM targetਸ Ҋ۰ೞݶ, common ٘ী Java ٘ܳ ನೣೡ ࣻ হ. • IOException, @Jvm- annotation ١ਸ ࢎਊೡ ࣻ হ. • ١١… -
KOTLINCONF’23 SONGDO Making Compose Multiplatform KOTLINCONF’23 SONGDO Googleীࢲ Compose
ࠗ࠙ਸ common Kotlinਵ۽ ࢿ೮! Link: https://github.com/androidx/androidx/tree/androidx-main/compose/ui/ui/src -
KOTLINCONF’23 SONGDO Compose Multiplatform Architecture Compose Android Skia Skiko Desktop
iOS Web Link: https://github.com/JetBrains/skiko -
KOTLINCONF’23 SONGDO iOS port Compose Skiko Skia iOS specific Kotlin/Native
UIViewController UIKit SwiftUI -
KOTLINCONF’23 SONGDO Get started Compose Multipla tf orm জਸ प೯೧ࠄ.
• Github Template Repository۽ Compose Multipla tf orm ۽ંܳ ࢤࢿೠ. Link: https://github.com/JetBrains/compose-multiplatform-template -
KOTLINCONF’23 SONGDO Get started ۽ં ҳઑܳ ಝࠁ. Link: https://github.com/JetBrains/compose-multiplatform-template#examine-the-project-structure Kotlin
Gradle desktop app Kotlin Gradle Swift Xcode Kotlin Gradle iOS app Android app Shared module Root project -
KOTLINCONF’23 SONGDO Restrictions • iOS ۽ંীࢲ ଵઑೞח Kotlin Multipla
tf orm Moduleীח ݽٚ Composable ೣࣻо private ژח internal۽݅ غযঠ ೠ. h tt ps://github.com/JetBrains/compose-multipla tf orm/issues/2346#issuecomment-1381339854 • ܻࣗझܳ ҙܻೞח ࠗ࠙ গݒೞ. (ex. Ҵয, ١) h tt ps://github.com/JetBrains/compose-multipla tf orm/issues/1255 • iOS/Webীࢲח ই ܻࣗझܳ ۪؊݂ೡ ࣻ হ. (JPG, PNG, SVG ١) h tt ps://github.com/JetBrains/compose-multipla tf orm/issues/2498 • JetBrainsীࢲ ܲ ۖಬө ഛೞৈ ҳഅೞ ࠁפ, android ৻ীח زೞ ঋח APIо ҵؘҵؘ . (गח ܻನ!) • ۖಬ݃ UXо ׳ۄࢲ ࢎਊࢿਸ Ҋ۰ೞݶ, ױੌ ٘݅ਵ۽ ҳഅೞח Ѫী ೠ҅о . • ١١… -
KOTLINCONF’23 SONGDO Link: https://github.com/fornewid/material-motion-compose Android জীࢲ ࢎਊೡ ݾਵ۽ ݅ٚ
Jetpack Compose Libraryܳ Compose Multiplatformਵ۽ ഛ೮. -
KOTLINCONF’23 SONGDO Release • Maven ࣗܳ ࢤࢿೠ. • ܳ ٜয,
Maven Central Repositoryۄݶ 1. गܳ ࢤࢿೞҊ, 2. Project URL ӂೠਸ ੋૐೠ. • زੌೠ Group IDח Repositoryܳ ೠߣ݅ ࢤࢿೞݶ ػ. Link: https://issues.sonatype.org/browse/OSSRH-80194 -
KOTLINCONF’23 SONGDO Release • ই౭ಂܳ ѱदೠ. 1. GPG ఃܳ ࢤࢿೠ.
h tt ps://central.sonatype.org/publish/requirements/gpg/ 2. ۽ંী ই౭ಂ ࠁܳ ࢸೠ. h tt ps://github.com/vanniktech/gradle-maven-publish-plugin 3. Gradle Task۽ ѱदೠ. h tt ps://central.sonatype.org/publish/publish-guide/ $ gpg --full-gen-key Link: https://developer.android.com/studio/projects/android-library // gradle.properties GROUP=io.github.fornewid POM_ARTIFACT_ID=material-motion-compose-core POM_PACKAGING=aar VERSION_NAME=1.0.0 ... // {library_module_name}/build.gradle plugins { id 'com.vanniktech.maven.publish' } ./gradlew publish --no-daemon --no-parallel signing.keyId={GPG_KEY} signing.password={password} signing.secretKeyRingFile=release/secring.gpg mavenCentralUsername=fornewid mavenCentralPassword=*********** 🔑 -
KOTLINCONF’23 SONGDO Release • ই౭ಂܳ ҕѐೠ. h tt ps://s01.oss.sonatype.org/#stagingRepositories
• Close, Release ࣽਵ۽ ೯ೠ. • Gradle Taskب ઁҕػ. Link: https://central.sonatype.org/publish/release/ ./gradlew closeAndReleaseRepository -
KOTLINCONF’23 SONGDO Develop & Release Tools ߈ࠂ೧ࢲ ѐߊ/ߓನೞӝ औѱ, ৈ۞о
بҳ بਸ ߉ਸ ࣻ . • Public API: Kotlin Explicit API mode • Compatibility: Metalava • Code Format: spotless • Documentation: KDoc + Dokka, .md + mkdocs + Github Pages • Publish: vanniktech/gradle-maven-publish-plugin • CI: Github Actions • ١١… -
KOTLINCONF’23 SONGDO • APIী Ӕ৬ return typeਸ ݺदೞب۾, ҃Ҋ
য়ܨܳ ߊࢤदఅ. Public API Kotlin Explicit API mode 💾 {library_module}/build.gradle android { kotlinOptions { freeCompilerArgs += '-Xexplicit-api=warning' } } Link: https://github.com/Kotlin/KEEP/blob/master/proposals/explicit-api-mode.md -
KOTLINCONF’23 SONGDO Compatibility Metalava • API Metadataܳ ୶ೞৈ ഐജࢿ ߸҃غחܳ
хೠ. Link: https://github.com/tylerbwong/metalava-gradle 💾 .github/workflows/build.yaml ./gradlew metalavaCheckCompatibility package com.webtoonscorp.android.readmore { public final class ReadMoreTextView extends androidx.appcompat.widget.AppCompatTextView { ctor public ReadMoreTextView(android.content.Context context, optional android.util.AttributeSet? attrs, optional int defStyleAttr); ctor public ReadMoreTextView(android.content.Context context, optional android.util.AttributeSet? attrs); ctor public ReadMoreTextView(android.content.Context context); method public boolean isExpanded(); method public void setExpanded(boolean expanded); method public void setOnStateChangeListener(com.webtoonscorp.android.readmore.ReadMoreTextView.OnStateChangeListener listener); method public void toggle(); field public static final int OVERFLOW_CLIP = 1; // 0x1 field public static final int OVERFLOW_ELLIPSIS = 2; // 0x2 } public static fun interface ReadMoreTextView.OnStateChangeListener { method public void onStateChanged(boolean expanded); } } Generate: 💾 {library_module}/api/current.api ./gradlew metalavaGenerateSignature If changes APIs intentionally: -
KOTLINCONF’23 SONGDO • ࣗझ٘ ഋध ৢ߄ܲ Ѩࢎೠ. • ࣗझ٘ী LICENSE
ࢳਸ ୶оೞח Ѫب زചೡ ࣻ . Code Format spotless Link: https://github.com/diffplug/spotless // build.gradle plugins { id 'com.diffplug.spotless' version '5.12.4' } subprojects { apply plugin: 'com.diffplug.spotless' spotless { kotlin { target '**/*.kt' targetExclude("$buildDir/**/*.kt") targetExclude('bin/**/*.kt') ktlint(“0.42.1") licenseHeaderFile rootProject.file('spotless/copyright.kt') } } } // spotless/copyright.kt /* * Copyright $YEAR SOUP * * ... */ -
KOTLINCONF’23 SONGDO • APIী যك ٘ ࢳਸ, API ޙࢲ۽ ߸ജೡ
ࣻ . Documentation KDoc + Dokka Link: https://kotlinlang.org/docs/kotlin-doc.html, https://github.com/Kotlin/dokka 💾 .github/workflows/publish-docs.yml 💾 generate_docs.sh # Generate API docs ./gradlew dokkaHtmlMultiModule jobs: update_draft_release: ... steps: ... - name: Generate docs run: ./generate_docs.sh ... -
KOTLINCONF’23 SONGDO Documentation .md + mkdocs + Github Pages •
.md ੌী ۄ࠳۞ܻী ೠ ࢸݺਸ ܻ೧فҊ, ਢಕ۽ ߸ജೠ. Link: https://www.mkdocs.org/ jobs: update_draft_release: ... steps: ... - name: Install dependencies run: | python3 -m pip install --upgrade pip python3 -m pip install mkdocs python3 -m pip install mkdocs-material - name: Build site run: mkdocs build ... 💾 .github/workflows/publish-docs.yml 💾 mkdocs.yml ... remote_branch: gh-pages # Navigation nav: - "Overview": index.md - "View": - 'Guide': readmore-view.md - 'API': api/readmore-view/ # Configuration theme: name: material language: "en" -
KOTLINCONF’23 SONGDO Documentation .md + mkdocs + Github Pages •
Github Actionਸ ਊೞৈ, ࢤࢿػ ਢಕܳ Github Page۽ ഐझೡ ࣻ . Link: https://github.com/peaceiris/actions-gh-pages on: push: tags: - v* jobs: update_draft_release: ... steps: ... - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./site 💾 .github/workflows/publish-docs.yml -
KOTLINCONF’23 SONGDO Github Actions • খࢲ ࣗѐೠ بҳٜਸ ۽ஸݠनীࢲ ࣻزਵ۽
Ѩࢎೞ ঋҊ, زചೡ ࣻ . Link: https://docs.github.com/ko/actions CI (Continuous Integration) -
KOTLINCONF’23 SONGDO Develop build.gradle 1. Kotlin pluginਸ ߸҃ೠ. 2. Targetਸ
ࢶೠ. 3. Source Setਸ ೞҊ, dependenciesܳ ӟ. • ߈٘द Groovyীࢲ KTS۽ ߸҃೧ঠ ೞח Ѫ ইפ. Link: https://kotlinlang.org/docs/multiplatform-dsl-reference.html, https://developer.android.com/build/migrate-to-kotlin-dsl -
KOTLINCONF’23 SONGDO • ҕాചೞ۰ח ٘ח commonMainਵ۽ زೠ. • ӝઓ Android
٘ח ইېۢ ӟ. • ӝࠄਵ۽ androidInstrumentedTestীࢲח commonTestী Ӕೡ ࣻ হ. Develop Source Setsী ݏࢲ srcী ۖಬ ਊ ಫ؊ܳ ୶оೠ. Link: https://kotlinlang.org/docs/whatsnew18.html#kotlinsourceset-naming-schema Kotlin 1.8 Kotlin 1.8 റ Android -
KOTLINCONF’23 SONGDO Develop ҕా ٘۽ ߸҃೧ঠ ೠ. ইפݶ expect
/ actualਸ ҳഅ೧ঠ ೠ. Link: https://github.com/fornewid/material-motion-compose/pull/190/files#diff -
KOTLINCONF’23 SONGDO Develop & Release Tools ೯ ݽف Kotlin Multipla
tf ormਸ ਗೞח بҳ. (ױ, ߡ ഛੋ೧ࠅ Ѫ!) • Public API: Kotlin Explicit API mode ✅ • Compatibility: Metalava ✅ • Code Format: spotless ✅ • Documentation: KDoc + Dokka ✅, .md + mkdocs + Github Pages ✅ • Publish: vanniktech/gradle-maven-publish-plugin ✅ • CI: Github Actions ⚠ • ١١… -
KOTLINCONF’23 SONGDO Github Actions • ਗೞח Targetী ݏѱ, runnerܳ ઑ೧ঠ
೮. Link: https://docs.github.com/ko/actions/using-workflows/workflow-syntax-for-github-actions#choosing-github-hosted-runners CI (Continuous Integration) -
KOTLINCONF’23 SONGDO Release • ߓನೞח ߑߨ Ѣ زੌೞ݅, Ѿҗޛ ׳ۄ.
(vanniktech/gradle-maven-publish-plugin ࢎਊೞח Ѫਸ ୶ୌ!) Link: https://search.maven.org/search?q=material-motion-compose-core Android ۄ࠳۞ܻܳ ѱदೞ۰ݶ variant nameਸ ݺद೧ঠ פ. Link: https://kotlinlang.org/docs/multiplatform-publish-lib.html -
KOTLINCONF’23 SONGDO Users ۄ࠳۞ܻ ઓࢿ ୶оೞӝ • ݽٚ Source Setਸ
ਗೞח ۄ࠳۞ܻח ҕా Source Setী ୶оೡ ࣻ . Kotlin Multipla tf orm plugin п Source Setী ݏח زਵ۽ ୶о೧ળ. Link: https://kotlinlang.org/docs/multiplatform-add-dependencies.html#library-shared-for-all-source-sets -
KOTLINCONF’23 SONGDO Users ۄ࠳۞ܻ ઓࢿ ୶оೞӝ • ౠ Source Setীࢲ݅
ݣ౭ۖಬ ۄ࠳۞ܻܳ ࢎਊೡ ࣻب . • ݣ౭ۖಬ ۄ࠳۞ܻо ইפۄݶ ഒزغ ঋب۾, ۖಬ ݺடਸ ࢎਊೞ ঋח Ѫਸ ӂೠ. Link: https://kotlinlang.org/docs/multiplatform-add-dependencies.html#library-used-in-specific-source-sets