Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Go Native: Integrating Native Code on Android
Search
Sérgio Marques Moura
July 10, 2018
Programming
25
0
Share
Go Native: Integrating Native Code on Android
Sérgio Marques Moura
July 10, 2018
More Decks by Sérgio Marques Moura
See All by Sérgio Marques Moura
Painless Libraries - Londroid April 2019
sergiomarquesmoura
2
130
AndroidLX: From an app to a library
sergiomarquesmoura
2
48
Android Lx - 25 Jan 2017 - RxJava: More than the basic
sergiomarquesmoura
0
90
AndKotlin
sergiomarquesmoura
0
39
Other Decks in Programming
See All in Programming
ポーリング処理廃止によるイベント駆動アーキテクチャへの移行
seitarof
3
1.3k
ロボットのための工場に灯りは要らない
watany
12
3.3k
20260320登壇資料
pharct
0
140
PHP でエミュレータを自作して Ubuntu を動かそう
m3m0r7
PRO
2
150
PHPのバージョンアップ時にも役立ったAST(2026年版)
matsuo_atsushi
0
270
2026-03-27 #terminalnight 変数展開とコマンド展開でターミナル作業をスマートにする方法
masasuzu
0
270
Kubernetesでセルフホストが簡単なNewSQLを求めて / Seeking a NewSQL Database That's Simple to Self-Host on Kubernetes
nnaka2992
0
190
PHPで TLSのプロトコルを実装してみる
higaki_program
0
660
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
350
夢の無限スパゲッティ製造機 -実装篇- #phpstudy
o0h
PRO
0
180
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
220
Ruby and LLM Ecosystem 2nd
koic
1
1.4k
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
141
7.4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
64
54k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
320
Typedesign – Prime Four
hannesfritz
42
3k
Documentation Writing (for coders)
carmenintech
77
5.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The Invisible Side of Design
smashingmag
302
51k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
210
Discover your Explorer Soul
emna__ayadi
2
1.1k
RailsConf 2023
tenderlove
30
1.4k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
210
Transcript
sergiomarquesmoura Go Native: Integrating native code on Android Sérgio Moura
Why native code? ➔ Java is slow ◆ Arithmetic tasks
◆ Image processing ➔ Gradle support ◆ Cmake ◆ ndk-build ➔ Research teams do it native ◆ C/C++
Git Submodules
[submodule "glare_detector"] path = onfido-capture-sdk/src/main/jni/edge_detector url =
[email protected]
:onfido/edge_detector.git ➔ Name
➔ Path ➔ Url $ git submodule update --init
None
Compiling the code
None
But why compiling?
Why compiling native code? ➔ Multiple devices ◆ Wide range
of CPUs • Multiple instruction sets ➔ Solution: ABIs (Application Binary Interface) ◆ armeabi-v7a ◆ arm64-v8a ◆ x86 ◆ x86_64
android { ... defaultConfig { ... externalNativeBuild { cmake {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' } } } externalNativeBuild { cmake { path 'src/main/jni/CMakeLists.txt' } } }
cmake_minimum_required(VERSION 3.6) project(NativeBridge) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/glare_detector) add_library(GlareBridge SHARED GlareBridge.cpp) target_link_libraries(GlareBridge GlareDetector)
Building the bridge
extern "C" { JNIEXPORT jobjectArray JNICALL Java_com_onfido_android_sdk_capture_native_1detector_NativeDetector_detectGla re(JNIEnv *, jobject,
jbyteArray, jint, jint, jint, jint, jint, jint, jint, jint); }
Back to Java
public class NativeDetector { static { System. loadLibrary("GlareBridge"); } public
native double[][] detectGlare(byte[] imageData, int width, int height, int rectWidth, int rectHeight, int rectLeft, int rectTop, int numRows, int numCols); } new NativeDetector().detectGlare( … );
Thank you! Questions?