SlideShare a Scribd company logo
1 of 16
Download to read offline
Native Development Kit 
…for Android OS 
novikov.ruslan@gmail.com
C/assembly 
C/C++ 
C/C++ 
Java 
/ ART
Why NDK Reusing existing code Also your own code For performance critical apps Native code is generally faster that bytecode To access low-level APIs Native lets you access more physical memory “Java” heap is seriously limited per app in a Android You are C++ freak
Let’s write some Java
Pre-NDK era 
•JNI always have been there 
•Native libraries always have been there 
•You could bundle your .so if you are ROM vendor 
•But you could not develop app that uses C/C++ code
What’s inside 
•NDK is a toolchain 
–Contains cross-compiler for ARM, x86, MIPS 
•NDK bundles native library into your app 
•Standardizes some native APIs 
–libc (C library) headers 
–libm (math library) headers 
–JNI interface headers 
–libz (Zlib compression) headers 
–liblog (Android logging) header 
–OpenGL ES 1.1 and OpenGL ES 2.0 (3D graphics libraries) headers 
–libjnigraphics (Pixel buffer access) header (for Android 2.2 and above). 
–A Minimal set of headers for C++ support 
–OpenSL ES native audio libraries 
–Android native application APIS
How to begin 
•You can develop on 
–Windows 
–Mac 
–Linux 
•You need download and unzip the latest NDK 
•If Inside eclipse, set Preferences->Android->NDK to mentioned directory 
•rclick on Android Project -> Android -> Add Native Support
Let’s write some C
"escape hatch" for Java 
•Technology that enables Java code running in a VM to call and be called by native applications 
•Has C and C++ interfaces 
•Has many of pitfalls: 
–Subtle errors in the use of JNI can destabilize the entire MRE 
–An application that relies on JNI loses the platform portability 
–The JNI framework does not provide any automatic garbage collection for non-JVM memory resources
Let’s do some JNI
Type Mapping From Java->C 
Native Type 
Java Language Type 
Description 
Type signature 
unsigned char 
jboolean 
unsigned 8 bits 
Z 
signed char 
jbyte 
signed 8 bits 
B 
unsigned short 
jchar 
unsigned 16 bits 
C 
short 
jshort 
signed 16 bits 
S 
long 
jint 
signed 32 bits 
I 
long long __int64 
jlong 
signed 64 bits 
J 
float 
jfloat 
32 bits 
F 
double 
jdouble 
64 bits 
D 
void 
V 
"L fully-qualified-class ;"
Summarizing Build Process
Why not NDK 
•Complexity 
•Significant part of the framework is not accessible via NDK (at least currently) 
•There are better tooling for Java development and debugging 
•Multiple architectures should be taken into account 
•Ironically native code can perform worse in some cases 
In general, you should only use the NDK if it is essential to your app—never because you simply prefer to program in C/C++
•Android programs are commonly written in Java and compiled to Java bytecode, which is then translated to Dalvik bytecode and stored in .dex (Dalvik EXecutable) 
•Later the bytecode is executed under Managed Runtime Environment (MRE) 
•Android Runtime (ART) is an MRE that replaced Dalvik VM beginning with Lollipop 
•Native code executes inside a process that contains MRE (Dalvik VM or ART) 
•(Dalvik) Bytecode executes under the control of the Runtime (Dalvik VM or ART)
References 
•http://stackoverflow.com/questions/11992836/where-exactly-does-ndk-native-code-execute 
•http://multi-core- dump.blogspot.co.il/2010/04/android- application-launch.html 
•http://coltf.blogspot.co.il/p/android-os- processes-and-zygote.html 
•https://groups.google.com/forum/#!topic/android-ndk/lcnwzszrESo

More Related Content

What's hot

Dotnet framework
Dotnet frameworkDotnet framework
Dotnet framework
Nitu Pandey
 
Presentation1
Presentation1Presentation1
Presentation1
kpkcsc
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
Dmytro Mindra
 

What's hot (20)

Introduction to c_sharp
Introduction to c_sharpIntroduction to c_sharp
Introduction to c_sharp
 
Java vs .net (beginners)
Java vs .net (beginners)Java vs .net (beginners)
Java vs .net (beginners)
 
Net framework
Net frameworkNet framework
Net framework
 
JetBrains MPS: Projectional Editing in Domain-Specific Languages
JetBrains MPS: Projectional Editing in Domain-Specific LanguagesJetBrains MPS: Projectional Editing in Domain-Specific Languages
JetBrains MPS: Projectional Editing in Domain-Specific Languages
 
Introduction to c language | History of C language
Introduction to c language | History of C languageIntroduction to c language | History of C language
Introduction to c language | History of C language
 
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
 
Introduction to .NET Framework
Introduction to .NET FrameworkIntroduction to .NET Framework
Introduction to .NET Framework
 
Introduction to .NET Framework
Introduction to .NET FrameworkIntroduction to .NET Framework
Introduction to .NET Framework
 
.Net framework
.Net framework.Net framework
.Net framework
 
Introduction to .NET by QuontraSolutions
Introduction to .NET by QuontraSolutionsIntroduction to .NET by QuontraSolutions
Introduction to .NET by QuontraSolutions
 
Introduction .NET Framework
Introduction .NET FrameworkIntroduction .NET Framework
Introduction .NET Framework
 
Net framework
Net frameworkNet framework
Net framework
 
Common language runtime clr
Common language runtime clrCommon language runtime clr
Common language runtime clr
 
Dotnet framework
Dotnet frameworkDotnet framework
Dotnet framework
 
Log cat kotlindsl
Log cat kotlindslLog cat kotlindsl
Log cat kotlindsl
 
Presentation1
Presentation1Presentation1
Presentation1
 
.Net + novas tecnologias + win8
.Net + novas tecnologias + win8.Net + novas tecnologias + win8
.Net + novas tecnologias + win8
 
Microsoft .NET Framework
Microsoft .NET FrameworkMicrosoft .NET Framework
Microsoft .NET Framework
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
 
ctchou-resume
ctchou-resumectchou-resume
ctchou-resume
 

Similar to Ndk

Developing and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-androidDeveloping and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-android
Elvis Jon Freddy Sitinjak
 
Toğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırma
Toğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırmaToğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırma
Toğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırma
Farhad
 
Toğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırma
Toğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırmaToğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırma
Toğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırma
Farhad
 
Curso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - StackCurso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - Stack
Jackson F. de A. Mafra
 

Similar to Ndk (20)

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
 
Android NDK
Android NDKAndroid NDK
Android NDK
 
Android ndk
Android ndkAndroid ndk
Android ndk
 
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
Node.js Native AddOns from zero to hero - Nicola Del Gobbo - Codemotion Rome ...
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDK
 
Nodejs Native Add-Ons from zero to hero
Nodejs Native Add-Ons from zero to heroNodejs Native Add-Ons from zero to hero
Nodejs Native Add-Ons from zero to hero
 
Introduction to Java Part-2
Introduction to Java Part-2Introduction to Java Part-2
Introduction to Java Part-2
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
Android ndk - Introduction
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - Introduction
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java
 
NDK Programming in Android
NDK Programming in AndroidNDK Programming in Android
NDK Programming in Android
 
Developing and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-androidDeveloping and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-android
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
 
Developing a mobile cross-platform library
Developing a mobile cross-platform libraryDeveloping a mobile cross-platform library
Developing a mobile cross-platform library
 
Session 01 - Introduction to Java
Session 01 - Introduction to JavaSession 01 - Introduction to Java
Session 01 - Introduction to Java
 
Alternatives to Java for Android development
Alternatives to Java for Android developmentAlternatives to Java for Android development
Alternatives to Java for Android development
 
Toğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırma
Toğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırmaToğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırma
Toğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırma
 
Toğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırma
Toğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırmaToğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırma
Toğrul Tağıyev - Müxtəlif dillərdə Android proqramlaşdırma
 
Curso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - StackCurso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - Stack
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

Ndk

  • 1. Native Development Kit …for Android OS novikov.ruslan@gmail.com
  • 3. Why NDK Reusing existing code Also your own code For performance critical apps Native code is generally faster that bytecode To access low-level APIs Native lets you access more physical memory “Java” heap is seriously limited per app in a Android You are C++ freak
  • 5. Pre-NDK era •JNI always have been there •Native libraries always have been there •You could bundle your .so if you are ROM vendor •But you could not develop app that uses C/C++ code
  • 6. What’s inside •NDK is a toolchain –Contains cross-compiler for ARM, x86, MIPS •NDK bundles native library into your app •Standardizes some native APIs –libc (C library) headers –libm (math library) headers –JNI interface headers –libz (Zlib compression) headers –liblog (Android logging) header –OpenGL ES 1.1 and OpenGL ES 2.0 (3D graphics libraries) headers –libjnigraphics (Pixel buffer access) header (for Android 2.2 and above). –A Minimal set of headers for C++ support –OpenSL ES native audio libraries –Android native application APIS
  • 7. How to begin •You can develop on –Windows –Mac –Linux •You need download and unzip the latest NDK •If Inside eclipse, set Preferences->Android->NDK to mentioned directory •rclick on Android Project -> Android -> Add Native Support
  • 9. "escape hatch" for Java •Technology that enables Java code running in a VM to call and be called by native applications •Has C and C++ interfaces •Has many of pitfalls: –Subtle errors in the use of JNI can destabilize the entire MRE –An application that relies on JNI loses the platform portability –The JNI framework does not provide any automatic garbage collection for non-JVM memory resources
  • 11. Type Mapping From Java->C Native Type Java Language Type Description Type signature unsigned char jboolean unsigned 8 bits Z signed char jbyte signed 8 bits B unsigned short jchar unsigned 16 bits C short jshort signed 16 bits S long jint signed 32 bits I long long __int64 jlong signed 64 bits J float jfloat 32 bits F double jdouble 64 bits D void V "L fully-qualified-class ;"
  • 13.
  • 14. Why not NDK •Complexity •Significant part of the framework is not accessible via NDK (at least currently) •There are better tooling for Java development and debugging •Multiple architectures should be taken into account •Ironically native code can perform worse in some cases In general, you should only use the NDK if it is essential to your app—never because you simply prefer to program in C/C++
  • 15. •Android programs are commonly written in Java and compiled to Java bytecode, which is then translated to Dalvik bytecode and stored in .dex (Dalvik EXecutable) •Later the bytecode is executed under Managed Runtime Environment (MRE) •Android Runtime (ART) is an MRE that replaced Dalvik VM beginning with Lollipop •Native code executes inside a process that contains MRE (Dalvik VM or ART) •(Dalvik) Bytecode executes under the control of the Runtime (Dalvik VM or ART)
  • 16. References •http://stackoverflow.com/questions/11992836/where-exactly-does-ndk-native-code-execute •http://multi-core- dump.blogspot.co.il/2010/04/android- application-launch.html •http://coltf.blogspot.co.il/p/android-os- processes-and-zygote.html •https://groups.google.com/forum/#!topic/android-ndk/lcnwzszrESo