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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Sérgio Marques Moura
July 10, 2018
Programming
28
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
95
AndKotlin
sergiomarquesmoura
0
40
Other Decks in Programming
See All in Programming
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
3.2k
Symfony AI in Action - SymfonyLive Berlin 2026
chr_hertel
1
160
色即是空、空即是色、データサイエンス
kamoneggi
1
120
[BalkanRuby 2026] Drop your app/services!
palkan
3
540
Skillは並べた。動かなかった。契約で繋いだ。— 65個のSkillから、自走する開発サイクルへ
junholee
0
630
AWSはOSSをどのように 考えているのか?
akihisaikeda
0
120
サプライチェーン攻撃対策「層を重ねて落ちない壁」を10日間で組み上げた話 #TechLeadConf2026
kashewnuts
1
290
cloudnative conference 2026 flyle
azihsoyn
1
190
iOS26時代の新規アプリ開発
yuukiw00w
0
140
Are We Really Coding 10× Faster with AI?
kohzas
0
190
tsserverとは何だったのか_これからどうなるのか
nowaki28
0
140
【ディップ|26年新卒研修資料】OpenAPI/Swagger REST API研修
dip_tech
PRO
0
170
Featured
See All Featured
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
240
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
180
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
800
Technical Leadership for Architectural Decision Making
baasie
3
370
Side Projects
sachag
455
43k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
910
Paper Plane
katiecoart
PRO
1
50k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.8k
Amusing Abliteration
ianozsvald
1
170
First, design no harm
axbom
PRO
2
1.2k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
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?