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
24
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
47
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
Fragmented Architectures
denyspoltorak
0
150
Oxlint JS plugins
kazupon
1
900
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6.1k
Best-Practices-for-Cortex-Analyst-and-AI-Agent
ryotaroikeda
1
100
Grafana:建立系統全知視角的捷徑
blueswen
0
330
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
450
余白を設計しフロントエンド開発を 加速させる
tsukuha
7
2.1k
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
200
CSC307 Lecture 09
javiergs
PRO
1
830
AtCoder Conference 2025
shindannin
0
1.1k
Patterns of Patterns
denyspoltorak
0
1.4k
Featured
See All Featured
Writing Fast Ruby
sferik
630
62k
HDC tutorial
michielstock
1
380
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.1k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
76
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Heart Work Chapter 1 - Part 1
lfama
PRO
5
35k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
0
1.9k
WENDY [Excerpt]
tessaabrams
9
36k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.6k
Color Theory Basics | Prateek | Gurzu
gurzu
0
200
Navigating Weather and Climate Data
rabernat
0
100
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?