Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Kotlin Nativeってandroid向けにもかけるんですよ
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
RyuNen344
July 20, 2022
Technology
700
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kotlin Nativeってandroid向けにもかけるんですよ
RyuNen344
July 20, 2022
More Decks by RyuNen344
See All by RyuNen344
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
0
110
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
410
せめて、ネイティブらしく
ryunen344
2
3.3k
Cache Me If You Can
ryunen344
3
9.4k
WindowInsetsだってテストしたい
ryunen344
2
440
サプライチェーン攻撃に備える
ryunen344
1
4.1k
Okioに愛を込めて
ryunen344
3
3.1k
Firebase Hostingを使ってPasskeyをandroidアプリで試してみよう
ryunen344
2
2.2k
Xcode Meets Gradle
ryunen344
0
460
Other Decks in Technology
See All in Technology
ドメインエキスパートは いかにして AI を使って プロダクト開発をするか
tatsuyashiraishi
1
250
今から始めるAWS環境の暗号移行 - ポスト量子時代に備える
sato4mi
0
150
なぜAI時代に技術記事を書くのか?どう書くのか? 〜bunの場合〜
kworkdev
PRO
0
3.4k
Deep Data Security 機能解説
oracle4engineer
PRO
3
990
re:Invent の去年のスケジュールを公開します!
miu_crescent
PRO
0
150
AI時代の開発はウォーターフォールに回帰する? / development-with-ai-back-to-wf
okamototakuyasr2
0
170
推論基盤と Scale-Up Interconnect の現状と制約から俯瞰する技術動向
markunet
2
730
(swiftc) NonCopyableとライフタイム修飾子
teamhimeh
0
160
[General] 개발자로 해외 기업에서 일하기
skydoves
1
250
AIがGISを代替する日:〜すべてをAIが創る時代に、私たちがFOSS4Gに関わる意味〜
lehupa
0
190
cdk deployとcdkd deploy、実際にデプロイして5倍速近くの差を実測した
yama3133
1
160
【Oracle AI SPOTLIGHT ウェビナー】事例から見る!なぜOCIが選ばれたのか ― AI時代のクラウド戦略を紐解く ―
oracle4engineer
PRO
1
150
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
100
6.3k
The untapped power of vector embeddings
frankvandijk
2
2k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
750
Designing Experiences People Love
moore
143
24k
Building AI with AI
inesmontani
PRO
1
1.3k
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Into the Great Unknown - MozCon
thekraken
41
2.8k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
How to Ace a Technical Interview
jacobian
280
24k
Visualization
eitanlees
153
17k
Transcript
Kotlin Nativeͬͯandroid͚ ʹॻ͚ΔΜͰ͢Α 2022.07.20 Qiita Night 2022ɺAndroidΞϓϦͲ͏࡞Δʁ Bunjiro Miyoshi
About Me • νʔϜϥϘॴଐ • (ࣗশ)ϚϧνϓϥοτϑΥʔϜܳਓ • ৽ଔͰAndroidΤϯδχΞͱͯ͠σϏϡʔɺAsyncTask͕ຮԆΔݹͷ ίʔυʹ͓ݟ͍͞ΕΔɻ࣮ͦΜͳʹRxॻ͚ͳ͍(Coroutine͔ Γ)ɻ
ΤϯδχΞɺ ࠷ऴతʹC͔C++ʹͨͲΓண͘આ
Android NDKͬͯ·͔͢ʁ C++͍ͩͬͯ͠ͷʹJNIʹͳΔͱߟ͑Δ͜ͱ૿͑Δɾɾɾɾ
࠷ۙϚϧνϓϥοτϑΥʔϜདྷͯ·͢ ΑͶ
Kotlin Native࣮ͬͯandroid NDK ͚ʹు͖ग़ͤΔ
Kotlin Multiplatformͱ
Kotlin Multiplatformͱ 👈ࠓճίίʹযΛͯ·͢
Kotlin Nativeͱ • αϙʔτ͍ͯ͠ΔPlatform • macOS, tvOS, watchOS • Linux
• Windows(MinGW) • Android NDK Ref: https://kotlinlang.org/docs/native-overview.html
Kotlin Nativeͱ • Static or DynamicϥΠϒϥϦΛੜͰ͖Δ • Static or Dynamic
CϥΠϒϥϦΛऔΓࠐΊΔ • (Swift, Objective-CͷϑϨʔϜϫʔΫऔΓࠐΊΔ)
Kotlin Native࣮ߦ࣌Πϝʔδ ɿ࣮ࡍʹΠϯετʔϧ࣌ͷAOTͱ͔བྷΉ
Kotlin Native࣮ߦ࣌Πϝʔδ ɿ࣮ࡍʹΠϯετʔϧ࣌ͷAOTͱ͔བྷΉ
ɿ࣮ࡍʹΠϯετʔϧ࣌ͷAOTͱ͔བྷΉ Kotlin Native࣮ߦ࣌Πϝʔδ
Kotlin Native࣮ߦ࣌Πϝʔδ ɿ࣮ࡍʹΠϯετʔϧ࣌ͷAOTͱ͔བྷΉ
Kotlin Native for Android Native • ݱঢ়API21͔Βαϙʔτ͞Ε͍ͯΔωΠςΟϒAPIʹରԠ͞Ε͍ͯΔ(ͬΆ͍) • ҎԼKotlin NativeΛ༻͍ͯKotlinͰ৮ΕΔ
• jniपΓͷ͋Ε͜Ε༻ͷinterface • android native app API(Native ActivityͳͲ) • EGL(GLES1~3.1ؚΉ) • media • OpenMAX AL • posix(linuxίϚϯυྨ) • zlib Android NDKެࣜͷωΠςΟϒAPIҰཡ https://developer.android.com/ndk/guides/stable_apis?hl=ja
Kotlin NativeΛNDK͚ʹॻ͖ग़͢
ઃఆɿSourceSets
ઃఆɿSourceSets androidNative༻ʹ༻ҙ͞Ε͍ͯΔϓϦ ηοτ༻ͷؔΛͬͯఆٛ
ઃఆɿSourceSets ు͖ग़͞ΕΔϥΠϒϥϦ͕੩తͳͷ͔ಈ తͳͷ͔Λఆٛ(ࠨಈత)
ઃఆɿbuild Ϗϧυ࣌ʹandroidϓϩδΣΫτʹ.soϑΝ ΠϧΛίϐʔ͢ΔॲཧΛKotlin Nativeଆͷ ϓϩδΣΫτʹՃ͢Δ K/NϓϩδΣΫτandroidϥΠϒϥϦͱ ͯ͠ೝࣝͰ͖ͳ͍ͨΊखͰϑΝΠϧΛί ϐʔͯ͋͛͠Δඞཁ͕͋Δ
Kotlin NativeΛݺͼग़͢
ܕͷޓੑ(Primitive) KBWB KOJ $ $ PO,/ LPUMJOPO,/ CPPMFBO KCPPMFBO VJOU@U
\MJCSBZ^@,#PPMFBO #PPMFBO CZUF KCZUF JOU@U \MJCSBZ^@,#ZUF #ZUF DIBS KDIBS VJOU@U \MJCSBZ^@,$IBS $IBS TIPSU KTIPSU JOU@U \MJCSBZ^@,4IPSU 4IPSU JOU KJOU JOU@U \MJCSBZ^@,*OU *OU MPOH KMPOH JOU@U \MJCSBZ^@,-POH -POH fl PBU K fl PBU fl PBU \MJCSBZ^@,'MPBU 'MPBU EPVCMF KEPVCMF EPVCMF \MJCSBZ^@,%PVCMF %PVCMF WPJE WPJE \MJCSBZ^@,/BUJWF1US
JNI on K/NΛ͏·͘ΔTips Primitiveฤ • Primitiveͳܕͦͷ··K/N্ͰKotlinΫϥεͰड͚औΕΔ • instanceΛੜ͢ΔࡍallocΛࣗಈͰͬͯ͘ΕΔmemScopedؔ Λ༻͍ͯϝϞϦ൪͕ScopeͰෆมʹͳΔΑ͏ʹ͢Δ RefrectionฤɺStructฤͲ͔͜ͰͤͨΒɾɾɾɾ
JNI on K/NΛ͏·͘ΔTips Primitiveฤ
JNI on K/NΛ͏·͘ΔTips Primitiveฤ instanceੜ͢Δͱallocͯ͘͠ΕΔ
JNI on K/NΛ͏·͘ΔTips Primitiveฤ ͳʹ͔ॲཧ͢Δ
JNI on K/NΛ͏·͘ΔTips Primitiveฤ ࠷ޙʹϝϞϦղ์ͯ͘͠ΕΔ Ұ൪͏ྫͱͯ͠memScopedΛऔΓ্͕͛ͨଞʹ৭ʑศརؔ ͕kotlinx.cinteropʹఆٛ͞Ε͍ͯΔ
ు͖ग़ͨ͠.so ϑΝΠϧΛNDKʹಡΈࠐ·ͤΔ • Kotlin Nativeʹύοέʔδͷ֓೦͕ଘࡏ͍ͯ͠Δ • τοϓϨϕϧؔͳͲͷ໊લۭ͕ؒͿ͔ͭΒͳ͍ͷ͜Εͷ͓͔ ͛ • ex.)cଆ͔ΒΈΔͱprintؔKotlin_io_Console_printʹͳͬͯͨ
Γ͢Δ • ݺͼग़͠ํ͕ಠಛ()ʹͳΔ
ు͖ग़ͨ͠.so ϑΝΠϧΛNDKʹಡΈࠐ·ͤΔ ·ͣK/Nͷexported symbolsΛऔΓग़͢
ు͖ग़ͨ͠.so ϑΝΠϧΛNDKʹಡΈࠐ·ͤΔ తͷTop LevelؔɺΫϥεΛݺͼग़͢ K/N RuntimeΛੜͯ͠ɺ͓ͯͷΫϥεؔΛݺͼग़͢Πϝʔδ
ύϑΥʔϚϯεͲ͏ͳͷΑ
ܭଌɿલఏ • Kotlin Nativeͷnew mmෆ༻ • Kotlin NativeͰ.soΛు͖ग़ͯͦ͠ΕΛndkʹऔΓࠐΜͰॲཧΛݺͼग़͢ • ࠓճΈΜͳେ͖ϑΟϘφονؔͰܭଌ(Ұ൪Orderͷଟ͍࠶ؼ
ύλʔϯ) • CoroutineͳͲΛ༻͍ͯॲཧதͷ࣮ߦεϨουͷมߋͳͲߦΘͳ͍ • tailrecΛͬͨݴޠϨϕϧͷ࠷దԽߦΘͳ͍
ܭଌɿ݁Ռ ߲a࣮NT LPUMJO $ ,/
ܭଌɿ·ͱΊ • ࠓճͷܭଌͰૉͷωΠςΟϒ࣮Λ্ճΕΔ݁Ռ͕ग़ͨ • ͜ͷ෦ڪΒ͘NDKͷࣝෆͰ࠷దԽෆͳ෦͕͋Δͣ • K/Ndebug symbol͕ॏΊͳͷͰ͔ͬ͠ΓReleaseϏϧυΛͬͨ ΄͏͕Α͍
·ͱΊᶃ • ૉఢͳͱ͜Ζ • IDEࢧԉΛ͞Βʹड͚͍͢(CLion࣋ͬͯͳ͍ਓͰϦονͳࢧԉ͕Β͑Δ) • ڧྗͳstdlibपΓΛઃఆͳ͠Ͱ͑Δ • ίΞϩδοΫʹؔͯ͠׳ΕͯΔKotlinΛͬͯهड़͢Δ͜ͱ͕Ͱ͖Δ •
͋ͱҰาͷͱ͜Ζ • KotlinͬͯΔͷʹPointerΛҙ࣮͕ࣝͨ͠ՕॴՕॴͰൃੜ͢Δ • coroutine, atomicfu͕ରԠ͞Εͯͳ͍ରԠ͞ΕΔݟࠐΈͳ͍(͕ճආࡦࣗମ͋Δ) • ύϑΥʔϚϯεͦΜͳʹΑ͘ͳ͍ ૉͷ࣮ΑΓૣͯ͘ϏοΫϦ
·ͱΊᶄ • ωΠςΟϒϥΠϒϥϦ͔͠ͳ͍͚ͲͲ͏ͯ͠C++ͷΩϟονΞο ϓ͢Δ༨༟͕ͳ͍ɺͱ͍͏߹ʹͲ͏Ͱ͠ΐ͏͔
ߏମޓฤ, CInteropฤʹଓ͘ to be continued….