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

Androidエンジニア目線のKMM / iOSエンジニア目線のKMM

Androidエンジニア目線のKMM / iOSエンジニア目線のKMM

61df7fd4bc6f622ca13afb007789fc23?s=128

watanave

May 19, 2021
Tweet

Transcript

  1. "OESPJEΤϯδχΞ໨ઢͷ,.. J04ΤϯδχΞ໨ઢͷ,.. גࣜձࣾελσΟετºגࣜձࣾΏΊΈ߹ಉษڧձ :PIUB8BUBOBWF

  2. "CPVUNF :PIUB8BUBOBWF גࣜձࣾΏΊΈJ04"OESPJE5FDI-FBE 
 ๺ւಓࡏॅͰࣇͷ෕ 🕊XBUBOBWF !4VTBO@KBDLP 
 🐙XBUBOBWF XBUBOBWFY

  3. ,..ͱ͸

  4. ,..ͱ͸ w ,PUMJO.VMUJQMBUGPSNGPS.PCJMF w ,PUMJOͰॻ͍ͨιʔε͕ "OESPJEͱJ04Ͱಈ͘ʂ IUUQTLPUMJOMBOHPSHEPDTNVMUJQMBUGPSNIUNM

  5. 'MVUUFSͱͲ͏ҧ͏ʁ IUUQTLPUMJOMBOHPSHEPDTNPCJMFBSDIJUFDULNNBQQIUNMUIBOLTUPDPOUSJCVUPST

  6. "OESPJEΤϯδχΞ໨ઢͷ,.. J04ΤϯδχΞ໨ઢͷ,..

  7. "OESPJEΤϯδχΞࢹ఺ͷ,.. w ීஈͷ"OESPJEΞϓϦ։ൃͱͲ͏ҧ͏ʁ w J04΁ͷ഑ྀ͸ඞཁʁ

  8. ։ൃ؀ڥ͸ʁ w "OESPJE4UVEJP ,..ϓϥάΠϯ w WFSTJPOPSIJHIFS w όʔδϣϯޓ׵ੑʹ஫ҙ w "OESPJE4UVEJP

    w ,PUMJOϓϥάΠϯ w ,..ϓϥάΠϯ
  9. "OESPJE(SBEMFQMVHJO w Ҏ্͸ඇରԠ w ͔͠͠ɺϫʔΫΞϥ΢ϯυͰར༻Մೳ w IUUQTZPVUSBDLKFUCSBJOTDPNJTTVF,5 w %SPJE,BJHJΞϓϦ΋͜ͷϫʔΫΞϥ΢ϯυΛ࢖͍ͬͯΔ

  10. ύοͱݟ͸ϚϧνϞδϡʔϧϓϩδΣΫτ w ςϯϓϨʔτͰ৽نϓϩδΣΫτ࡞Δͱʜ w "OESPJEΞϓϦϞδϡʔϧ w ,..ڞ௨Ϟδϡʔϧ w JPT"QQ഑Լ͸9DPEFͷϓϩδΣΫτ w

    ϚϧνϦϙδτϦ΋Մ "OESPJEΞϓϦϞδϡʔϧ 9DPEFϓϩδΣΫτ ڞ௨Ϟδϡʔϧ
  11. ڞ௨Ϟδϡʔϧͷத਎ w DPNNPO.BJOʹڞ௨ίʔυ w ϓϥοτϑΥʔϜݻ༗ίʔυ͸ͦΕͧΕͷ σΟϨΫτϦ͸഑Լʹ w DPNNPO.BJOʹએݴͨ͠JOUFSGBDFΛ֤ϓ ϥοτϑΥʔϜͰ࣮૷ w

    FYQFDUBDUVBMͱ͍͏࢓૊Έ΋ "OESPJEݻ༗ίʔυ J04ݻ༗ίʔυ ڞ௨ίʔυ
  12. ϥΠϒϥϦબఆ͸৻ॏʹ w 🙅+BWB੡ϥΠϒϥϦ͸࢖͑ͳ͍ w %BHHFSˠ,PJO ,PEFJO w 3FUSP fi Uˠ,UPS

    w 3PPNˠ4RMEFMJHIU w IUUQTHJUIVCDPN""LJSB,PUMJO.VMUJQMBUGPSN-JCSBSJFT
  13. $PSPVUJOFTͷѻ͍ʹ஫ҙ͕ඞཁ w J04 ,PUMJO/BUJWF ͷ$PSPVUJOFT͸γϯάϧεϨου w ϚϧνεϨουόʔδϣϯ͸ผϒϥϯν dependencies { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3-native-mt")

    { version { strictly("1.4.3-native-mt" ) } } }
  14. $PSPVUJOFTͷѻ͍ʹ஫ҙ͕ඞཁ w J04 ,PUMJO/BUJWF ͸҆શͳฒྻॲཧͷͨΊʹGSP[FOͱ͍͏࢓૊Έ͕ w "OESPJEΤϯδχΞ͕ීஈ௨Γʹڞ௨ίʔυΛ࣮૷͢Δͱ 
 J04͚ͩΫϥογϡ💥ͷΑ͏ͳ͜ͱ͕ى͜ΓಘΔ MainScope().launch

    { var str = “string " withContext(Dispatchers.Main) { str = “main " } withContext(Dispatchers.Default) { str = "default " } )
  15. J04ΤϯδχΞࢹ఺ͷ,.. w ීஈͷJ04ΞϓϦ։ൃͱͲ͏ҧ͏ʁ w ԿΛ֮͑ͳ͚Ε͹ͳΒͳ͍ʁ w ,..ͷίʔυ͸Ͳ͏΍ͬͯݺͼग़͢ͷʁ w ݴ͍͍ͨ͜ͱ͕ଟ͗͢ΔͷͰۦ͚଍Ͱ

  16. ։ൃ؀ڥ͸ʁ w ͍ͭ΋௨Γͷ9DPEF w WFSTJPOPSIJHIFS w ,PUMJOίʔυ΋ॻ͘ͳΒ"OESPJE4UVEJP ,..ϓϥάΠϯ

  17. ,PUMJOͱ4XJGU͸ࣅͯΔʁ WBM⁶MFU GVOD⁶GVO 7PJE⁶6OJU QSPUPDPM⁶JOUFSGBDF TXJUDI⁶XIFO 
 FOVN⁶TFBMEDMBTTʁ ͋Δఔ౓ͷֶशίετ͸ඞཁ͔΋ fun

    test(str: String?) { str?.count() // ·͘͞͠OptionalνΣΠϯʂ str!!.count() // ڧ੍Unwra p if (str == null) retur n // ͜͜͸OptionalνΣΠϯ͍Βͳ͍ͷ⁉ str.count( ) } Ұݟɺҙຯෆ໌ͳεϚʔτΩϟετ
  18. (SBEMFͱ͍͏ϏϧυγεςϜ val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =

    if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true ) ::iosArm6 4 els e ::iosX6 4 iosTarget("ios") { binaries { framework { baseName = "shared " } } } ,..ͷϞδϡʔϧ⁶9DPEFͷλʔήοτʁʁʁ
  19. J04ΤϯδχΞ͕֮͑Δඞཁ͋Δ͔ʁ IUUQTLPUMJOMBOHPSHEPDTNPCJMFPSHBOJ[FQSPDFTTBSPVOELNNIUNMBQQSPBDIFTUPPSHBOJ[JOHUFBNXPSLGPSNVMUJQMBUGPSNQSPKFDUT

  20. ,PUMJOίʔυΛͲ͏΍࣮ͬͯߦ͢Δʁ w J04ͷ,PUMJO ,PUMJO/BUJWF ͸0CK$ޓ׵ w ,PUMJOίϯύΠϥ͸GSBNFXPSLΛੜ੒ͯ͘͠ΕΔ w ,PUMJOͰ"'/FUXPSLJOH͕࢖͑Δ w

    "3$ͱ౷߹͞ΕͯΔ
  21. ,PUMJOίʔυΛͲ͏΍࣮ͬͯߦ͢Δʁ IUUQTLPUMJOMBOHPSHEPDTOBUJWFPCKDJOUFSPQIUNMVTBHF *OUFSPQFSBCJMJUZXJUI4XJGU0CKFDUJWF$

  22. ,PUMJOίʔυΛͲ͏΍࣮ͬͯߦ͢Δʁ w GSBNFXPSLΛJNQPSU͢Δ IUUQTLPUMJOMBOHPSHEPDTNPCJMFJOUFHSBUFJOFYJTUJOHBQQIUNMDPOOFDUUIFGSBNFXPSLUPZPVSJPTQSPKFDU val packForXcode by tasks.creating(Sync::class) { group

    = "build " val mode = System.getenv("CONFIGURATION") ?: "DEBUG " val targetName = "ios " val framework = kotlin.targets.getByName<KotlinNative > inputs.property("mode", mode ) dependsOn(framework.linkTask ) val targetDir = File(buildDir, "xcode-frameworks" ) from({ framework.outputDirectory } ) into(targetDir ) }
  23. ,PUMJOίʔυΛͲ͏΍࣮ͬͯߦ͢Δʁ w GSBNFXPSLΛJNQPSU͢Δ IUUQTLPUMJOMBOHPSHEPDTNPCJMFJOUFHSBUFJOFYJTUJOHBQQIUNMDPOOFDUUIFGSBNFXPSLUPZPVSJPTQSPKFDU

  24. ݟ஌Β͵Τϥʔ 'VODUJPOEPFTOUIBWFPSJOIFSJU!5ISPXTBOOPUBUJPOBOEUIVTFYDFQUJPOJTOU QSPQBHBUFEGSPN,PUMJOUP0CKFDUJWF$4XJGUBT/4&SSPS *UJTDPOTJEFSFEVOFYQFDUFEBOEVOIBOEMFEJOTUFBE1SPHSBNXJMMCF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