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
19
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
43
Android Lx - 25 Jan 2017 - RxJava: More than the basic
sergiomarquesmoura
0
85
AndKotlin
sergiomarquesmoura
0
33
Other Decks in Programming
See All in Programming
見た目から始める生産性向上
ikumatadokoro
10
1.3k
効率化に挑戦してみたらモバイル開発が少し快適になった話
ryunakayama
0
140
if constexpr文はテンプレート世界のラムダ式である
faithandbrave
3
670
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
1k
単体テストを書かない技術 #phpcon_odawara
o0h
PRO
27
8.5k
Deep Dive into React Stream/Serialize
mugi_uno
3
550
Apache Hive 4 on Treasure Data
ryukobayashi
1
410
AmperとFleetを使ったAndroidアプリ
yoppie
0
250
SIMD Parallel Programming with the Vector API
josepaumard
0
220
Komplexe Oberflächen mit SVG und der Web Animation API
joergneumann
0
680
使ってみよう Azure AI Document Intelligence
kosmosebi
2
360
From Spring Boot 2 to Spring Boot 3 with Java 21 and Jakarta EE
ivargrimstad
0
430
Featured
See All Featured
Clear Off the Table
cherdarchuk
85
310k
GraphQLの誤解/rethinking-graphql
sonatard
55
9.3k
Fantastic passwords and where to find them - at NoRuKo
philnash
38
2.5k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
275
13k
Designing for humans not robots
tammielis
248
25k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
41
4.4k
Teambox: Starting and Learning
jrom
128
8.4k
In The Pink: A Labor of Love
frogandcode
138
21k
It's Worth the Effort
3n
180
27k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
Faster Mobile Websites
deanohume
300
30k
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?