SlideShare une entreprise Scribd logo
1  sur  11
Android NDK Intro
Tokyo Android Meetup 21st July 2016
About The Presenter
Giles Payne
Android Developer - TenTen Corp
Developing for Android since Cupcake
BA Honours Mathematics and Computation, Oxford University
Country of Origin: Scotland
What is the Android NDK?
A set of tools for building/debugging C/C++ code to run on Android
Invoked from Java via JNI(Java Native Interface)
Available for download at https://developer.android.com/ndk/index.html
Android NDK - Why?
Performance
Order of magnitude speedup for performance critical code
Code reuse
Existing code C/C++ base can be ported to Android without total rewrite in Java
Large amount of libraries written in C/C++ can be reused (boost/cocos2d-x/OpenCV)
Cross platform development
iOS and other mobile OSs all support C/C++
NDK How To
Declare method as native with no body
public native void myNativeMethod();
Use javah to generate native stub
javah -o "MyClass.h" -classpath "/home/giles/myjavalibs" com.example.MyClass
Add implementation to stub and build C/C++ lib
extern "C" void Java_com_example_MyClass_myNativeMethod(JNIEnv* env, jobject this) {
/* do stuff */
}
What if I need to call back out to Java?
jclass myjclass = (*env)->GetObjectClass(env, myjobj);
jmethodID myMethodId = (*env)->GetMethodID(env, myjclass, "myMethod", "()Ljava/lang/String;");
jstring jstrResult = (jstring)(*env)->CallObjectMethod(env, myjobj, myMethodId);
Reference:
http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html
Android NDK Gotchas
Managing your own reference counting
Check you have correct calls to NewStringUTF/ReleaseStringUTFChars
Create/delete global references using NewGlobalRef/DeleteGlobalRef
Library state on second run
Native libraries will not be unloaded after the calling Java activity exits!
Libraries need to be completely reinitialized when calling activity restarts. Hint:
extern int __bss_start;
extern int _end;
void reStart() {
void* bssBackup = native_backup_bss(); /* back-up somethings that need to be remembered */
memset((void*)__bss_start, 0 , _end-__bss_start); /* clear all memory that was initially zeroed */
Android NDK with autotools
Inspect verbose output to get the correct compiler linker flags. Might look
something like:
./configure --with-gcc=$ANDROID_NDK/toolchains/$ANDROID_NDK_TOOLCHAIN/bin/arm-linux-androideabi-gcc --with-
ld=$ANDROID_NDK/toolchains/$ANDROID_NDK_TOOLCHAIN/bin/arm-linux-androideabi-ld --build=i386-unknown-linux --
host=arm-unknown-linux CFLAGS="-w -I$ANDROID_NDK/platforms/android-18/arch-arm/usr/include -march=armv5te -
DANDROID -mtune=xscale -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64" LDFLAGS="--
sysroot=$ANDROID_NDK/platforms/android-18/arch-arm -lgcc -no-canonical-prefixes -Wl,-z,noexecstack -lc -lm -llog"
NDK Chip Architecture Support
ARM - nearly all smartphones use ARM chips
x86 - recently x86 tablets becoming more common
MIPs - not widely used
Android NDK Debugging: The Old Way
Set up port forwarding for android emulator
adb forward tcp:1234 tcp:1234
Run gdbserver on device/emulator
gdbserver :1234 ondevicebinary args
Run gdb on PC
./arm-linux-androideabi-gdb.exe
Select file
file onPCbinary
Set shared object search path
set solib-search-path .
Run
target remote :1234
Android NDK Debugging: The New Way
Demo!

Contenu connexe

Tendances

Docker deploy
Docker deployDocker deploy
Docker deployEric Ahn
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++Joan Puig Sanz
 
Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo Yu-Shuan Hsieh
 
TDC2018SP | Trilha Containers - CI/CD com Docker e Drone
TDC2018SP | Trilha Containers - CI/CD com Docker e DroneTDC2018SP | Trilha Containers - CI/CD com Docker e Drone
TDC2018SP | Trilha Containers - CI/CD com Docker e Dronetdc-globalcode
 
Common design patterns (migang 16 May 2012)
Common design patterns (migang 16 May 2012)Common design patterns (migang 16 May 2012)
Common design patterns (migang 16 May 2012)Steven Smith
 
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit, Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit, Farshid Pirahansiah
 
Mobile C++
Mobile C++Mobile C++
Mobile C++gdgut
 
NDK Programming in Android
NDK Programming in AndroidNDK Programming in Android
NDK Programming in AndroidArvind Devaraj
 
HOW TO RUN RSTUDIO SERVERS ANYWHERE WITH CONTAINERS - HPC, CLOUD, AND LOCALLY
HOW TO RUN RSTUDIO SERVERS ANYWHERE WITH CONTAINERS - HPC, CLOUD, AND LOCALLYHOW TO RUN RSTUDIO SERVERS ANYWHERE WITH CONTAINERS - HPC, CLOUD, AND LOCALLY
HOW TO RUN RSTUDIO SERVERS ANYWHERE WITH CONTAINERS - HPC, CLOUD, AND LOCALLYWendy Wong
 
July 2015 Android Taipei - Anti-Decompiler by SUKI
July 2015 Android Taipei - Anti-Decompiler by SUKIJuly 2015 Android Taipei - Anti-Decompiler by SUKI
July 2015 Android Taipei - Anti-Decompiler by SUKISuki Huang
 
Take care of hundred containers and not go crazy
Take care of hundred containers and not go crazyTake care of hundred containers and not go crazy
Take care of hundred containers and not go crazyHonza Horák
 
Common Workflow Language (CWL) - George Carvalho
Common Workflow Language (CWL) -  George CarvalhoCommon Workflow Language (CWL) -  George Carvalho
Common Workflow Language (CWL) - George CarvalhoGeorge Carvalho
 
Native development kit (ndk) introduction
Native development kit (ndk)  introductionNative development kit (ndk)  introduction
Native development kit (ndk) introductionRakesh Jha
 
Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0André Moreira
 
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...Yoshifumi Kawai
 

Tendances (18)

Docker deploy
Docker deployDocker deploy
Docker deploy
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
 
Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo
 
TDC2018SP | Trilha Containers - CI/CD com Docker e Drone
TDC2018SP | Trilha Containers - CI/CD com Docker e DroneTDC2018SP | Trilha Containers - CI/CD com Docker e Drone
TDC2018SP | Trilha Containers - CI/CD com Docker e Drone
 
.Net Core
.Net Core.Net Core
.Net Core
 
Common design patterns (migang 16 May 2012)
Common design patterns (migang 16 May 2012)Common design patterns (migang 16 May 2012)
Common design patterns (migang 16 May 2012)
 
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit, Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
 
Mobile C++
Mobile C++Mobile C++
Mobile C++
 
NDK Programming in Android
NDK Programming in AndroidNDK Programming in Android
NDK Programming in Android
 
Android and cpp
Android and cppAndroid and cpp
Android and cpp
 
HOW TO RUN RSTUDIO SERVERS ANYWHERE WITH CONTAINERS - HPC, CLOUD, AND LOCALLY
HOW TO RUN RSTUDIO SERVERS ANYWHERE WITH CONTAINERS - HPC, CLOUD, AND LOCALLYHOW TO RUN RSTUDIO SERVERS ANYWHERE WITH CONTAINERS - HPC, CLOUD, AND LOCALLY
HOW TO RUN RSTUDIO SERVERS ANYWHERE WITH CONTAINERS - HPC, CLOUD, AND LOCALLY
 
July 2015 Android Taipei - Anti-Decompiler by SUKI
July 2015 Android Taipei - Anti-Decompiler by SUKIJuly 2015 Android Taipei - Anti-Decompiler by SUKI
July 2015 Android Taipei - Anti-Decompiler by SUKI
 
Take care of hundred containers and not go crazy
Take care of hundred containers and not go crazyTake care of hundred containers and not go crazy
Take care of hundred containers and not go crazy
 
Common Workflow Language (CWL) - George Carvalho
Common Workflow Language (CWL) -  George CarvalhoCommon Workflow Language (CWL) -  George Carvalho
Common Workflow Language (CWL) - George Carvalho
 
Native development kit (ndk) introduction
Native development kit (ndk)  introductionNative development kit (ndk)  introduction
Native development kit (ndk) introduction
 
Oscon Talk; 2014
Oscon Talk; 2014Oscon Talk; 2014
Oscon Talk; 2014
 
Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0
 
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
 

En vedette

Sport tourism product of greece 2008 by goutzioupas george
Sport tourism product of greece 2008 by goutzioupas georgeSport tourism product of greece 2008 by goutzioupas george
Sport tourism product of greece 2008 by goutzioupas georgeGeorge Goutzioupas
 
Electricidad y electrónica
Electricidad y electrónicaElectricidad y electrónica
Electricidad y electrónicajuana0910
 
Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]
Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]
Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]rusell rivera urbina
 
Sanctum Consulting can help people travel to Greece for tourist visa
 Sanctum Consulting can help people travel to Greece for tourist visa   Sanctum Consulting can help people travel to Greece for tourist visa
Sanctum Consulting can help people travel to Greece for tourist visa Sanctum Business Consulting Pvt Ltd
 
Responsabilidad social corporativa 2
Responsabilidad social  corporativa 2Responsabilidad social  corporativa 2
Responsabilidad social corporativa 2kariosmara
 
Glossario de Search Engine Marketing
Glossario de Search Engine MarketingGlossario de Search Engine Marketing
Glossario de Search Engine MarketingPablo Almeida
 
Gestion y Asesoramiento en la compraventa de vehiculos
Gestion y Asesoramiento en la compraventa de vehiculosGestion y Asesoramiento en la compraventa de vehiculos
Gestion y Asesoramiento en la compraventa de vehiculosJ.M.A.S
 
Five IT Considerations for the Media-Centric Hotel Room
Five IT Considerations for the Media-Centric Hotel RoomFive IT Considerations for the Media-Centric Hotel Room
Five IT Considerations for the Media-Centric Hotel RoomSamsung Business USA
 
Presentacion seguridad internet balvina
Presentacion seguridad internet balvinaPresentacion seguridad internet balvina
Presentacion seguridad internet balvinaBAlvina Barrera
 
Unidad educativa diana y gissela
Unidad educativa diana y gisselaUnidad educativa diana y gissela
Unidad educativa diana y gisselagissexsj
 
Certification Reference Letter - TINA KINDEL WALKER
Certification Reference Letter -  TINA KINDEL WALKERCertification Reference Letter -  TINA KINDEL WALKER
Certification Reference Letter - TINA KINDEL WALKER?Tina Walker? -L ! O N-
 
What we have in common
What we have in commonWhat we have in common
What we have in commonAdinaTeodora
 
Final presentation research project mergers and acquisitions-august 2014 by m...
Final presentation research project mergers and acquisitions-august 2014 by m...Final presentation research project mergers and acquisitions-august 2014 by m...
Final presentation research project mergers and acquisitions-august 2014 by m...Mostafa Talaat
 
IPE-DHL"gestione dei flussi di approvvigionamento dei materiali operativi" 2015
IPE-DHL"gestione dei flussi di approvvigionamento dei materiali operativi" 2015IPE-DHL"gestione dei flussi di approvvigionamento dei materiali operativi" 2015
IPE-DHL"gestione dei flussi di approvvigionamento dei materiali operativi" 2015IPE Business School
 

En vedette (20)

Pablofernandez4 a hipervinculo
Pablofernandez4 a hipervinculoPablofernandez4 a hipervinculo
Pablofernandez4 a hipervinculo
 
Sport tourism product of greece 2008 by goutzioupas george
Sport tourism product of greece 2008 by goutzioupas georgeSport tourism product of greece 2008 by goutzioupas george
Sport tourism product of greece 2008 by goutzioupas george
 
Electricidad y electrónica
Electricidad y electrónicaElectricidad y electrónica
Electricidad y electrónica
 
Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]
Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]
Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]
 
Sanctum Consulting can help people travel to Greece for tourist visa
 Sanctum Consulting can help people travel to Greece for tourist visa   Sanctum Consulting can help people travel to Greece for tourist visa
Sanctum Consulting can help people travel to Greece for tourist visa
 
Responsabilidad social corporativa 2
Responsabilidad social  corporativa 2Responsabilidad social  corporativa 2
Responsabilidad social corporativa 2
 
Glossario de Search Engine Marketing
Glossario de Search Engine MarketingGlossario de Search Engine Marketing
Glossario de Search Engine Marketing
 
Gestion y Asesoramiento en la compraventa de vehiculos
Gestion y Asesoramiento en la compraventa de vehiculosGestion y Asesoramiento en la compraventa de vehiculos
Gestion y Asesoramiento en la compraventa de vehiculos
 
Five IT Considerations for the Media-Centric Hotel Room
Five IT Considerations for the Media-Centric Hotel RoomFive IT Considerations for the Media-Centric Hotel Room
Five IT Considerations for the Media-Centric Hotel Room
 
Presentacion seguridad internet balvina
Presentacion seguridad internet balvinaPresentacion seguridad internet balvina
Presentacion seguridad internet balvina
 
Hoja de vida
Hoja de vidaHoja de vida
Hoja de vida
 
Unidad educativa diana y gissela
Unidad educativa diana y gisselaUnidad educativa diana y gissela
Unidad educativa diana y gissela
 
Ley islamica
Ley islamicaLey islamica
Ley islamica
 
Certification Reference Letter - TINA KINDEL WALKER
Certification Reference Letter -  TINA KINDEL WALKERCertification Reference Letter -  TINA KINDEL WALKER
Certification Reference Letter - TINA KINDEL WALKER
 
What we have in common
What we have in commonWhat we have in common
What we have in common
 
Privacy and Libraries
Privacy and LibrariesPrivacy and Libraries
Privacy and Libraries
 
NEELKAMAL_PRODUCT BROCHURE
NEELKAMAL_PRODUCT BROCHURENEELKAMAL_PRODUCT BROCHURE
NEELKAMAL_PRODUCT BROCHURE
 
Salah_Attar_DPT
Salah_Attar_DPTSalah_Attar_DPT
Salah_Attar_DPT
 
Final presentation research project mergers and acquisitions-august 2014 by m...
Final presentation research project mergers and acquisitions-august 2014 by m...Final presentation research project mergers and acquisitions-august 2014 by m...
Final presentation research project mergers and acquisitions-august 2014 by m...
 
IPE-DHL"gestione dei flussi di approvvigionamento dei materiali operativi" 2015
IPE-DHL"gestione dei flussi di approvvigionamento dei materiali operativi" 2015IPE-DHL"gestione dei flussi di approvvigionamento dei materiali operativi" 2015
IPE-DHL"gestione dei flussi di approvvigionamento dei materiali operativi" 2015
 

Similaire à Android NDK Intro

Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDKKirill Kounik
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Paris Android User Group
 
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Xavier Hallade
 
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)DroidConTLV
 
Android Native Development Kit
Android Native Development KitAndroid Native Development Kit
Android Native Development KitPeter R. Egli
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDKBeMyApp
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application DevelopmentRamesh Prasad
 
Android ndk - Introduction
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - IntroductionRakesh Jha
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Opersys inc.
 
Android on IA devices and Intel Tools
Android on IA devices and Intel ToolsAndroid on IA devices and Intel Tools
Android on IA devices and Intel ToolsXavier Hallade
 
DLL Design with Building Blocks
DLL Design with Building BlocksDLL Design with Building Blocks
DLL Design with Building BlocksMax Kleiner
 
iOS,From Development to Distribution
iOS,From Development to DistributioniOS,From Development to Distribution
iOS,From Development to DistributionTunvir Rahman Tusher
 
Running native code on Android #OSDCfr 2012
Running native code on Android #OSDCfr 2012Running native code on Android #OSDCfr 2012
Running native code on Android #OSDCfr 2012Cédric Deltheil
 
Hacking the Codename One Source Code - Part V - Transcript.pdf
Hacking the Codename One Source Code - Part V - Transcript.pdfHacking the Codename One Source Code - Part V - Transcript.pdf
Hacking the Codename One Source Code - Part V - Transcript.pdfShaiAlmog1
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'acorehard_by
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)Ron Munitz
 

Similaire à Android NDK Intro (20)

Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDK
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014
 
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
 
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)
 
Android Native Development Kit
Android Native Development KitAndroid Native Development Kit
Android Native Development Kit
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDK
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
Android ndk
Android ndkAndroid ndk
Android ndk
 
Android ndk - Introduction
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - Introduction
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
 
Android NDK
Android NDKAndroid NDK
Android NDK
 
Android on IA devices and Intel Tools
Android on IA devices and Intel ToolsAndroid on IA devices and Intel Tools
Android on IA devices and Intel Tools
 
DLL Design with Building Blocks
DLL Design with Building BlocksDLL Design with Building Blocks
DLL Design with Building Blocks
 
iOS,From Development to Distribution
iOS,From Development to DistributioniOS,From Development to Distribution
iOS,From Development to Distribution
 
Running native code on Android #OSDCfr 2012
Running native code on Android #OSDCfr 2012Running native code on Android #OSDCfr 2012
Running native code on Android #OSDCfr 2012
 
React Native
React NativeReact Native
React Native
 
Hacking the Codename One Source Code - Part V - Transcript.pdf
Hacking the Codename One Source Code - Part V - Transcript.pdfHacking the Codename One Source Code - Part V - Transcript.pdf
Hacking the Codename One Source Code - Part V - Transcript.pdf
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'a
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)
 

Dernier

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 

Dernier (20)

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 

Android NDK Intro

  • 1. Android NDK Intro Tokyo Android Meetup 21st July 2016
  • 2. About The Presenter Giles Payne Android Developer - TenTen Corp Developing for Android since Cupcake BA Honours Mathematics and Computation, Oxford University Country of Origin: Scotland
  • 3. What is the Android NDK? A set of tools for building/debugging C/C++ code to run on Android Invoked from Java via JNI(Java Native Interface) Available for download at https://developer.android.com/ndk/index.html
  • 4. Android NDK - Why? Performance Order of magnitude speedup for performance critical code Code reuse Existing code C/C++ base can be ported to Android without total rewrite in Java Large amount of libraries written in C/C++ can be reused (boost/cocos2d-x/OpenCV) Cross platform development iOS and other mobile OSs all support C/C++
  • 5. NDK How To Declare method as native with no body public native void myNativeMethod(); Use javah to generate native stub javah -o "MyClass.h" -classpath "/home/giles/myjavalibs" com.example.MyClass Add implementation to stub and build C/C++ lib extern "C" void Java_com_example_MyClass_myNativeMethod(JNIEnv* env, jobject this) { /* do stuff */ }
  • 6. What if I need to call back out to Java? jclass myjclass = (*env)->GetObjectClass(env, myjobj); jmethodID myMethodId = (*env)->GetMethodID(env, myjclass, "myMethod", "()Ljava/lang/String;"); jstring jstrResult = (jstring)(*env)->CallObjectMethod(env, myjobj, myMethodId); Reference: http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html
  • 7. Android NDK Gotchas Managing your own reference counting Check you have correct calls to NewStringUTF/ReleaseStringUTFChars Create/delete global references using NewGlobalRef/DeleteGlobalRef Library state on second run Native libraries will not be unloaded after the calling Java activity exits! Libraries need to be completely reinitialized when calling activity restarts. Hint: extern int __bss_start; extern int _end; void reStart() { void* bssBackup = native_backup_bss(); /* back-up somethings that need to be remembered */ memset((void*)__bss_start, 0 , _end-__bss_start); /* clear all memory that was initially zeroed */
  • 8. Android NDK with autotools Inspect verbose output to get the correct compiler linker flags. Might look something like: ./configure --with-gcc=$ANDROID_NDK/toolchains/$ANDROID_NDK_TOOLCHAIN/bin/arm-linux-androideabi-gcc --with- ld=$ANDROID_NDK/toolchains/$ANDROID_NDK_TOOLCHAIN/bin/arm-linux-androideabi-ld --build=i386-unknown-linux -- host=arm-unknown-linux CFLAGS="-w -I$ANDROID_NDK/platforms/android-18/arch-arm/usr/include -march=armv5te - DANDROID -mtune=xscale -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64" LDFLAGS="-- sysroot=$ANDROID_NDK/platforms/android-18/arch-arm -lgcc -no-canonical-prefixes -Wl,-z,noexecstack -lc -lm -llog"
  • 9. NDK Chip Architecture Support ARM - nearly all smartphones use ARM chips x86 - recently x86 tablets becoming more common MIPs - not widely used
  • 10. Android NDK Debugging: The Old Way Set up port forwarding for android emulator adb forward tcp:1234 tcp:1234 Run gdbserver on device/emulator gdbserver :1234 ondevicebinary args Run gdb on PC ./arm-linux-androideabi-gdb.exe Select file file onPCbinary Set shared object search path set solib-search-path . Run target remote :1234
  • 11. Android NDK Debugging: The New Way Demo!