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
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
210
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
イベント駆動で成長して委員会
happymana
1
340
CSC509 Lecture 11
javiergs
PRO
0
180
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2.1k
Jakarta EE meets AI
ivargrimstad
0
270
Vapor Revolution
kazupon
2
510
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
120
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
120
Building Your Own Lightsaber
phodgson
103
6.1k
Writing Fast Ruby
sferik
627
61k
Docker and Python
trallard
40
3.1k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Music & Morning Musume
bryan
46
6.2k
Unsuck your backbone
ammeep
668
57k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Ruby is Unlike a Banana
tanoku
97
11k
KATA
mclloyd
29
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?