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
25
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
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
エンジニアの「手元の自動化」を加速するn8n 2026.02.27
symy2co
0
130
Go Conference mini in Sendai 2026 : Goに新機能を提案し実装されるまでのフロー徹底解説
yamatoya
0
550
SourceGeneratorのマーカー属性問題について
htkym
0
180
エージェント開発初心者の僕がエージェントを作った話と今後やりたいこと
thasu0123
0
240
モジュラモノリスにおける境界をGoのinternalパッケージで守る
magavel
0
3.5k
手戻りゼロ? Spec Driven Developmentとは@KAG AI week
tmhirai
1
190
2026年は Rust 置き換えが流行る! / 20260220-niigata-5min-tech
girigiribauer
0
230
How to stabilize UI tests using XCTest
akkeylab
0
110
Fundamentals of Software Engineering In the Age of AI
therealdanvega
1
240
Go1.26 go fixをプロダクトに適用して困ったこと
kurakura0916
0
350
Railsの気持ちを考えながらコントローラとビューを整頓する/tidying-rails-controllers-and-views-as-rails-think
moro
5
390
AI時代のシステム設計:ドメインモデルで変更しやすさを守る設計戦略
masuda220
PRO
4
500
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
141
7.3k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
760
The Cost Of JavaScript in 2023
addyosmani
55
9.8k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
180
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
670
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
330
From π to Pie charts
rasagy
0
150
[SF Ruby Conf 2025] Rails X
palkan
2
820
Building Adaptive Systems
keathley
44
2.9k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.2k
Unsuck your backbone
ammeep
672
58k
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?