SlideShare a Scribd company logo
1 of 16
Download to read offline
© Peter R. Egli 2015
1/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
Peter R. Egli
INDIGOO.COM
OVERVIEW OF THE ANDROID
NATIVE DEVELOPMENT KIT
ANDROID
NDK
© Peter R. Egli 2015
2/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
Contents
1. What you can do with NDK
2. When to use native code
3. Stable APIs to use / available libraries
4. Build native applications with NDK
5. NDK contents and structure
6. NDK cross-compiler suite
7. Android EABI
8. NDK C++ support
9. JNI - Calling native functions from Java code
10. SDK project with native code
11. Native activity
© Peter R. Egli 2015
3/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
1. What you can do with NDK
• Build native libraries that are callable from Android Java application code (JNI).
• Build executables (non-recommended use of NDK).
• Debug native program (with gdb).
Android Java application
Native library (*.so)
JNI
Dalvik VM
Recommended use of native functions:
An Android Java application makes native
calls through JNI.
Thus the entire application running in the VM
is subject to the defined
Android application lifecycle.
It is possible to run entirely native applications
on Android. However, it is
recommended to use a small Java wrapper
for managing the lifecycle of the application
(start, stop).
Android application (*.apk)
Stable native libraries
(libc, libm, liblog …)
© Peter R. Egli 2015
4/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
2. When to use native code
The power of Android lies in the rich Java application framework to be used by Android
applications written in Java.
In special cases, however, it may be required to write native code that directly runs on the CPU
without the Android VM interpreter.
NDK is a toolkit for writing and integrating native code with Java application code.
Native code characteristics for use in Android:
• Graphically and computationally intensive (e.g. complex algorithms)
• Few library dependencies (restricted to stable Android libraries provided by NDK)
• Little interaction between Java application code and native code (ideally, the Java
application calls computationally intensive native functions and receives the result; there
should not be frequent calls and callbacks between Java and native code)
Primary uses of NDK:
NDK should be used to build native libraries (shared objects) that are called by an Android
application.
Entirely native applications without Java code are possible starting from Android 2.3
(Gingerbread) by using NativeActivity.
Non-recommeded uses of NDK:
Custom native applications that run outside the VM.
© Peter R. Egli 2015
5/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
3. Stable APIs to use / available libraries
The Android NDK contains a small number of stable libraries that are guaranteed to be
contained in successive Android versions.
It is recommended that native code only make use of these stable libraries. If native code uses
non-stable libraries, the native application may break upon an Android update.
android-3 android-4
android-5
android-6
android-7 android-8 android-9 android-14
Library Description Android 1.5 Android 1.6 Android 2.0 Android 2.2 Android 2.3 Android 4.0
crtbegin_dynamic.o Calls of global object ctors Yes Yes Yes Yes Yes Yes
crtbegin_so.o Calls of global object ctors Yes Yes Yes Yes Yes Yes
crtbegin_static.o Calls of global object ctors Yes Yes Yes Yes Yes Yes
crtend_android.o Calls of global object dtors Yes Yes Yes Yes Yes Yes
crtend_so.o Calls of global object dtors Yes Yes Yes Yes Yes Yes
libandroid.so Functions for access to Java platform from native code No No No No Yes Yes
libc.so Standard C library (bionic) Yes Yes Yes Yes Yes Yes
libdl.so Dynamic linker library Yes Yes Yes Yes Yes Yes
libEGL.so Interface library for low level graphics buffer access No No No No Yes Yes
libGLESv1_CM.so Open GL graphics library No Yes Yes Yes Yes Yes
libGLESv2.so Open GL graphics library No No Yes Yes Yes Yes
libjnigraphics.so C-function-based library for graphics pixel access No No No Yes Yes Yes
liblog.so Android logging library Yes Yes Yes Yes Yes Yes
libm.so Math library Yes Yes Yes Yes Yes Yes
libOpenMAXAL.so Audio and video streaming library No No No No No Yes
libOpenSLES.so Audio streaming library No No No No Yes Yes
libstdc++.so Minimal C++ library (no exceptions, no RTTI) Yes Yes Yes Yes Yes Yes
libthread_db.so Thread debug support library. Yes Yes Yes Yes Yes Yes
© Peter R. Egli 2015
6/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
4. Build native applications with NDK
The NDK build system is made for creating .a (static libs) and .so (shared libs).
The shell script <NDK-base>/ndk-build creates the library output.
With some minimal effort it is possible to create fully native applications:
ndk-build
C/C++
source
NDK
arm-eabi-gcc
NDK
arm-eabi-ld
NDK
Prebuilt
libraries
.o
.a
.so
C/C++
source
(main)
Native
executable
© Peter R. Egli 2015
7/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
5. NDK contents and structure (1/2)
NDK installation simply requires unzipping it to a suitable location.
NDK contains a cross-toolchain for ARM and x86 based CPUs, header files and stable libraries.
NDK R7 structure:
Build scripts (makefiles, awk scripts etc.)
Documentation (HTML)
Platforms (header files and stable libraries)
Build executables (make, awk, sed, echo)
Samples (hello world, JNI example etc.)
Source files that can be linked to an application or library
Test scripts for automated tests of the NDK
ARM Linux and x86 toolchains (compiler, linker etc.)
Documentation entry point
Makefile for building NDK
Build script for building a native application or library
Experimental Windows native build script (working?)
GDB debug start script
Stack trace analysis tool
Readme file
NDK release identifier (contents for R7: r7d)
© Peter R. Egli 2015
8/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
5. NDK contents and structure (2/2)
The platforms sub-folder contains stable header files and libraries.
Android API-level 9 (Android 2.3)
ARMv7 CPU architecture header files and libs ('sysroot')
Stable Android API header files and libraries
C++ headers and libraries are under <NDK-base>/sources/cxx-stl.
© Peter R. Egli 2015
9/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
6. NDK cross-compiler suite (1/3)
Standard naming convention for cross-compilers:
<arch>-<vendor>-(os)-<abi>
Example:
arm-linux-androideabi-c++.exe
 Architecture (CPU): ARM
 Vendor: None
 OS: Linux
 ABI: Android EABI (see below)
NDK toolchains:
NDK contains GNU-based cross-compile tools for ARM7 and x86 CPUs.
The NDK toolchain can be used for:
a. NDK integrated toolchain for building shared libraries for use in an Android application
b. Standalone toolchain that is invoked by a custom build
© Peter R. Egli 2015
10/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
6. NDK cross-compiler suite (2/3)
a. NDK integrated toolchain:
Location: <NDK-base>/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows (likewise for
x86 toolchain).
The NDK integrated toolchain uses the scripts, header files and library files that are part of the
NDK installation.
NDK
toolchain
(ndk-build)
© Peter R. Egli 2015
11/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
6. NDK cross-compiler suite (3/3)
Standalone toolchain:
The NDK standalone toolchain is useful for situations where another build system, e.g. as part
of an open source package, needs to invoke a cross-compiler for building.
In the standalone toolchain, everything that is needed for building (compilers etc., header files,
library files) is contained in a single location.
How to create standalone-toolchain:
1. Start bash shell (on Windows start cygwin shell as administrator)
2. Run the make standalone toolchain command:
/cygdrive/c/install/Android-NDK/android-ndk-r7b/build/tools/make-
standalone-toolchain.sh --platform=android-9 --install-
dir=/cygdrive/c/temp/android-standalone-toolchain/
How to invoke the standalone-toolchain:
SET PATH=c:tempandroid-standalone-toolchain;%PATH%
SET CC=arm-linux-androideabi-gcc.exe
%CC% -o foo.o –c foo.c
© Peter R. Egli 2015
12/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
7. Android EABI
What is an ABI?
ABI (Application Binary Interface) defines how an application interacts with the underlying
system at run-time.
An ABI is a low-level interface definition that comprises the following:
- CPU instruction set to use
- Endianness of memory load and store operations
- Format of executable binaries (programs, libraries)
- Function call conventions (stack framing when functions are called, argument passing)
- Alignment of structs and struct fields, enums
The goal of an ABI is binary compatibility between executables (e.g. program calling a library
function).
An EABI (Embedded ABI) defines an ABI for embedded targets.
Android EABI:
Android EABI is basically identical to the Linux (GNU) EABI with the difference of the C-library
(bionic C-library instead of GNU C-library).
Android provides 3 EABIs:
a. armeabi (ARMv5TE instruction set, thumb mode)
b. armeabi-v7a (Thumb-2 instruction set extensions, hardware floating point support)
c. x86 (IA-32 based instruction set)
For more details see <NDK-base>/docs/CPU-ARCH-ABIS.html
© Peter R. Egli 2015
13/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
8. NDK C++ support
NDK provides some basic C++ runtime support through the default /system/lib/libstdc++
library.
The following C++ features are not supported:
- C++ exceptions
- RTTI (Run-Time Time Information)
- Standard C++ library
C++ runtimes:
NDK provides different libraries (run-times) with different levels of C++ support:
Application files must all be linked against the same runtime library (mixing is not possible).
The C++ runtime is specified in the (optional) Application.mk makefile.
Static versus shared libraries:
Shared libraries are the preferred mode of library use to conserve space (library not contained
multiple times in different executables) and avoid problems with global library variables.
More details see CPLUSPLUS-SUPPORT.html.
C++ Runtime Library C++ exceptions RTTI Standard C++ library
system libstdc++ No No No
gabi+ libgabi++ No Yes No
stlport libstlport No Yes Yes
gnustl libgnustl Yes Yes Yes
© Peter R. Egli 2015
14/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
9. JNI - Calling native functions from Java code
Java code:
Declaration of native function that is contained in a library.
Native code:
jstring
Java_<path to Java package>_<Java-Class>_<function-name>(JNIEnv* env,
jobject thiz)
{
…
}
where JNIEnv identifies the JNI context of the calling VM and jobject is a reference to
the calling Java object.
© Peter R. Egli 2015
15/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
10. SDK project with native code
1. Build native sources to library with ndk-build
2. Compile Android Java sources with ADT plugin
3. Create Android application package (.apk) with ADT plugin
NDK
toolchain
(ndk-build)
NDK
toolchain
(ndk-build)
.apk
© Peter R. Egli 2015
16/16
Rev. 1.40
Android NDK – Native Development Kit indigoo.com
*.apk package
11. Native activity
Android provides to possibility to implement a completely native activity.
Possible use cases:
a. Games (direct access from native code to graphics)
b. Use of existing application code available in C++
 Native activities are still running in the VM. Thus the lifecycle for normal Android application
still applies.
 Native activities can be started in 2 ways:
Java wrapper
Native
activity in
C/C++
 Small Java Wrapper starts native activity
 Attribute HasCode=true in manifest
Native
activity in
C/C++
*.apk package
 Native activity directly started
 Attribute HasCode=false in manifest

More Related Content

What's hot

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
 
Android NDK and the x86 Platform
Android NDK and the x86 PlatformAndroid NDK and the x86 Platform
Android NDK and the x86 PlatformSebastian Mauer
 
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
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineChun-Yu Wang
 
Android ndk - Introduction
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - IntroductionRakesh Jha
 
Understanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer toolUnderstanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer toolGabor Paller
 
LinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik BytecodeLinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik BytecodeAlain Leon
 
How to reverse engineer Android applications
How to reverse engineer Android applicationsHow to reverse engineer Android applications
How to reverse engineer Android applicationshubx
 
Android Developer Meetup
Android Developer MeetupAndroid Developer Meetup
Android Developer MeetupMedialets
 
Reverse engineering android apps
Reverse engineering android appsReverse engineering android apps
Reverse engineering android appsPranay Airan
 
Jollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen Chen
 
Toward dynamic analysis of obfuscated android malware
Toward dynamic analysis of obfuscated android malwareToward dynamic analysis of obfuscated android malware
Toward dynamic analysis of obfuscated android malwareZongXian Shen
 
ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...
ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...
ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...ZongXian Shen
 
Google ART (Android RunTime)
Google ART (Android RunTime)Google ART (Android RunTime)
Google ART (Android RunTime)Niraj Solanke
 
Hierarchy Viewer Internals
Hierarchy Viewer InternalsHierarchy Viewer Internals
Hierarchy Viewer InternalsKyungmin Lee
 
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android ApplicationsSteelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android ApplicationsTom Keetch
 
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS EngineZongXian Shen
 

What's hot (20)

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 ndk
Android ndkAndroid ndk
Android ndk
 
Android NDK and the x86 Platform
Android NDK and the x86 PlatformAndroid NDK and the x86 Platform
Android NDK and the x86 Platform
 
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
 
Android NDK: Entrando no Mundo Nativo
Android NDK: Entrando no Mundo NativoAndroid NDK: Entrando no Mundo Nativo
Android NDK: Entrando no Mundo Nativo
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machine
 
Android ndk - Introduction
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - Introduction
 
Understanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer toolUnderstanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer tool
 
LinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik BytecodeLinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik Bytecode
 
How to reverse engineer Android applications
How to reverse engineer Android applicationsHow to reverse engineer Android applications
How to reverse engineer Android applications
 
Android Developer Meetup
Android Developer MeetupAndroid Developer Meetup
Android Developer Meetup
 
Reverse Engineering Android Application
Reverse Engineering Android ApplicationReverse Engineering Android Application
Reverse Engineering Android Application
 
Reverse engineering android apps
Reverse engineering android appsReverse engineering android apps
Reverse engineering android apps
 
Jollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-level
 
Toward dynamic analysis of obfuscated android malware
Toward dynamic analysis of obfuscated android malwareToward dynamic analysis of obfuscated android malware
Toward dynamic analysis of obfuscated android malware
 
ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...
ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...
ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...
 
Google ART (Android RunTime)
Google ART (Android RunTime)Google ART (Android RunTime)
Google ART (Android RunTime)
 
Hierarchy Viewer Internals
Hierarchy Viewer InternalsHierarchy Viewer Internals
Hierarchy Viewer Internals
 
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android ApplicationsSteelcon 2015 Reverse-Engineering Obfuscated Android Applications
Steelcon 2015 Reverse-Engineering Obfuscated Android Applications
 
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
 

Similar to Android Native Development Kit

Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDKKirill Kounik
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentIJERD Editor
 
Alternatives to Java for Android development
Alternatives to Java for Android developmentAlternatives to Java for Android development
Alternatives to Java for Android developmentttogrul
 
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ırmaFarhad
 
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ırmaFarhad
 
Alternatives to Java for Android development
Alternatives to Java for Android developmentAlternatives to Java for Android development
Alternatives to Java for Android developmentttogrul
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application DevelopmentRamesh Prasad
 
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
 
Curso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - StackCurso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - StackJackson F. de A. Mafra
 
Enhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_osEnhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_osArnav Gupta
 
lecture-2-android-dev.pdf
lecture-2-android-dev.pdflecture-2-android-dev.pdf
lecture-2-android-dev.pdfjakjak36
 
Cross-compilation native sous android
Cross-compilation native sous androidCross-compilation native sous android
Cross-compilation native sous androidThierry Gayet
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxtakshilkunadia
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application FrameworkYong Heui Cho
 
An Introduction To Android
An Introduction To AndroidAn Introduction To Android
An Introduction To Androidnatdefreitas
 
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...BeMyApp
 

Similar to Android Native Development Kit (20)

Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDK
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and Development
 
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
 
Android ndk
Android ndkAndroid ndk
Android ndk
 
Alternatives to Java for Android development
Alternatives to Java for Android developmentAlternatives to Java for Android development
Alternatives to Java for Android development
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
01 02 - introduction - adroid stack
01  02 - introduction - adroid stack01  02 - introduction - adroid stack
01 02 - introduction - adroid stack
 
Ndk
NdkNdk
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
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
 
Curso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - StackCurso de Desenvolvimento Mobile - Android - Stack
Curso de Desenvolvimento Mobile - Android - Stack
 
Enhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_osEnhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_os
 
lecture-2-android-dev.pdf
lecture-2-android-dev.pdflecture-2-android-dev.pdf
lecture-2-android-dev.pdf
 
Cross-compilation native sous android
Cross-compilation native sous androidCross-compilation native sous android
Cross-compilation native sous android
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptx
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application Framework
 
An Introduction To Android
An Introduction To AndroidAn Introduction To Android
An Introduction To Android
 
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...
[Android Codefest Germany] Adding x86 target to your Android app by Xavier Ha...
 

More from Peter R. Egli

LPWAN Technologies for Internet of Things (IoT) and M2M Scenarios
LPWAN Technologies for Internet of Things (IoT) and M2M ScenariosLPWAN Technologies for Internet of Things (IoT) and M2M Scenarios
LPWAN Technologies for Internet of Things (IoT) and M2M ScenariosPeter R. Egli
 
Data Networking Concepts
Data Networking ConceptsData Networking Concepts
Data Networking ConceptsPeter R. Egli
 
Communication middleware
Communication middlewareCommunication middleware
Communication middlewarePeter R. Egli
 
Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)Peter R. Egli
 
Business Process Model and Notation (BPMN)
Business Process Model and Notation (BPMN)Business Process Model and Notation (BPMN)
Business Process Model and Notation (BPMN)Peter R. Egli
 
Microsoft .NET Platform
Microsoft .NET PlatformMicrosoft .NET Platform
Microsoft .NET PlatformPeter R. Egli
 
Overview of Cloud Computing
Overview of Cloud ComputingOverview of Cloud Computing
Overview of Cloud ComputingPeter R. Egli
 
MQTT - MQ Telemetry Transport for Message Queueing
MQTT - MQ Telemetry Transport for Message QueueingMQTT - MQ Telemetry Transport for Message Queueing
MQTT - MQ Telemetry Transport for Message QueueingPeter R. Egli
 
Enterprise Application Integration Technologies
Enterprise Application Integration TechnologiesEnterprise Application Integration Technologies
Enterprise Application Integration TechnologiesPeter R. Egli
 
Overview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technologyOverview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technologyPeter R. Egli
 
Overview of SCTP (Stream Control Transmission Protocol)
Overview of SCTP (Stream Control Transmission Protocol)Overview of SCTP (Stream Control Transmission Protocol)
Overview of SCTP (Stream Control Transmission Protocol)Peter R. Egli
 
Overview of SCTP (Stream Control Transmission Protocol)
Overview of SCTP (Stream Control Transmission Protocol)Overview of SCTP (Stream Control Transmission Protocol)
Overview of SCTP (Stream Control Transmission Protocol)Peter R. Egli
 
Overview of Spanning Tree Protocol (STP & RSTP)
Overview of Spanning Tree Protocol (STP & RSTP)Overview of Spanning Tree Protocol (STP & RSTP)
Overview of Spanning Tree Protocol (STP & RSTP)Peter R. Egli
 
MSMQ - Microsoft Message Queueing
MSMQ - Microsoft Message QueueingMSMQ - Microsoft Message Queueing
MSMQ - Microsoft Message QueueingPeter R. Egli
 
Common Object Request Broker Architecture - CORBA
Common Object Request Broker Architecture - CORBACommon Object Request Broker Architecture - CORBA
Common Object Request Broker Architecture - CORBAPeter R. Egli
 
Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)Peter R. Egli
 
JMS - Java Messaging Service
JMS - Java Messaging ServiceJMS - Java Messaging Service
JMS - Java Messaging ServicePeter R. Egli
 
Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)Peter R. Egli
 
REST - Representational State Transfer
REST - Representational State TransferREST - Representational State Transfer
REST - Representational State TransferPeter R. Egli
 

More from Peter R. Egli (20)

LPWAN Technologies for Internet of Things (IoT) and M2M Scenarios
LPWAN Technologies for Internet of Things (IoT) and M2M ScenariosLPWAN Technologies for Internet of Things (IoT) and M2M Scenarios
LPWAN Technologies for Internet of Things (IoT) and M2M Scenarios
 
Data Networking Concepts
Data Networking ConceptsData Networking Concepts
Data Networking Concepts
 
Communication middleware
Communication middlewareCommunication middleware
Communication middleware
 
Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)Transaction Processing Monitors (TPM)
Transaction Processing Monitors (TPM)
 
Business Process Model and Notation (BPMN)
Business Process Model and Notation (BPMN)Business Process Model and Notation (BPMN)
Business Process Model and Notation (BPMN)
 
Microsoft .NET Platform
Microsoft .NET PlatformMicrosoft .NET Platform
Microsoft .NET Platform
 
Overview of Cloud Computing
Overview of Cloud ComputingOverview of Cloud Computing
Overview of Cloud Computing
 
MQTT - MQ Telemetry Transport for Message Queueing
MQTT - MQ Telemetry Transport for Message QueueingMQTT - MQ Telemetry Transport for Message Queueing
MQTT - MQ Telemetry Transport for Message Queueing
 
Enterprise Application Integration Technologies
Enterprise Application Integration TechnologiesEnterprise Application Integration Technologies
Enterprise Application Integration Technologies
 
Overview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technologyOverview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technology
 
Overview of SCTP (Stream Control Transmission Protocol)
Overview of SCTP (Stream Control Transmission Protocol)Overview of SCTP (Stream Control Transmission Protocol)
Overview of SCTP (Stream Control Transmission Protocol)
 
Overview of SCTP (Stream Control Transmission Protocol)
Overview of SCTP (Stream Control Transmission Protocol)Overview of SCTP (Stream Control Transmission Protocol)
Overview of SCTP (Stream Control Transmission Protocol)
 
Web services
Web servicesWeb services
Web services
 
Overview of Spanning Tree Protocol (STP & RSTP)
Overview of Spanning Tree Protocol (STP & RSTP)Overview of Spanning Tree Protocol (STP & RSTP)
Overview of Spanning Tree Protocol (STP & RSTP)
 
MSMQ - Microsoft Message Queueing
MSMQ - Microsoft Message QueueingMSMQ - Microsoft Message Queueing
MSMQ - Microsoft Message Queueing
 
Common Object Request Broker Architecture - CORBA
Common Object Request Broker Architecture - CORBACommon Object Request Broker Architecture - CORBA
Common Object Request Broker Architecture - CORBA
 
Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)
 
JMS - Java Messaging Service
JMS - Java Messaging ServiceJMS - Java Messaging Service
JMS - Java Messaging Service
 
Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)Web Services (SOAP, WSDL, UDDI)
Web Services (SOAP, WSDL, UDDI)
 
REST - Representational State Transfer
REST - Representational State TransferREST - Representational State Transfer
REST - Representational State Transfer
 

Recently uploaded

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
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...Jeffrey Haguewood
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
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 AmsterdamUiPathCommunity
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
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, ...Angeliki Cooney
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
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...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
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
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
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, ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

Android Native Development Kit

  • 1. © Peter R. Egli 2015 1/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com Peter R. Egli INDIGOO.COM OVERVIEW OF THE ANDROID NATIVE DEVELOPMENT KIT ANDROID NDK
  • 2. © Peter R. Egli 2015 2/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com Contents 1. What you can do with NDK 2. When to use native code 3. Stable APIs to use / available libraries 4. Build native applications with NDK 5. NDK contents and structure 6. NDK cross-compiler suite 7. Android EABI 8. NDK C++ support 9. JNI - Calling native functions from Java code 10. SDK project with native code 11. Native activity
  • 3. © Peter R. Egli 2015 3/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com 1. What you can do with NDK • Build native libraries that are callable from Android Java application code (JNI). • Build executables (non-recommended use of NDK). • Debug native program (with gdb). Android Java application Native library (*.so) JNI Dalvik VM Recommended use of native functions: An Android Java application makes native calls through JNI. Thus the entire application running in the VM is subject to the defined Android application lifecycle. It is possible to run entirely native applications on Android. However, it is recommended to use a small Java wrapper for managing the lifecycle of the application (start, stop). Android application (*.apk) Stable native libraries (libc, libm, liblog …)
  • 4. © Peter R. Egli 2015 4/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com 2. When to use native code The power of Android lies in the rich Java application framework to be used by Android applications written in Java. In special cases, however, it may be required to write native code that directly runs on the CPU without the Android VM interpreter. NDK is a toolkit for writing and integrating native code with Java application code. Native code characteristics for use in Android: • Graphically and computationally intensive (e.g. complex algorithms) • Few library dependencies (restricted to stable Android libraries provided by NDK) • Little interaction between Java application code and native code (ideally, the Java application calls computationally intensive native functions and receives the result; there should not be frequent calls and callbacks between Java and native code) Primary uses of NDK: NDK should be used to build native libraries (shared objects) that are called by an Android application. Entirely native applications without Java code are possible starting from Android 2.3 (Gingerbread) by using NativeActivity. Non-recommeded uses of NDK: Custom native applications that run outside the VM.
  • 5. © Peter R. Egli 2015 5/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com 3. Stable APIs to use / available libraries The Android NDK contains a small number of stable libraries that are guaranteed to be contained in successive Android versions. It is recommended that native code only make use of these stable libraries. If native code uses non-stable libraries, the native application may break upon an Android update. android-3 android-4 android-5 android-6 android-7 android-8 android-9 android-14 Library Description Android 1.5 Android 1.6 Android 2.0 Android 2.2 Android 2.3 Android 4.0 crtbegin_dynamic.o Calls of global object ctors Yes Yes Yes Yes Yes Yes crtbegin_so.o Calls of global object ctors Yes Yes Yes Yes Yes Yes crtbegin_static.o Calls of global object ctors Yes Yes Yes Yes Yes Yes crtend_android.o Calls of global object dtors Yes Yes Yes Yes Yes Yes crtend_so.o Calls of global object dtors Yes Yes Yes Yes Yes Yes libandroid.so Functions for access to Java platform from native code No No No No Yes Yes libc.so Standard C library (bionic) Yes Yes Yes Yes Yes Yes libdl.so Dynamic linker library Yes Yes Yes Yes Yes Yes libEGL.so Interface library for low level graphics buffer access No No No No Yes Yes libGLESv1_CM.so Open GL graphics library No Yes Yes Yes Yes Yes libGLESv2.so Open GL graphics library No No Yes Yes Yes Yes libjnigraphics.so C-function-based library for graphics pixel access No No No Yes Yes Yes liblog.so Android logging library Yes Yes Yes Yes Yes Yes libm.so Math library Yes Yes Yes Yes Yes Yes libOpenMAXAL.so Audio and video streaming library No No No No No Yes libOpenSLES.so Audio streaming library No No No No Yes Yes libstdc++.so Minimal C++ library (no exceptions, no RTTI) Yes Yes Yes Yes Yes Yes libthread_db.so Thread debug support library. Yes Yes Yes Yes Yes Yes
  • 6. © Peter R. Egli 2015 6/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com 4. Build native applications with NDK The NDK build system is made for creating .a (static libs) and .so (shared libs). The shell script <NDK-base>/ndk-build creates the library output. With some minimal effort it is possible to create fully native applications: ndk-build C/C++ source NDK arm-eabi-gcc NDK arm-eabi-ld NDK Prebuilt libraries .o .a .so C/C++ source (main) Native executable
  • 7. © Peter R. Egli 2015 7/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com 5. NDK contents and structure (1/2) NDK installation simply requires unzipping it to a suitable location. NDK contains a cross-toolchain for ARM and x86 based CPUs, header files and stable libraries. NDK R7 structure: Build scripts (makefiles, awk scripts etc.) Documentation (HTML) Platforms (header files and stable libraries) Build executables (make, awk, sed, echo) Samples (hello world, JNI example etc.) Source files that can be linked to an application or library Test scripts for automated tests of the NDK ARM Linux and x86 toolchains (compiler, linker etc.) Documentation entry point Makefile for building NDK Build script for building a native application or library Experimental Windows native build script (working?) GDB debug start script Stack trace analysis tool Readme file NDK release identifier (contents for R7: r7d)
  • 8. © Peter R. Egli 2015 8/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com 5. NDK contents and structure (2/2) The platforms sub-folder contains stable header files and libraries. Android API-level 9 (Android 2.3) ARMv7 CPU architecture header files and libs ('sysroot') Stable Android API header files and libraries C++ headers and libraries are under <NDK-base>/sources/cxx-stl.
  • 9. © Peter R. Egli 2015 9/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com 6. NDK cross-compiler suite (1/3) Standard naming convention for cross-compilers: <arch>-<vendor>-(os)-<abi> Example: arm-linux-androideabi-c++.exe  Architecture (CPU): ARM  Vendor: None  OS: Linux  ABI: Android EABI (see below) NDK toolchains: NDK contains GNU-based cross-compile tools for ARM7 and x86 CPUs. The NDK toolchain can be used for: a. NDK integrated toolchain for building shared libraries for use in an Android application b. Standalone toolchain that is invoked by a custom build
  • 10. © Peter R. Egli 2015 10/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com 6. NDK cross-compiler suite (2/3) a. NDK integrated toolchain: Location: <NDK-base>/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows (likewise for x86 toolchain). The NDK integrated toolchain uses the scripts, header files and library files that are part of the NDK installation. NDK toolchain (ndk-build)
  • 11. © Peter R. Egli 2015 11/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com 6. NDK cross-compiler suite (3/3) Standalone toolchain: The NDK standalone toolchain is useful for situations where another build system, e.g. as part of an open source package, needs to invoke a cross-compiler for building. In the standalone toolchain, everything that is needed for building (compilers etc., header files, library files) is contained in a single location. How to create standalone-toolchain: 1. Start bash shell (on Windows start cygwin shell as administrator) 2. Run the make standalone toolchain command: /cygdrive/c/install/Android-NDK/android-ndk-r7b/build/tools/make- standalone-toolchain.sh --platform=android-9 --install- dir=/cygdrive/c/temp/android-standalone-toolchain/ How to invoke the standalone-toolchain: SET PATH=c:tempandroid-standalone-toolchain;%PATH% SET CC=arm-linux-androideabi-gcc.exe %CC% -o foo.o –c foo.c
  • 12. © Peter R. Egli 2015 12/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com 7. Android EABI What is an ABI? ABI (Application Binary Interface) defines how an application interacts with the underlying system at run-time. An ABI is a low-level interface definition that comprises the following: - CPU instruction set to use - Endianness of memory load and store operations - Format of executable binaries (programs, libraries) - Function call conventions (stack framing when functions are called, argument passing) - Alignment of structs and struct fields, enums The goal of an ABI is binary compatibility between executables (e.g. program calling a library function). An EABI (Embedded ABI) defines an ABI for embedded targets. Android EABI: Android EABI is basically identical to the Linux (GNU) EABI with the difference of the C-library (bionic C-library instead of GNU C-library). Android provides 3 EABIs: a. armeabi (ARMv5TE instruction set, thumb mode) b. armeabi-v7a (Thumb-2 instruction set extensions, hardware floating point support) c. x86 (IA-32 based instruction set) For more details see <NDK-base>/docs/CPU-ARCH-ABIS.html
  • 13. © Peter R. Egli 2015 13/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com 8. NDK C++ support NDK provides some basic C++ runtime support through the default /system/lib/libstdc++ library. The following C++ features are not supported: - C++ exceptions - RTTI (Run-Time Time Information) - Standard C++ library C++ runtimes: NDK provides different libraries (run-times) with different levels of C++ support: Application files must all be linked against the same runtime library (mixing is not possible). The C++ runtime is specified in the (optional) Application.mk makefile. Static versus shared libraries: Shared libraries are the preferred mode of library use to conserve space (library not contained multiple times in different executables) and avoid problems with global library variables. More details see CPLUSPLUS-SUPPORT.html. C++ Runtime Library C++ exceptions RTTI Standard C++ library system libstdc++ No No No gabi+ libgabi++ No Yes No stlport libstlport No Yes Yes gnustl libgnustl Yes Yes Yes
  • 14. © Peter R. Egli 2015 14/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com 9. JNI - Calling native functions from Java code Java code: Declaration of native function that is contained in a library. Native code: jstring Java_<path to Java package>_<Java-Class>_<function-name>(JNIEnv* env, jobject thiz) { … } where JNIEnv identifies the JNI context of the calling VM and jobject is a reference to the calling Java object.
  • 15. © Peter R. Egli 2015 15/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com 10. SDK project with native code 1. Build native sources to library with ndk-build 2. Compile Android Java sources with ADT plugin 3. Create Android application package (.apk) with ADT plugin NDK toolchain (ndk-build) NDK toolchain (ndk-build) .apk
  • 16. © Peter R. Egli 2015 16/16 Rev. 1.40 Android NDK – Native Development Kit indigoo.com *.apk package 11. Native activity Android provides to possibility to implement a completely native activity. Possible use cases: a. Games (direct access from native code to graphics) b. Use of existing application code available in C++  Native activities are still running in the VM. Thus the lifecycle for normal Android application still applies.  Native activities can be started in 2 ways: Java wrapper Native activity in C/C++  Small Java Wrapper starts native activity  Attribute HasCode=true in manifest Native activity in C/C++ *.apk package  Native activity directly started  Attribute HasCode=false in manifest