Android NDK Native Development Kit



Similar documents
Introduction to Native Android Development with NDK

Development_Setting. Step I: Create an Android Project

Native code in Android Quad Detection

A Study on Android development kits and the Phone Gap Framework

How To Develop Android On Your Computer Or Tablet Or Phone

Building graphic-rich and better performing native applications. Pro. Android C++ with the NDK. Onur Cinar

OpenCV on Android Platforms

The Decaffeinated Robot

Running a Program on an AVD

ANDROID DEVELOPER TOOLS TRAINING GTC Sébastien Dominé, NVIDIA

10 STEPS TO YOUR FIRST QNX PROGRAM. QUICKSTART GUIDE Second Edition

TEGRA X1 DEVELOPER TOOLS SEBASTIEN DOMINE, SR. DIRECTOR SW ENGINEERING

AllJoyn Android Environment Setup Guide

An Introduction to Android

Android Basics. Xin Yang

Multithreading and Java Native Interface (JNI)!

GETTING STARTED WITH ANDROID DEVELOPMENT FOR EMBEDDED SYSTEMS

Università Degli Studi di Parma. Distributed Systems Group. Android Development. Lecture 1 Android SDK & Development Environment. Marco Picone

l What is Android? l Getting Started l The Emulator l Hello World l ADB l Text to Speech l Other APIs (camera, bitmap, etc)

Table of Contents. Adding Build Targets to the SDK 8 The Android Developer Tools (ADT) Plug-in for Eclipse 9

Apache Jakarta Tomcat

Android Programming and Security

Easing embedded Linux software development for SBCs

NVIDIA Tegra Android Platform Support Pack Getting Started Guide

Lecture 1 Introduction to Android

How To Develop For A Powergen 2.2 (Tegra) With Nsight) And Gbd (Gbd) On A Quadriplegic (Powergen) Powergen Powergen 3

Graduate presentation for CSCI By Janakiram Vantipalli ( Janakiram.vantipalli@colorado.edu )

Q N X S O F T W A R E D E V E L O P M E N T P L A T F O R M v Steps to Developing a QNX Program Quickstart Guide

Android Malware for Pen-testing. IOAsis San Fransicso 2014

Android: How To. Thanks. Aman Nijhawan

Intel Integrated Native Developer Experience (INDE): IDE Integration for Android*

Writing standalone Qt & Python applications for Android

Overview. The Android operating system is like a cake consisting of various layers.

Example of Standard API

Android Development. Lecture AD 0 Android SDK & Development Environment. Università degli Studi di Parma. Mobile Application Development

What else can you do with Android? Inside Android. Chris Simmonds. Embedded Linux Conference Europe Copyright 2010, 2net Limited.

Android Architecture. Alexandra Harrison & Jake Saxton

RTI Connext DDS. Core Libraries Getting Started Guide Addendum for Android Systems Version 5.2.0

Mobility Introduction Android. Duration 16 Working days Start Date 1 st Oct 2013

ANDROID PROGRAMMING - INTRODUCTION. Roberto Beraldi

System Reference 2013

Integrating TAU With Eclipse: A Performance Analysis System in an Integrated Development Environment

The "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.

Overview. Open source toolchains. Buildroot features. Development process

Introduction to Android

STLinux Software development environment

An Introduction to Android Application Development. Serdar Akın, Haluk Tüfekçi

Reminders. Lab opens from today. Many students want to use the extra I/O pins on

Eddy Integrated Development Environment, LemonIDE for Embedded Software System Development

An Introduction to Android. Huang Xuguang Database Lab. Inha University

Publishing to TIZEN Using the Automated Conversion/Repackaging of Existing Android Apps. Hyeokgon Ryu, Infraware Technology, Ltd.

NVIDIA CUDA GETTING STARTED GUIDE FOR MAC OS X

BogDan Vatra and Andy Gryc. Qt on Android: Is it right for you?

Android Development: a System Perspective. Javier Orensanz

Using Intel C++ Compiler in Eclipse* for Embedded Linux* targets

Introduction to Android Development. Jeff Avery CS349, Mar 2013

Introduction to Android

OMX, Android, GStreamer How do I decide what to use? 15 July 2011

Hacking your Droid ADITYA GUPTA

ANDROID BASED MOBILE APPLICATION DEVELOPMENT and its SECURITY

Running Android Applications on BlackBerry 10 developer.blackberry.com/android

Overview of CS 282 & Android

Tutorial on Basic Android Setup

Android 4.4 App Development Essentials

Red Hat Developer Toolset 1.1

Instrumentation Software Profiling

Xeon Phi Application Development on Windows OS

Developing multi-platform mobile applications: doing it right. Mihail Ivanchev

Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department. Mobile Computing ECOM Eng. Wafaa Audah.

Embedded Linux Platform Developer

Android Hands-On Labs

ITG Software Engineering

Research and Design of Universal and Open Software Development Platform for Digital Home

Android Development. Marc Mc Loughlin

WebView addjavascriptinterface Remote Code Execution 23/09/2013

Android Geek Night. Application framework

Virtualization and Other Tricks.

An Android based Quantum GIS prototype. Ramon Carrillo, Daniel Ochoa

RISC-V Software Ecosystem. Andrew Waterman UC Berkeley

Intel Application Software Development Tool Suite 2.2 for Intel Atom processor. In-Depth

Fahim Uddin 1. Java SDK

The installation of pylon for Linux is described in the INSTALL text document.

Smartphone market share

IOTIVITY AND EMBEDDED LINUX SUPPORT. Kishen Maloor Intel Open Source Technology Center

Mobile Devices - An Introduction to the Android Operating Environment. Design, Architecture, and Performance Implications

ARM-BASED PERFORMANCE MONITORING FOR THE ECLIPSE PLATFORM

Mobile Phones Operating Systems

ReactOS is (not) Windows. Windows internals and why ReactOS couldn t just use a Linux kernel

ODROID Multithreading in Android

System Structures. Services Interface Structure

RED HAT DEVELOPER TOOLSET Build, Run, & Analyze Applications On Multiple Versions of Red Hat Enterprise Linux

imaginea white paper

Android Development: Part One

Android and OpenCV Tutorial

Analysis of advanced issues in mobile security in android operating system

The Embedded Linux Quick Start Guide In the Beginning... Embedded Linux Conference Europe 2010

Jordan Jozwiak November 13, 2011

VM Application Debugging via JTAG: Android TRACE32 JTAG Debug Bridge ADB Architecture Stop-Mode implications for ADB JTAG Transport Outlook

Технологии Java. Android: Введение. Кузнецов Андрей Николаевич. Санкт-Петербургский Государственный Политехнический Университет

Building Applications Using Micro Focus COBOL

Transcription:

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 1

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). Dalvik VM Android application (*.apk) Android Java application JNI Native library (*.so) 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). Stable native libraries (libc, libm, liblog ) 2

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. 3

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 4

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: C/C++ source ndk-build.o.a.so NDK arm-eabi-ld Native executable C/C++ source (main) NDK arm-eabi-gcc NDK Prebuilt libraries 5

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) 6

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. 7

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 8

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) 9

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/makestandalone-toolchain.sh --platform=android-9 --installdir=/cygdrive/c/temp/android-standalone-toolchain/ How to invoke the standalone-toolchain: SET PATH=c:\temp\android-standalone-toolchain;%PATH% SET CC=arm-linux-androideabi-gcc.exe %CC% -o foo.o c foo.c 10

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 11

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: 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 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. 12

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. 13

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 14

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: Small Java Wrapper starts native activity Attribute HasCode=true in manifest Native activity directly started Attribute HasCode=false in manifest Java wrapper Native activity in C/C++ *.apk package Native activity in C/C++ *.apk package 15