$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
System.loadLibrary("Unix, Native Code and why b...
Search
Júlio Zynger
March 16, 2018
Programming
0
870
System.loadLibrary("Unix, Native Code and why bother")
Presented at AppDevCon (Amsterdam) 2018
Júlio Zynger
March 16, 2018
Tweet
Share
More Decks by Júlio Zynger
See All by Júlio Zynger
Improving developer productivity with Gradle Enterprise in 2023
julioz
1
450
FloorPlan: Visualize databases' evolution
julioz
0
750
Publishing API & Continuous Deployment on Android
julioz
1
720
Continuous Deploy no Android
julioz
0
3.7k
Other Decks in Programming
See All in Programming
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
210
Canon EOS R50 V と R5 Mark II 購入でみえてきた最近のデジイチ VR180 事情、そして VR180 静止画に活路を見出すまで
karad
0
130
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
290
Navigating Dependency Injection with Metro
l2hyunwoo
1
170
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
120
Denoのセキュリティに関する仕組みの紹介 (toranoana.deno #23)
uki00a
0
150
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
3
1.1k
開発に寄りそう自動テストの実現
goyoki
2
1.4k
AIエージェントを活かすPM術 AI駆動開発の現場から
gyuta
0
470
リリース時」テストから「デイリー実行」へ!開発マネージャが取り組んだ、レガシー自動テストのモダン化戦略
goataka
0
140
GISエンジニアから見たLINKSデータ
nokonoko1203
0
180
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
280
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
70k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.3k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
HDC tutorial
michielstock
0
260
ラッコキーワード サービス紹介資料
rakko
0
1.8M
AI: The stuff that nobody shows you
jnunemaker
PRO
1
12
Optimising Largest Contentful Paint
csswizardry
37
3.5k
Designing for Performance
lara
610
69k
KATA
mclloyd
PRO
33
15k
エンジニアに許された特別な時間の終わり
watany
105
220k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
37
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
130
Transcript
System.loadLibrary( “Unix, Native Code and why bother”)
Library static shared static dynamic loading (.o, .a, ...) (.so,
.dll, .dylib, ...)
Program A Program B static libs (.a) static libs (.a)
static linking compile-time
Program A Program B Program A Program B static libs
(.a) static libs (.a) shared libs (.so) static linking dynamic linking compile-time run-time
Library static shared bookstore library Paul Richter
source code compiler
source code compiler objects (.o) .o .o .o .a archive
.o
source code compiler linker objects (.o) .o .o .o .a
archive .o executable .so .so .so .so
source code compiler linker loader objects (.o) .o .o .o
.a archive .o executable in-memory image .so .so .so .so
Building the objects
lib1.c
main.c
Static Libraries
Static Libraries
Shared Libraries: Static Loading
Shared Libraries: Static Loading LD_LIBRARY_PATH
Shared Libraries: Dynamic Loading
main.c
main.c
Android
Kernel Display driver USB driver Camera driver WiFi driver Power
Mgmt. Binder IPC ... Application Framework Apps Home Contacts Dialer Clock Your app 3rd party app ... Activity Manager Window Manager Package Manager Location Manager View System Content Providers ... Libraries Android Runtime (Dalvik/ART) Core Libraries Dalvik Virtual Machine (DVM) Surface Manager OpenGL Media Framework SQLite WebKit SSL ... Bionic
Kernel Display driver USB driver Camera driver WiFi driver Power
Mgmt. Binder IPC ...
Kernel Display driver USB driver Camera driver WiFi driver Power
Mgmt. Binder IPC ... Libraries Surface Manager OpenGL Media Framework SQLite WebKit SSL ... Bionic
Android Bionic
Bionic libc libm libdl Linker libstdc++
Bionic libc libm libdl Linker libstdc++ License Size Speed
Bionic libc libm libdl Linker libstdc++ BSD + Rewritten code
+ Android specific services
Bionic libc libm libdl Linker libstdc++
Bionic libc libm libdl Linker libstdc++ Completely from scratch! dlopen()
dlsym() dlerror() dlclose() {
Bionic libc libm libdl Linker libstdc++
Kernel Display driver USB driver Camera driver WiFi driver Power
Mgmt. Binder IPC ... Libraries Android Runtime (Dalvik/ART) Core Libraries Dalvik Virtual Machine (DVM) Surface Manager OpenGL Media Framework SQLite WebKit SSL ... Bionic
Kernel Display driver USB driver Camera driver WiFi driver Power
Mgmt. Binder IPC ... Application Framework Apps Home Contacts Dialer Clock Your app 3rd party app ... Activity Manager Window Manager Package Manager Location Manager View System Content Providers ... Libraries Android Runtime (Dalvik/ART) Core Libraries Dalvik Virtual Machine (DVM) Surface Manager OpenGL Media Framework SQLite WebKit SSL ... Bionic
Kernel Audio driver Application Framework Apps Your app Media Player
Libraries Android Runtime (Dalvik/ART) Core Libraries Dalvik Virtual Machine (DVM) Media Framework Media Player Audio Flinger libaudio.so JNI dlopen()
System.loadLibrary
System.loadLibrary Runtime.loadLibrary
Runtime.java
Runtime.java
None
None
Win: main.dll Linux: libmain.so Mac: libmain.dylib
None
LD_LIBRARY_PATH
Runtime.java
//TODO Runtime::doLoad Runtime.java
//TODO Runtime::doLoad
//TODO Runtime::doLoad LD_LIBRARY_PATH
ClassLoader search (for application libraries) VM search (for system libraries)
Runtime.java
Workaround for zygote’s LD_LIBRARY_PATH Runtime.java
Runtime.cpp
Native.cpp
Native.cpp
Native.cpp
Kernel Application Framework Apps Your app Runtime.java Libraries Android Runtime
Dalvik Virtual Machine (DVM) Native.cpp Runtime.cpp yourlib.so JNI dlopen()
We learned... • Static vs Shared Libraries • Dynamic Loading
• Library paths (+ difference on android) • Android’s internals ◦ Bionic ◦ Dynamic Loading with Dalvik ◦ System.loadLibrary
Thanks! @juliozynger soundcloud.com/jobs