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
CSC307 Lecture 08
javiergs
PRO
0
670
今から始めるClaude Code超入門
448jp
8
8.7k
CSC307 Lecture 03
javiergs
PRO
1
490
CSC307 Lecture 02
javiergs
PRO
1
780
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
180
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
200
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
140
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
130
Grafana:建立系統全知視角的捷徑
blueswen
0
330
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
Apache Iceberg V3 and migration to V3
tomtanaka
0
160
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
Featured
See All Featured
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
140
Test your architecture with Archunit
thirion
1
2.1k
The SEO identity crisis: Don't let AI make you average
varn
0
240
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
200
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Code Review Best Practice
trishagee
74
20k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
Raft: Consensus for Rubyists
vanstee
141
7.3k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
110
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
170
How to Ace a Technical Interview
jacobian
281
24k
How to train your dragon (web standard)
notwaldorf
97
6.5k
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?