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
29
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
50
Android Lx - 25 Jan 2017 - RxJava: More than the basic
sergiomarquesmoura
0
96
AndKotlin
sergiomarquesmoura
0
42
Other Decks in Programming
See All in Programming
「つくるAI」だけではバグは見つからない ~テストに必要な「見つけるAI」を分離させる戦略~
mfunaki
0
230
KotlinConf Extended South Korea 2026 Keynote
l2hyunwoo
0
130
iOS開発×AI駆動開発 〜最近使って便利だったスキルの話〜
nogu66
0
140
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
53
34k
私のClaude Code活用法 (個人開発編) - PHPerKaigi mini #4(2026/08/24)
panda_program
1
210
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
100
PHPプロジェクトの結合バランスを可視化する #php_night
kajitack
0
200
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
1
450
Jindong: Introducing Declarative Haptics in Compose Multiplatform
l2hyunwoo
0
140
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
思考垂れ流し開発 ~音声入力 × AIエージェント × 開発ハーネスによる試行錯誤~
npostring
0
810
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
0
380
Featured
See All Featured
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
490
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
550
Become a Pro
speakerdeck
PRO
31
6.2k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
920
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
590
Google's AI Overviews - The New Search
badams
0
1.6k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
520
How STYLIGHT went responsive
nonsquared
100
6.3k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
230
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?