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

System.loadLibrary("Unix, Native Code and why b...

System.loadLibrary("Unix, Native Code and why bother")

Presented at AppDevCon (Amsterdam) 2018

Júlio Zynger

March 16, 2018
Tweet

More Decks by Júlio Zynger

Other Decks in Programming

Transcript

  1. 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
  2. source code compiler linker objects (.o) .o .o .o .a

    archive .o executable .so .so .so .so
  3. source code compiler linker loader objects (.o) .o .o .o

    .a archive .o executable in-memory image .so .so .so .so
  4. 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
  5. Kernel Display driver USB driver Camera driver WiFi driver Power

    Mgmt. Binder IPC ... Libraries Surface Manager OpenGL Media Framework SQLite WebKit SSL ... Bionic
  6. 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
  7. 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
  8. 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()
  9. Kernel Application Framework Apps Your app Runtime.java Libraries Android Runtime

    Dalvik Virtual Machine (DVM) Native.cpp Runtime.cpp yourlib.so JNI dlopen()
  10. We learned... • Static vs Shared Libraries • Dynamic Loading

    • Library paths (+ difference on android) • Android’s internals ◦ Bionic ◦ Dynamic Loading with Dalvik ◦ System.loadLibrary