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
0
20
Go Native: Integrating Native Code on Android
Sérgio Marques Moura
July 10, 2018
Tweet
Share
More Decks by Sérgio Marques Moura
See All by Sérgio Marques Moura
Painless Libraries - Londroid April 2019
sergiomarquesmoura
2
120
AndroidLX: From an app to a library
sergiomarquesmoura
2
44
Android Lx - 25 Jan 2017 - RxJava: More than the basic
sergiomarquesmoura
0
86
AndKotlin
sergiomarquesmoura
0
35
Other Decks in Programming
See All in Programming
Is Xcode slowly dying out in 2025?
uetyo
1
270
新メンバーも今日から大活躍!SREが支えるスケールし続ける組織のオンボーディング
honmarkhunt
5
7.2k
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
470
#kanrk08 / 公開版 PicoRubyとマイコンでの自作トレーニング計測装置を用いたワークアウトの理想と現実
bash0c7
1
770
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
390
なんとなくわかった気になるブロックテーマ入門/contents.nagoya 2025 6.28
chiilog
1
270
プロダクト志向ってなんなんだろうね
righttouch
PRO
0
190
PostgreSQLのRow Level SecurityをPHPのORMで扱う Eloquent vs Doctrine #phpcon #track2
77web
2
530
「テストは愚直&&網羅的に書くほどよい」という誤解 / Test Smarter, Not Harder
munetoshi
0
170
RailsGirls IZUMO スポンサーLT
16bitidol
0
180
Systèmes distribués, pour le meilleur et pour le pire - BreizhCamp 2025 - Conférence
slecache
0
120
NPOでのDevinの活用
codeforeveryone
0
830
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
How GitHub (no longer) Works
holman
314
140k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
107
19k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Why Our Code Smells
bkeepers
PRO
336
57k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
Music & Morning Musume
bryan
46
6.6k
It's Worth the Effort
3n
185
28k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.9k
Side Projects
sachag
455
42k
KATA
mclloyd
30
14k
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?