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

Kotlin Nativeでクロスプラットフォーム開発 / Cross-platform de...

satsukies
November 17, 2018

Kotlin Nativeでクロスプラットフォーム開発 / Cross-platform development with Kotlin Native

satsukies

November 17, 2018
Tweet

More Decks by satsukies

Other Decks in Technology

Transcript

  1. Kotlin/NativeͰ ΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ

    τ / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ
  2. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Who is? ౎ཱ࢈ۀٕज़ߴઐ(ຊՊ/ઐ߈Պ) ిؾ௨৴େֶେֶӃ CAʹ2017೥৽ଔͰೖࣾ AbemaTV ։ൃہ/AndroidνʔϜ ஛ా ஐʢ͚ͨͩ ͞ͱ͠ʣ satsukies satsukies Takeda Satoshi
  3. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ ΨδΣοτ ΫϧϚ εϙʔπ My hobby
  4. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Try Kotlin/Native What’s Kotlin Agenda Conclusion
  5. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Try Kotlin/Native What’s Kotlin Agenda Conclusion 5
  6. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ What’s • JetBrains͕։ൃͨ͠੩తܕ෇͚ݴޠ • JavaΛΑΓ؆ܿɾ҆શʹ • Null҆શ / ֦ுؔ਺ / Ϋϩʔδϟ / etc.. • OSඇґଘɺJVM্Ͱಈ࡞ • Javaͱͷ૬ޓӡ༻ੑ͕֬อ͞Ε͍ͯΔ • Javaͷࢿ࢈͕׆͔ͤΔ
  7. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Kotlin 1.3 Kotlin/Native Beta release Google I/O 2017 Android Official Support Kotlin 1.0 Feb 2016 May 2017 Oct 2018 History
  8. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Kotlin/Native • Kotlin͔Βλʔήοτ؀ڥͰಈ࡞͢ΔωΠςΟϒ
 όΠφϦΛੜ੒͢ΔίϯύΠϥ • ಺෦Ͱ͸LLVMΛܦ༝͍ͯ͠Δ • αϙʔτͯ͠ΔϓϥοτϑΥʔϜ͸ҎԼͷ௨Γ • iOS, Android, Windows, MacOS, Linux, WebAssembly
  9. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Μʁ
  10. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Kotlin/Native • Kotlin͔Βλʔήοτ؀ڥͰಈ࡞͢ΔωΠςΟϒ
 όΠφϦΛੜ੒͢ΔίϯύΠϥ • ಺෦Ͱ͸LLVMΛܦ༝͍ͯ͠Δ • αϙʔτͯ͠ΔϓϥοτϑΥʔϜ͸ҎԼͷ௨Γ • iOS, Android, Windows, MacOS, Linux, WebAssembly
  11. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Kotlin/Native • Kotlin͔Βλʔήοτ؀ڥͰಈ࡞͢ΔωΠςΟϒ
 όΠφϦΛੜ੒͢ΔίϯύΠϥ • ಺෦Ͱ͸LLVMΛܦ༝͍ͯ͠Δ • αϙʔτͯ͠ΔϓϥοτϑΥʔϜ͸ҎԼͷ௨Γ • iOS, Android, Windows, MacOS, Linux, WebAssembly
  12. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ KotlinͰiOSΞϓϦ͕ ࡞ΕΔʂ
  13. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ ૣ଎ೖ໳ͯ͠ΈΔ
  14. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Try Kotlin/Native What’s Kotlin Agenda Conclusion
  15. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Task Overview • ϕʔεϓϩδΣΫτͷ࡞੒ / ઃఆ • ڞ༗͢Δίʔυͷ࣮૷ • AndroidΞϓϦͷઃఆ / ࣮૷ • iOSΞϓϦͷઃఆ / ࣮૷
  16. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Preparing • MacOS͕ಈ࡞͢ΔPC • Android Studioʢ3.4 Preview Canary 3ʣ • ϕʔεͱͳΔProjectΛੜ੒ͨ͠Γ͠·͢ • Xcodeʢ10.1 10B61ʣ • iOSΞϓϦͷͨΊͷઃఆ΍࣮૷ʹ࢖͍·͢ • Τϥʔʹෛ͚ͳ͍΍Δؾ΍޷ح৺
  17. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Generating base project Android StudioΛ࢖ͬͯϕʔεϓϩδΣΫτΛ࡞੒ ීஈͷΞϓϦ৽ن࡞੒ͱಉ͡
  18. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Generating base project Android StudioΛ࢖ͬͯϕʔεϓϩδΣΫτΛ࡞੒ ීஈͷΞϓϦ৽ن࡞੒ͱಉ͡
  19. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Creating common module ڞ௨ͷίʔυΛ࣮૷͢Δ৔ॴΛ࡞੒ File > New > New Module
  20. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Creating common module ڞ௨ͷίʔυΛ࣮૷͢Δ৔ॴΛ࡞੒ Java LibraryΛબ୒
  21. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Creating common module ڞ௨ͷίʔυΛ࣮૷͢Δ৔ॴΛ࡞੒ Java LibraryΛબ୒ > Α͠ͳʹ໊લΛ͚ͭΔ Class໊͸ద౰ͰOK
  22. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Creating common module moduleͱඞཁͳϑΝΠϧ͕௥Ճ͞Ε settings.gradleʹԿ΍Β௥ه͞Ε͍ͯΔ ɹɹɹɹɹɹɹɹ ௥Ճͨ͠moduleΛgradleʹೝࣝͤ͞ΔͨΊʹඞཁ include ':app', ':ShareCode'
  23. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement common codes srcʹڞ௨ίʔυ༻ͷσΟϨΫτϦΛ࡞੒ commonMain/kotlin/{ύοέʔδ໊}/common
  24. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement common codes ੜ੒ͨ͠σΟϨΫτϦʹ ڞ௨ίʔυΛهड़͢ΔΫϥεΛ௥Ճ࣮͠૷ package net.ddns.satsukies.diveintokotlinnative.common expect fun platformName(): String fun createApplicationScreenMessage(): String { return "Kotlin Rocks on ${platformName()}" }
  25. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement common codes (android) ઌͱಉ͡खॱͰandroid޲͚ͷσΟϨΫτϦΛ௥Ճ androidMain/kotlin/{ύοέʔδ໊}/common
  26. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement common codes (android) ੜ੒ͨ͠σΟϨΫτϦʹΫϥεΛ࡞੒͠ Android޲͚ͷίʔυΛ࣮૷ package net.ddns.satsukies.diveintokotlinnative.common actual fun platformName(): String = "android"
  27. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement common codes (iOS) ઌͱಉ͡खॱͰiOS޲͚ͷσΟϨΫτϦΛ௥Ճ iosMain/kotlin/{ύοέʔδ໊}/common
  28. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement common codes (iOS) ੜ੒ͨ͠σΟϨΫτϦʹΫϥεΛ࡞੒͠ iOS޲͚ͷίʔυΛ࣮૷ package net.ddns.satsukies.diveintokotlinnative.common actual fun platformName(): String { return UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion }
  29. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Fix build.gradle CommonϞδϡʔϧ಺ʹ͋Δbuild.gradleΛमਖ਼͠ ෳ਺ͷϓϥοτϑΥʔϜʹରԠͤ͞Δ
  30. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Fix build.gradle CommonϞδϡʔϧ಺ʹ͋Δbuild.gradleΛमਖ਼͠ ෳ਺ͷϓϥοτϑΥʔϜʹରԠͤ͞Δ apply plugin: ‘kotlin-multiplatform' kotlin { targets { final def iOSTarget = System.getenv('SDK_NAME') ?.startsWith("iphoneos")\ ? presets.iosArm64 : presets.iosX64 fromPreset(iOSTarget, 'iOS') { compilations.main.outputKinds('FRAMEWORK') } fromPreset(presets.jvm, 'android') } sourceSets { commonMain.dependencies { api 'org.jetbrains.kotlin:kotlin-stdlib-common' } androidMain.dependencies { api 'org.jetbrains.kotlin:kotlin-stdlib' } } } // workaround for https: //youtrack.jetbrains.com/issue/KT-27170 configurations { compileClasspath }
  31. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Fix build.gradle CommonϞδϡʔϧ಺ʹ͋Δbuild.gradleΛमਖ਼͠ ෳ਺ͷϓϥοτϑΥʔϜʹରԠͤ͞Δ apply plugin: ‘kotlin-multiplatform' kotlin { targets { final def iOSTarget = System.getenv('SDK_NAME') ?.startsWith("iphoneos")\ ? presets.iosArm64 : presets.iosX64 fromPreset(iOSTarget, 'iOS') { compilations.main.outputKinds('FRAMEWORK') } fromPreset(presets.jvm, 'android') } sourceSets { commonMain.dependencies { api 'org.jetbrains.kotlin:kotlin-stdlib-common' } androidMain.dependencies { api 'org.jetbrains.kotlin:kotlin-stdlib' } } } // workaround for https: //youtrack.jetbrains.com/issue/KT-27170 configurations { compileClasspath } iOSλʔήοτͷઃఆ
  32. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Fix build.gradle CommonϞδϡʔϧ಺ʹ͋Δbuild.gradleΛमਖ਼͠ ෳ਺ͷϓϥοτϑΥʔϜʹରԠͤ͞Δ apply plugin: ‘kotlin-multiplatform' kotlin { targets { final def iOSTarget = System.getenv('SDK_NAME') ?.startsWith("iphoneos")\ ? presets.iosArm64 : presets.iosX64 fromPreset(iOSTarget, 'iOS') { compilations.main.outputKinds('FRAMEWORK') } fromPreset(presets.jvm, 'android') } sourceSets { commonMain.dependencies { api 'org.jetbrains.kotlin:kotlin-stdlib-common' } androidMain.dependencies { api 'org.jetbrains.kotlin:kotlin-stdlib' } } } // workaround for https: //youtrack.jetbrains.com/issue/KT-27170 configurations { compileClasspath } Androidλʔήοτͷઃఆ
  33. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Fix build.gradle CommonϞδϡʔϧ಺ʹ͋Δbuild.gradleΛमਖ਼͠ ෳ਺ͷϓϥοτϑΥʔϜʹରԠͤ͞Δ apply plugin: ‘kotlin-multiplatform' kotlin { targets { final def iOSTarget = System.getenv('SDK_NAME') ?.startsWith("iphoneos")\ ? presets.iosArm64 : presets.iosX64 fromPreset(iOSTarget, 'iOS') { compilations.main.outputKinds('FRAMEWORK') } fromPreset(presets.jvm, 'android') } sourceSets { commonMain.dependencies { api 'org.jetbrains.kotlin:kotlin-stdlib-common' } androidMain.dependencies { api 'org.jetbrains.kotlin:kotlin-stdlib' } } } // workaround for https: //youtrack.jetbrains.com/issue/KT-27170 configurations { compileClasspath } ϥΠϒϥϦͷಡΈࠐΈઃఆ
  34. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ What’s happen? commonϞδϡʔϧʹ͸ڞ௨ར༻͢ΔίʔυΛ࣮૷ Common fun platformName(): String
  35. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ What’s happen? Common fun platformName(): String Android iOS 12.1 λʔήοτຖʹ݁ՌΛม͍͑ͨͱ͖͸Ͳ͏͠Α͏
  36. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ expected, actual ͪΐ͏ͲabstractͱoverrideΈ͍ͨͳؔ܎[1] • ڞ௨ίʔυͰ͸ϝιουʹexpectedΛ෇༩ • ֤λʔήοτσΟϨΫτϦͷίʔυͰactualΛ࣮૷ [1]https://aakira.app/blog/2018/10/kotlin-native/
  37. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ expected, actual [1]https://aakira.app/blog/2018/10/kotlin-native/ expect fun platformName(): String actual fun platformName(): String { return UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion } actual fun platformName(): String = "android" Android iOS Common
  38. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement Android App AndroidΞϓϦͷίʔυ͔Βڞ௨࣮૷Λ࢖ͬͯΈΔ ※AndroidΞϓϦͷ࣮૷͸appϞδϡʔϧ಺Ͱ͢
  39. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement Android App app/build.gradleʹڞ௨Ϟδϡʔϧͷݺग़Λ௥ه dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) // ڞ௨Ϟδϡʔϧ implementation project(':ShareCode') … }
  40. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement Android App <TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> activity_main.xmlΛमਖ਼ TextViewʹίʔυ͔ΒΞΫηεͰ͖ΔΑ͏ʹ͢Δ
  41. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement Android App activity_main.xmlΛमਖ਼ TextViewʹίʔυ͔ΒΞΫηεͰ͖ΔΑ͏ʹ͢Δ <TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> IDΛׂΓ౰͍ͯͯ͋͛ͯΔ
  42. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement Android App MainActivity.ktͰදࣔจࣈྻͱจࣈαΠζΛηοτ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val textView = findViewById<TextView>(R.id.text_view) textView.text = createApplicationScreenMessage() textView.textSize = 24f }
  43. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement Android App override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val textView = findViewById<TextView>(R.id.text_view) textView.text = createApplicationScreenMessage() textView.textSize = 24f } viewΛ͖ͬ͞ͷID͔Βݟ͚ͭग़͍ͯ͠Δ MainActivity.ktͰදࣔจࣈྻͱจࣈαΠζΛηοτ
  44. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ MainActivity.ktͰදࣔจࣈྻͱจࣈαΠζΛηοτ Implement Android App override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val textView = findViewById<TextView>(R.id.text_view) textView.text = createApplicationScreenMessage() textView.textSize = 24f } จࣈྻͱจࣈαΠζΛηοτ
  45. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Run Android App ࣮ߦͯ͠ΈΔͱ ʮKotlin Rocks on Androidʯ ͱදࣔ͞Ε·͢ʂ
  46. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement iOS App XcodeΛ࢖ͬͯiOSΞϓϦΛ࡞੒͍͖ͯ͠·͢
  47. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Generating Xcode project Xcodeͷॳظը໘͔Β Create a new Xcode project
  48. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Generating Xcode project Single View AppΛબ୒
  49. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Generating Xcode project ໊લΛܾΊɺอଘઌ͸rootϑΥϧμ௚ԼΛࢦఆ
  50. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Fix build.gradle iOS޲͚ͷϑΝΠϧ͕ੜ੒͞ΕΔΑ͏ʹमਖ਼͢Δ
  51. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Fix build.gradle CommonϞδϡʔϧ಺ʹ͋Δbuild.gradleΛमਖ਼͠ ෳ਺ͷϓϥοτϑΥʔϜʹରԠͤ͞Δ apply plugin: 'kotlin-multiplatform' kotlin { … } // workaround for https: //youtrack.jetbrains.com/issue/KT-27170 configurations { compileClasspath } task packForXCode(type: Sync) { final File frameworkDir = new File(buildDir, "xcode-frameworks") final String mode = project.findProperty("XCODE_CONFIGURATION") ?.toUpperCase() ?: 'DEBUG' inputs.property "mode", mode dependsOn kotlin.targets.iOS.compilations.main.linkTaskName("FRAMEWORK", mode) from { kotlin.targets.iOS.compilations.main.getBinary("FRAMEWORK", mode).parentFile } into frameworkDir doLast { new File(frameworkDir, 'gradlew').with { text = " #!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '$ {rootProject.rootDir}'\n./gradlew \$@\n" setExecutable(true) } } } tasks.build.dependsOn packForXCode
  52. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Fix build.gradle CommonϞδϡʔϧ಺ʹ͋Δbuild.gradleΛमਖ਼͠ ෳ਺ͷϓϥοτϑΥʔϜʹରԠͤ͞Δ apply plugin: 'kotlin-multiplatform' kotlin { … } // workaround for https: //youtrack.jetbrains.com/issue/KT-27170 configurations { compileClasspath } task packForXCode(type: Sync) { final File frameworkDir = new File(buildDir, "xcode-frameworks") final String mode = project.findProperty("XCODE_CONFIGURATION") ?.toUpperCase() ?: 'DEBUG' inputs.property "mode", mode dependsOn kotlin.targets.iOS.compilations.main.linkTaskName("FRAMEWORK", mode) from { kotlin.targets.iOS.compilations.main.getBinary("FRAMEWORK", mode).parentFile } into frameworkDir doLast { new File(frameworkDir, 'gradlew').with { text = " #!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '$ {rootProject.rootDir}'\n./gradlew \$@\n" setExecutable(true) } } } tasks.build.dependsOn packForXCode iOSͰඞཁͳϑΝΠϧͷੜ੒λεΫ
  53. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Build from terminal iOS༻ͷϑΝΠϧΛੜ੒ͤ͞ΔͨΊʹbuild 1. terminalͳͲͰϓϩδΣΫτϧʔτ΁Ҡಈ 2. ./gradlew build Λ࣮ߦ 3. ੒ޭ͢Δͱxcode-frameworks͕ੜ੒͞ΕΔ
  54. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Project setting .frameworkϑΝΠϧΛಡΈࠐΉઃఆΛߦ͏ General > Embedded Binaries
  55. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Project setting .frameworkϑΝΠϧΛಡΈࠐΉઃఆΛߦ͏ + > Add Other… > .frameworks΁ͷύεΛࢦఆ
  56. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Project setting XcodeͷBitcodeػೳΛOFFʹ͢Δ Kotlin/Native͸ωΠςΟϒίʔυΛੜ੒ͯ͠Δ͔Β
  57. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Project setting FrameworkݕࡧύεΛ௥Ճ͢Δ BuildSettings > Framework Search Path > +
  58. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Project setting XcodeͰͷbuild࣌ʹgradle buildΛ࣮ߦ͢Δઃఆ Build Phase > + > New Run Script Phase
  59. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Project setting XcodeͰͷbuild࣌ʹgradle buildΛ࣮ߦ͢Δઃఆ cd {.frameworksͷpath} , gradlewϏϧυίϚϯυ
  60. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Project setting XcodeͰͷbuild࣌ʹgradle buildΛ࣮ߦ͢Δઃఆ Run ScriptΛCompile SourcesΑΓલʹฒͼସ͑
  61. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement 
 iOS App Androidͱಉ༷ʹɺจࣈྻΛදࣔͤͯ͞Έ·͢
  62. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement 
 iOS App Androidͱಉ༷ʹɺจࣈྻΛදࣔͤͯ͞Έ·͢ ViewController.swift΁ίʔυΛ࣮૷
  63. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement 
 iOS App Androidͱಉ༷ʹɺจࣈྻΛදࣔͤͯ͞Έ·͢ import UIKit import ShareCode class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let label = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 21)) label.center = CGPoint(x: 160, y: 285) label.textAlignment = .center label.font = label.font.withSize(24) // ڞ௨Ϟδϡʔϧʹ࣮૷ͨ͠function͕ݺͼग़͍ͤͯΔ label.text = CommonKt.createApplicationScreenMessage() view.addSubview(label) } }
  64. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement 
 iOS App Androidͱಉ༷ʹɺจࣈྻΛදࣔͤͯ͞Έ·͢ import UIKit import ShareCode class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let label = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 21)) label.center = CGPoint(x: 160, y: 285) label.textAlignment = .center label.font = label.font.withSize(24) // ڞ௨Ϟδϡʔϧʹ࣮૷ͨ͠function͕ݺͼग़͍ͤͯΔ label.text = CommonKt.createApplicationScreenMessage() view.addSubview(label) } } ࠷ॳʹ࡞੒ͨ͠ڞ௨ϞδϡʔϧΛimport
  65. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Implement 
 iOS App Androidͱಉ༷ʹɺจࣈྻΛදࣔͤͯ͞Έ·͢ import UIKit import ShareCode class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let label = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 21)) label.center = CGPoint(x: 160, y: 285) label.textAlignment = .center label.font = label.font.withSize(24) // ڞ௨Ϟδϡʔϧʹ࣮૷ͨ͠function͕ݺͼग़͍ͤͯΔ label.text = CommonKt.createApplicationScreenMessage() view.addSubview(label) } } ڞ௨Ϟδϡʔϧͷ࣮૷Λݺͼग़͠
  66. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Run iOS App ࣮ߦͯ͠ΈΔͱ ʮKotlin Rocks on iOS 12.1ʯ ͱදࣔ͞Ε·͢ʂ
  67. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Compare App iOS Android
  68. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Try Kotlin/Native What’s Kotlin Agenda Conclusion
  69. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Conclusion • Kotlin/Native͸λʔήοτຖͷωΠςΟϒόΠφ ϦΛు͖ग़͢ίϯύΠϥ • αϙʔτ͍ͯ͠Δλʔήοτ͸෯޿͍ • ڞ௨෦෼ΛKotlinͰॻ͚Δͱ͍͏രΞυ㽉 • ·ͩϕʔλͳͷͰࠓޙͷൃలʹظ଴
  70. Kotlin/NativeͰΫϩεϓϥοτϑΥʔϜ։ൃ α Πό ʔ Τ ʔ δ Σ ϯ τ

    / ະ དྷ େ L T େ ձ @ വ ؗ ະ དྷ େ Slide, Sample Codes satsukies/DiveIntoKotlinNative TwitterϑΥϩʔͯ͠Ͷ Slideshare GitHub