Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin Multiplatform Library 배포하기

Kotlin Multiplatform Library 배포하기

2023년 05/13 (토) KotlinConf'23 Global in Songdo 행사에서의 발표자료입니다.
https://festa.io/events/3416

Sungyong An

May 13, 2023
Tweet

More Decks by Sungyong An

Other Decks in Programming

Transcript

  1. KOTLINCONF’23 SONGDO Sungyong An NAVER WEBTOON Android GDE @fornewid ⚠

    Ӓېࢲ য়ט ߊ಴ب Android ѐߊ੗ ҙ੼ਵ۽ ૓೯ؾפ׮! ⚠
  2. 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/
  3. KOTLINCONF’23 SONGDO Kotlin Multiplatform? नӏ জ ӝઓ জ Link: https://kotlinlang.org/lp/multiplatform/

    ׮নೠ ೒ۖಬী ؀೧ زੌೠ ௏٘ܳ ҕਬೞৈ ѐߊೡ ࣻ ੓׮.
  4. KOTLINCONF’23 SONGDO ৵ Ӓۡө? ׮ܲ ೒ۖಬ ѐߊ੗о Kotlinਸ ೟ण೧ঠ ೠ׮.

    ఋੋਸ ࢸٙೞח Ѫ਷ য۵׮. Link: https://kotlinlang.org/docs/multiplatform-mobile-introduce-your-team.html
  5. KOTLINCONF’23 SONGDO ੉޷ ঌҊ ੓ח Compose APIܳ ੉ਊ೧ ৈ۞ ೒ۖಬী

    ز੘ೞח UIܳ ٜ݅ ࣻ ੓׮. ≈ Link: https://www.jetbrains.com/lp/compose-multiplatform/
  6. KOTLINCONF’23 SONGDO Kotlin Multiplatform੄ ѐ֛ਸ ੉೧ೞҊ, 
 Library۽ ߓನೡ ٸ

    Ҋ۰ೡ ੼ਸ ঌইࠇפ׮. ݾ಴ Multiplatform জਸ ٜ݅ ࣻ ੓ח ജ҃ਸ оԼࠁ੗!
  7. KOTLINCONF’23 SONGDO expect / actual Kotlin Multipla tf orm ݽٕী

    ೒ۖಬ APIܳ োѾೞח ߑߨ. Link: https://kotlinlang.org/docs/multiplatform-connect-to-apis.html
  8. KOTLINCONF’23 SONGDO expect / actual زੌೠ ੉ܴਸ о૑ݴ, زੌೠ ಁః૑ী

    ਤ஖೧ঠ ೠ׮. Link: https://kotlinlang.org/docs/multiplatform-connect-to-apis.html
  9. KOTLINCONF’23 SONGDO expect / actual п ೒ۖಬ੄ ௏٘ח ೞա੄ ݽٕ

    উীࢲ Source Setsਵ۽ ҳ࠙ೡ ࣻ ੓׮. Link: https://kotlinlang.org/docs/multiplatform-connect-to-apis.html
  10. 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
  11. 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
  12. KOTLINCONF’23 SONGDO Get started Kotlin Multipla tf orm জਸ प೯೧ࠄ׮.

    Link: https://kotlinlang.org/docs/multiplatform-mobile-create-first-app.html#run-your-application
  13. KOTLINCONF’23 SONGDO Source Sets ઺р ױ҅ Source Setsਸ ٜ݅ ࣻ

    ੓׮. Link: https://kotlinlang.org/docs/multiplatform-hierarchy.html#target-shortcuts
  14. 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 ١ਸ ࢎਊೡ ࣻ হ׮. • ١١…
  15. 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
  16. KOTLINCONF’23 SONGDO Get started Compose Multipla tf orm জਸ प೯೧ࠄ׮.

    • Github Template Repository۽ 
 Compose Multipla tf orm ೐۽ં౟ܳ 
 ࢤࢿೠ׮. Link: https://github.com/JetBrains/compose-multiplatform-template
  17. 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о ׳ۄࢲ ࢎਊࢿਸ Ҋ۰ೞݶ, ױੌ ௏٘݅ਵ۽ ҳഅೞח Ѫী ೠ҅о ੓׮. • ١١…
  18. KOTLINCONF’23 SONGDO Release • Maven ੷੢ࣗܳ ࢤࢿೠ׮. • ৘ܳ ٜয,

    Maven Central Repositoryۄݶ 1. ੉गܳ ࢤࢿೞҊ, 2. Project URL ӂೠਸ ੋૐೠ׮. • زੌೠ Group IDח 
 Repositoryܳ ೠߣ݅ ࢤࢿೞݶ ػ׮. Link: https://issues.sonatype.org/browse/OSSRH-80194
  19. 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=*********** 🔑
  20. 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
  21. 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 • ١١…
  22. 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
  23. 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:
  24. 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 * * ... */
  25. 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 ...
  26. 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"
  27. 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
  28. KOTLINCONF’23 SONGDO Github Actions • খࢲ ࣗѐೠ بҳٜਸ ۽ஸݠनীࢲ ࣻزਵ۽

    Ѩࢎೞ૑ ঋҊ, ੗زചೡ ࣻ ੓׮. Link: https://docs.github.com/ko/actions CI (Continuous Integration)
  29. 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
  30. 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
  31. KOTLINCONF’23 SONGDO Develop ҕా ௏٘۽ ੸੺൤ ߸҃೧ঠ ೠ׮. ইפݶ expect

    / actualਸ ҳഅ೧ঠ ೠ׮. Link: https://github.com/fornewid/material-motion-compose/pull/190/files#diff
  32. 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 ⚠ • ١١…
  33. 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)
  34. 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
  35. 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
  36. KOTLINCONF’23 SONGDO Users ۄ੉࠳۞ܻ ੄ઓࢿ ୶оೞӝ • ౠ੿ Source Setীࢲ݅

    ݣ౭೒ۖಬ ۄ੉࠳۞ܻܳ ࢎਊೡ ࣻب ੓׮. • ݣ౭೒ۖಬ ۄ੉࠳۞ܻо ইפۄݶ ഒزغ૑ ঋب۾, 
 ೒ۖಬ ݺடਸ ࢎਊೞ૑ ঋח Ѫਸ ӂ੢ೠ׮. 
 Link: https://kotlinlang.org/docs/multiplatform-add-dependencies.html#library-used-in-specific-source-sets