SlideShare une entreprise Scribd logo
1  sur  37
Télécharger pour lire hors ligne
Getting Native with NDK
About Marko Gargenta 
Marko Gargenta 
Entrepreneur, Author, Speaker 
Developer of Android Bootcamp for Marakana. 
Instructor for 1,000s of developers on Android at Qualcomm, Cisco, Motorola, Intel, DoD and other great orgs. 
Author of Learning Android published by O’Reilly. 
Speaker at OSCON (4x), ACM, IEEE(2x), SDC(2x), AnDevCon(3x), DroidCon. 
Co-Founder of SFAndroid.org 
Co-Chair of Android Open conference: Android Open
Objectives of NDK Module 
Android is put together of about equal part Java and C. So, no wonder that we need an easy 
way to bridge between these two totally different worlds. Java offers Java Native Interface 
(JNI) as a framework connecting the world of Java to the native code. Android goes a step 
further by packaging other useful tools and libraries into a Native Development Kit, or NDK. 
NDK makes developing C/C++ code that works with an Android app much simpler than if one 
was to do it by hand. Topics covered include: 
What is in NDK? 
Why NDK? 
Java Native Interface (JNI) 
Using NDK 
NDK and JNI by Example 
NDK’s Stable APIs 
Lab: NDK
NDK in Action 
Using NDK to connect Activity to native code
Dalvik Runs Native
What is in NDK? 
NDK is a toolchain 
Cross-compiler, linker, what you need to build for ARM, x86, MIPS, etc. 
NDK provides a way to bundle lib.so into your APK 
The native library needs to be loadable in a secure way. 
NDK "standardizes" various native platforms 
It provides headers for lliibbcc, lliibbmm, lliibbzz, lliibblloogg, lliibbjjnniiggrraahhiiccss, OpenGL/OpenSL ES, 
JNI headers, minimal C++ support headers, and Android native app APIs. 
NDK comes with docs and samples 
Helps you get up to speed with native development. 
Android’s Dalvik VM allows our applications written in Java to call methods implemented in native code 
through the Java Native Interface (JNI) 
For example: 
package com.marakana.android.fetchurl; 
public class FetchUrl { 
public static native byte[] fetch(String url); 
static { 
System.loadLibrary("fetchurl"); 
} 
} 
NDK is a tool-chain to build and cross-compile our native code for the device-specific architecture 
At the moment, NDK supports ARMv5TE, ARMv7-A, x86 (since r6), and mips (since r8) ABIs 
For example, we would implement native ffeettcchh method in C and compile it into a library 
lliibbffeettcchhuurrll..ssoo 
NDK offers a way to package our native code library (as lliibb<<ssoommeetthhiinngg>>..ssoo) into the APK file so we can 
distribute it with our application easily 
For example, our library would be packaged as lliibbss//aarrmmeeaabbii//lliibbffeettcchhuurrll..ssoo in the APK 
NDK provides a set of native system headers that will be supported for the future releases of Android platform 
(lliibbcc, lliibbmm, lliibbzz, lliibblloogg, lliibbjjnniiggrraahhiiccss, OpenGL/OpenSL ES, JNI headers, minimal C++ support 
headers, and Android native app APIs) 
NDK comes with extensive documentation, sample code, and examples 
As of ADT r20, NDK also adds a plugin to ADT that enables debugging NDK projects in Eclipse and requires:
CDT (v7.0.2 or 8.0.2) for Eclipse from http://download.eclipse.org/tools/cdt/releases/indigo 
ADT (r20) with SDK/NDK plugins for Eclipse from https://dl-ssl.google.com/android/eclipse/ with 
SDK/NDK paths configured 
Before an Eclipse project app can be debugged, it must have: 
native support (project properties → Android Tools → Add native support) enabled 
NNDDKK__DDEEBBUUGG==11 (project properties → C/C++ Build → Build Command → nnddkk--bbuuiilldd NNDDKK__DDEEBBUUGG==11) 
set 
To debug an Eclipse project app: 
Set the break point(s) as desired 
Select project → Run → Debug As → Android Native Application
Why NDK? 
For performance 
Sometimes, native code still runs faster. 
For legacy support 
You may have that C/C++ code you’d like to use in your app. 
For access to low-level libraries 
In a rare case when there is no Java API to do something. 
For cross-platform development 
C is the new portable language. 
But 
Adding JNI to your app will make it more complex. 
Plus 
Java often offers much richer APIs, memory protection, OOP, productivity. 
NDK allows us to develop parts of our Android application in C/C++ 
Generally, we do not develop native-only apps via NDK 
Android’s Gingerbread (2.3) release supports NNaattiivveeAAccttiivviittyy, which allows handling lifecycle 
callbacks in native code, so we can now develop native-only apps, 
No support for native services, broadcast receivers, content providers, etc. 
NDK code still subject to security sandboxing - we don’t get extra permissions for running natively 
Main motivation for native code is performance (CPU-intensive, self-contained, low-memory footprint code) 
and the re-use of legacy code 
For system integrators, NDK offers access to low-level libraries (e.g. access to user-space HAL) 
Using NDK always increases complexity of applications, so it should only be used when it’s essential to 
the application 
Programming in Java offers richer APIs, memory protection and management, higher-level language 
constructs (OOP), all of which generally results in higher productivity
Using NDK with C 
NDK Process Using C
Using NDK with C++ 
NDK Process Using C++
NDK and JNI by Example 
NDK is best explained via an example (based on Fibonacci) 
The code is available 
As a ZIP archive: https://github.com/marakana/FibonacciNative/zipball/master 
By Git: ggiitt cclloonnee https://github.com/marakana/FibonacciNative.git 
Start by creating a new Android Project 
Project Name: FibonacciNative 
Build Target: Android 2.2 (API 8) or later 
Application Name: Fibonacci Native 
Package: ccoomm..mmaarraakkaannaa..aannddrrooiidd..ffiibboonnaacccciinnaattiivvee 
Create Activity: FFiibboonnaacccciiAAccttiivviittyy
Fibonacci - Java Native Function Prototypes 
We start off by defining C function prototypes as nnaattiivvee Java methods (wrapped in some 
class): 
FFiibboonnaacccciiNNaattiivvee//ssrrcc//ccoomm//mmaarraakkaannaa//aannddrrooiidd//ffiibboonnaacccciinnaattiivvee//FFiibbLLiibb..jjaavvaa
package com.marakana.android.fibonaccinative; 
import android.util.Log; 
public class FibLib { 
private static final String TAG = "FibLib"; 
private static long fib(long n) { 
return n <= 0 ? 0 : n == 1 ? 1 : fib(n - 1) + fib(n - 2); 
} 
// Recursive Java implementation of the Fibonacci algorithm 
// (included for comparison only) 
public static long fibJR(long n) { 
Log.d(TAG, "fibJR(" + n + ")"); 
return fib(n); 
} 
// Function prototype for future native recursive implementation 
// of the Fibonacci algorithm 
public native static long fibNR(long n); 
// Iterative Java implementation of the Fibonacci algorithm 
// (included for comparison only) 
public static long fibJI(long n) { 
Log.d(TAG, "fibJI(" + n + ")"); 
long previous = -1; 
long result = 1; 
for (long i = 0; i <= n; i++) { 
long sum = result + previous; 
previous = result; 
result = sum; 
} 
return result; 
} 
// Function prototype for future iterative recursive implementation 
// of the Fibonacci algorithm 
public native static long fibNI(long n); 
static { 
// as defined by LOCAL_MODULE in Android.mk 
System.loadLibrary("com_marakana_android_fibonaccinative_FibLib"); 
} 
}
Fibonacci - Function Prototypes in a C Header File 
We then extract our C header file with our function prototypes: 
1. On the command line, change to your project’s root directory 
$ cd /path/to/workspace/FibonacciNative 
2. Create jjnnii sub-directory 
3. Extract the C header file from ccoomm..mmaarraakkaannaa..aannddrrooiidd..ffiibboonnaacccciinnaattiivvee..FFiibbLLiibb 
class: 
Prior to ADT r14, compiled class files were kept directly in the bbiinn// directory, so in our jjaavvaahh command 
we would’ve used --ccllaassssppaatthh bbiinn instead. 
4. Check out the resulting file: 
FFiibboonnaacccciiNNaattiivvee//jjnnii//ccoomm__mmaarraakkaannaa__aannddrrooiidd__ffiibboonnaacccciinnaattiivvee__FFiibbLLiibb..hh 
$ mkdir jni 
$ javah -jni -classpath bin/classes -d jni com.marakana.android.fibonaccinative.FibLib
/* DO NOT EDIT THIS FILE - it is machine generated */ 
#include <jni.h> 
/* Header for class com_marakana_android_fibonaccinative_FibLib */ 
#ifndef _Included_com_marakana_android_fibonaccinative_FibLib 
#define _Included_com_marakana_android_fibonaccinative_FibLib 
#ifdef __cplusplus 
extern "C" { 
#endif 
/* 
* Class: com_marakana_android_fibonaccinative_FibLib 
* Method: fibNR 
* Signature: (J)J 
*/ 
JNIEXPORT jlong JNICALL Java_com_marakana_android_fibonaccinative_FibLib_fibNR 
(JNIEnv *, jclass, jlong); 
/* 
* Class: com_marakana_android_fibonaccinative_FibLib 
* Method: fibNI 
* Signature: (J)J 
*/ 
JNIEXPORT jlong JNICALL Java_com_marakana_android_fibonaccinative_FibLib_fibNI 
(JNIEnv *, jclass, jlong); 
#ifdef __cplusplus 
} #endif 
#endif 
The function prototype names are name-spaced to the classname they are found in.
Fibonacci - Provide C Implementation 
We provide the C implementation of com_marakana_android_ffiibboonnaaccccii__FFiibbLLiibb..hh 
header file: 
FFiibboonnaacccciiNNaattiivvee//jjnnii//ccoomm__mmaarraakkaannaa__aannddrrooiidd__ffiibboonnaacccciinnaattiivvee__FFiibbLLiibb..cc 
/* Include the header file that was created via "javah -jni" command */ 
#include "com_marakana_android_fibonaccinative_FibLib.h" 
#include <android/log.h> 
/* Recursive implementation of the fibonacci algorithm (in a helper function) */ 
static jlong fib(jlong n) { 
return n <= 0 ? 0 : n == 1 ? 1 : fib(n - 1) + fib(n - 2); 
} 
/* Actual implementation of JNI-defined `fibNR` (recursive) function */ 
JNIEXPORT jlong JNICALL Java_com_marakana_android_fibonaccinative_FibLib_fibNR 
(JNIEnv *env, jclass clazz, jlong n) { 
__android_log_print(ANDROID_LOG_DEBUG, "FibLib.c", "fibNR(%lld)", n); 
return fib(n); 
} 
/* Actual implementation of JNI-defined `fibNI` (iterative) function */ 
JNIEXPORT jlong JNICALL Java_com_marakana_android_fibonaccinative_FibLib_fibNI 
(JNIEnv *env, jclass clazz, jlong n) { 
jlong previous = -1; 
jlong result = 1; 
jlong i; 
__android_log_print(ANDROID_LOG_DEBUG, "FibLib.c", "fibNI(%lld)", n); 
for (i = 0; i <= n; i++) { 
jlong sum = result + previous; 
previous = result; 
result = sum; 
} 
return result; 
}
Fibonacci - An Alternative Implementation (C++) 
We could also use an alternative mechanism of linking native-code to managed code by pre-registering 
our functions. This leads to earlier detection of method-function mismatch issues, 
a slight performance improvement, and spares us the redundancy of the header file and the 
use of the jjaavvaahh command. 
See Registering Native Methods and JNI_OnLoad 
FFiibboonnaacccciiNNaattiivvee//jjnnii//ccoomm__mmaarraakkaannaa__aannddrrooiidd__ffiibboonnaacccciinnaattiivvee__FFiibbLLiibb..ccpppp
#include <jni.h> 
#include <android/log.h> 
namespace com_marakana_android_fibonaccinative { 
static jlong fib(jlong n) { 
return n <= 0 ? 0 : n == 1 ? 1 : fib(n - 1) + fib(n - 2); 
} 
static jlong fibNR(JNIEnv *env, jclass clazz, jlong n) { 
__android_log_print(ANDROID_LOG_DEBUG, "FibLib.c", "fibNR(%lld)", n); 
return fib(n); 
} 
static jlong fibNI(JNIEnv *env, jclass clazz, jlong n) { 
jlong previous = -1; 
jlong result = 1; 
jlong i; 
__android_log_print(ANDROID_LOG_DEBUG, "FibLib.c", "fibNI(%lld)", n); 
for (i = 0; i <= n; i++) { 
jlong sum = result + previous; 
previous = result; 
result = sum; 
} 
return result; 
} 
static JNINativeMethod method_table[] = { 
{ "fibNR", "(J)J", (void *) fibNR }, 
{ "fibNI", "(J)J", (void *) fibNI } 
}; 
} 
using namespace com_marakana_android_fibonaccinative; 
extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) { 
JNIEnv* env; 
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { 
return JNI_ERR; 
} else { 
jclass clazz = env->FindClass("com/marakana/android/fibonaccinative/FibLib"); 
if (clazz) { 
jint ret = env->RegisterNatives(clazz, method_table, sizeof(method_table) / 
sizeof(method_table[0])); 
env->DeleteLocalRef(clazz); 
return ret == 0 ? JNI_VERSION_1_6 : JNI_ERR; 
} else { 
return JNI_ERR; 
} 
} 
} 
Most of the Android’s JNI-based shared libraries are built using this, "alternative", approach where the 
functions are pre-registered.
Fibonacci - Makefile 
We need a AAnnddrrooiidd..mmkk makefile, which will be used by NDK to compile our JNI code into a 
shared library: 
FFiibboonnaacccciiNNaattiivvee//jjnnii//AAnnddrrooiidd..mmkk 
# Defines the root to all other relative paths 
# The macro function my-dir, provided by the build system, 
# specifies the path of the current directory (i.e. the 
# directory containing the Android.mk file itself) 
LOCAL_PATH := $(call my-dir) 
# Clear all LOCAL_XXX variables with the exception of 
# LOCAL_PATH (this is needed because all variables are global) 
include $(CLEAR_VARS) 
# List all of our C files to be compiled (header file 
# dependencies are automatically computed) 
LOCAL_SRC_FILES := com_marakana_android_fibonaccinative_FibLib.c 
# The name of our shared module (this name will be prepended 
# by lib and postfixed by .so) 
LOCAL_MODULE := com_marakana_android_fibonaccinative_FibLib 
# We need to tell the linker about our use of the liblog.so 
LOCAL_LDLIBS += -llog 
# Collects all LOCAL_XXX variables since "include $(CLEAR_VARS)" 
# and determines what to build (in this case a shared library) 
include $(BUILD_SHARED_LIBRARY) 
It’s easiest to copy the AAnnddrrooiidd..mmkk file from another (sample) project and adjust LLOOCCAALL__SSRRCC__FFIILLEESS and 
LLOOCCAALL__MMOODDUULLEE as necessary 
See //ppaatthh//ttoo//nnddkk--iinnssttaallllaattiioonn--ddiirr//ddooccss//AANNDDRROOIIDD--MMKK..hhttmmll for the complete reference of 
Android make files (build system)
Fibonacci - Compile Our Shared Module 
Finally, from the root of our project (i.e. FFiibboonnaacccciiNNaattiivvee//), we run nnddkk--bbuuiilldd to build 
our code into a shared library 
(FFiibboonnaacccciiNNaattiivvee//lliibbss//aarrmmeeaabbii//lliibbccoomm__mmaarraakkaannaa__aannddrrooiidd__ffiibboonnaaccccii__FFiibbLLiibb..$ ndk-build 
Compile thumb : com_marakana_android_fibonaccinative_FibLib <= 
com_marakana_android_fibonaccinative_FibLib.c 
SharedLibrary : libcom_marakana_android_fibonaccinative_FibLib.so 
Install : libcom_marakana_android_fibonaccinative_FibLib.so => 
libs/armeabi/libcom_marakana_android_fibonaccinative_FibLib.so 
The command nnddkk--bbuuiilldd comes from the NDK’s installation directory (e.g. //ppaatthh//ttoo//aannddrrooiidd--nnddkk--rr55bb), 
so it’s easiest if we add this directory to our PPAATTHH. 
On Windows, older version of NDK required Cygwin (a Unix-like environment and command-line interface for 
Microsoft Windows) to provide "shell" (bash) and "make" (gmake) to nnddkk--bbuuiilldd. 
Controlling CPU Application Binary Interface (ABI) 
By default, the NDK will generate machine code for the aarrmmeeaabbii - i.e. ARMv5TE with 
support for Thumb-1. 
In addition to ARMv5, NDK also comes with the toolchains necessary to build code for: 
ARMv7-A (including hardware FPU/VFPv3-D16, Thumb-2, VFPv3-D32/ThumbEE, and SIMD/NEON) 
x86 (as of r6) 
MIPS (as of r8) 
We can explicitly select ABIs using AAPPPP__AABBII variable: 
$ ndk-build APP_ABI=armeabi 
$ ndk-build APP_ABI=armeabi-v7a 
$ ndk-build APP_ABI=x86 
$ ndk-build APP_ABI=mips 
We can also combine them, thereby building a "fat binary": 
$ ndk-build "APP_ABI=armeabi armeabi-v7a x86 mips" 
$ ndk-build APP_ABI=all 
Finally, we can also persist our choice of ABI, by saving AAPPPP__AABBII in a AApppplliiccaattiioonn..mmkk file: 
jjnnii//AApppplliiccaattiioonn..mmkk: 
APP_ABI := all 
Each ABI-specific library, gets packaged as lliibb//<<AABBII>>//lliibb<<nnaammee>>..ssoo inside our APK.
Upon installation, the library that best matches the native ABI of the device it will execute 
on, will get copied to /data/data/<package>/lliibb//lliibb<<nnaammee>>..ssoo. 
To remove all generated binaries, run: 
$ ndk-build clean 
Clean: com_marakana_android_fibonaccinative_FibLib [armeabi] 
Clean: stdc++ [armeabi]
Fibonacci - Client 
We can now build the "client" of our library (in this case a simple activity) to use our FFiibbLLiibb 
library. 
Fibonacci - String Resources 
FFiibboonnaacccciiNNaattiivvee//rreess//vvaalluueess//ssttrriinnggss..xxmmll 
<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<string name="hello">Get Your Fibonacci Numbers Here!</string> 
<string name="fibJR">fibJR</string> 
<string name="fibJI">fibJI</string> 
<string name="fibNR">fibNR</string> 
<string name="fibNI">fibNI</string> 
<string name="app_name">FibonacciNative</string> 
<string name="button">Get Fibonacci Result</string> 
Fibonacci - User Interface (Layout) 
Fibonacci Native Main Layout 
FFiibboonnaacccciiNNaattiivvee//rreess//llaayyoouutt//mmaaiinn..xxmmll 
</resources> 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 
<!-- This is just a simple title ("Get Your Fibonacci Here!") --> 
<TextView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:gravity="center" 
android:text="@string/hello" 
android:textSize="25sp" /> 
<!-- This is the entry box for our number "n" --> 
<EditText
android:id="@+id/input" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:ems="10" 
android:gravity="right" 
android:inputType="number" > 
<requestFocus /> 
</EditText> 
<!-- This radio group allows the user to select the fibonacci implementation type --> 
<RadioGroup 
android:id="@+id/type" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 
<RadioButton 
android:id="@+id/type_fib_jr" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_weight="1" 
android:text="@string/fibJR" /> 
<RadioButton 
android:id="@+id/type_fib_ji" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_weight="1" 
android:text="@string/fibJI" /> 
<RadioButton 
android:id="@+id/type_fib_nr" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_weight="1" 
android:text="@string/fibNR" /> 
<RadioButton 
android:id="@+id/type_fib_ni" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_weight="1" 
android:text="@string/fibNI" /> 
</RadioGroup> 
<!-- This button allows the user to trigger fibonacci calculation --> 
<Button 
android:id="@+id/button" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:text="@string/button" /> 
<!-- This is the output area for the fibonacci result --> 
<TextView 
android:id="@+id/output" 
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:gravity="center" 
android:textSize="20sp" /> 
</LinearLayout> 
Fibonacci - FFiibboonnaacccciiAAccttiivviittyy 
FFiibboonnaacccciiNNaattiivvee//ssrrcc//ccoomm//mmaarraakkaannaa//aannddrrooiidd//ffiibboonnaacccciinnaattiivvee//FFiibboonnaacccciiAAccttiivviittyy..jjaavvaa 
package com.marakana.android.fibonaccinative; 
import android.app.Activity; 
import android.app.ProgressDialog; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.os.SystemClock; 
import android.text.TextUtils; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.RadioGroup; 
import android.widget.TextView; 
public class FibonacciActivity extends Activity implements OnClickListener { 
private EditText input; 
private RadioGroup type; 
private TextView output; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 
this.input = (EditText) super.findViewById(R.id.input); 
this.type = (RadioGroup) super.findViewById(R.id.type); 
this.output = (TextView) super.findViewById(R.id.output); 
Button button = (Button) super.findViewById(R.id.button); 
button.setOnClickListener(this); 
} 
public void onClick(View view) { 
String s = this.input.getText().toString(); 
if (TextUtils.isEmpty(s)) { 
return; 
} 
final ProgressDialog dialog = ProgressDialog.show(this, "", 
"Calculating...", true); 
final long n = Long.parseLong(s); 
new AsyncTask<Void, Void, String>() { 
@Override
protected String doInBackground(Void... params) { 
long result = 0; 
long t = SystemClock.uptimeMillis(); 
switch (FibonacciActivity.this.type.getCheckedRadioButtonId()) { 
case R.id.type_fib_jr: 
result = FibLib.fibJR(n); 
break; 
case R.id.type_fib_ji: 
result = FibLib.fibJI(n); 
break; 
case R.id.type_fib_nr: 
result = FibLib.fibNR(n); 
break; 
case R.id.type_fib_ni: 
result = FibLib.fibNI(n); 
break; 
} 
t = SystemClock.uptimeMillis() - t; 
return String.format("fib(%d)=%d in %d ms", n, result, t); 
} 
@Override 
protected void onPostExecute(String result) { 
dialog.dismiss(); 
FibonacciActivity.this.output.setText(result); 
} 
}.execute(); 
} 
}
Fibonacci - Result 
Fibonacci Native Result
NDK’s Stable APIs 
The header files for NDK stable APIs are available at 
/path/to/ndk/platforms/<android-platform>/<arch-nnaammee>>//uussrr//iinncclluuddee.
Android-specific Log Support 
Include <<aannddrrooiidd//lloogg..hh>> to access various functionality that can be used to send log messages to the 
kernel (i.e. logcat buffers) from our native code 
Requires that our code be linked to //ssyysstteemm//lliibb//lliibblloogg..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== --lllloogg in our 
AAnnddrrooiidd..mmkk file
ZLib Compression Library 
Include <<zzlliibb..hh>> and <<zzccoonnff..hh>> to access ZLib compression library 
See hhttttpp::////wwwwww..zzlliibb..nneett//mmaannuuaall..hhttmmll for more info on ZLib 
Requires that our code be linked to //ssyysstteemm//lliibb//lliibbzz..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== --llzz in our 
AAnnddrrooiidd..mmkk file
The OpenGL ES 1.x Library 
Include <<GGLLEESS//ggll..hh>> and <<GGLLEESS//gglleexxtt..hh>> to access OpenGL ES 1.x rendering calls from native code 
The "1.x" here refers to both versions 1.0 and 1.1 
Using 1.1 requires OpenGL-capable GPU 
Using 1.0 is universally supported since Android includes software renderer for GPU-less devices 
Requires that we include <<uusseess--ffeeaattuurree>> tag in our manifest file to indicate the actual OpenGL 
version that we expect 
Requires that our code be linked to //ssyysstteemm//lliibb//lliibbGGLLEESSvv11__CCMM..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== -- 
llGGLLEESSvv11__CCMM..ssoo in our AAnnddrrooiidd..mmkk file 
Since API 4 (Android 1.6)
The OpenGL ES 2.0 Library 
Include <<GGLLEESS22//ggll22..hh>> and <<GGLLEESS22//ggll22eexxtt..hh>> to access OpenGL ES 2.0 rendering calls from native 
code 
Enables the use of vertex and fragment shaders via the GLSL language 
Since not all devices support OpenGL 2.0, we should include <<uusseess--ffeeaattuurree>> tag in our manifest file 
to indicate this requirement 
Requires that our code be linked to //ssyysstteemm//lliibb//lliibbGGLLEESSvv22..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== -- 
llGGLLEESSvv22..ssoo in our AAnnddrrooiidd..mmkk file 
Since API 4 (Android 2.0)
The jjnniiggrraapphhiiccss Library 
Include <<aannddrrooiidd//bbiittmmaapp..hh>> to reliably access the pixel buffers of Java bitmap objects from native code 
Requires that our code be linked to //ssyysstteemm//lliibb//lliibbjjnniiggrraapphhiiccss..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== -- 
lljjnniiggrraapphhiiccss in our AAnnddrrooiidd..mmkk file 
Since API 8 (Android 2.2)
The OpenSL ES native audio Library 
Include <<SSLLEESS//OOppeennSSLLEESS..hh>> and <<SSLLEESS//OOppeennSSLLEESS__PPllaattffoorrmm..hh>> to perform audio input and output 
from native code 
Based on Khronos Group OpenSL ES™ 1.0.1 
Requires that our code be linked to //ssyysstteemm//lliibb//lliibbOOppeennSSLLEESS..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== -- 
llOOppeennSSLLEESS in our AAnnddrrooiidd..mmkk file 
Since API 9 (Android 2.3)
The Android native application APIs 
Makes it possible to write our entire application in native code 
Mainly added for gaming 
Our code still depends on the Dalvik VM since most of the platform features are managed in the VM and 
accessed via JNI (Native → Java) 
Include <android/nnaattiivvee__aaccttiivviittyy..hh>> to write an Android activity (with its life-cycle callbacks) in 
native code 
A native activity would serve as the main entry point into our native application 
Include <<aannddrrooiidd//llooooppeerr..hh>>, <<aannddrrooiidd//iinnppuutt..hh>>, <<aannddrrooiidd//kkeeyyccooddeess..hh>>, and 
<<aannddrrooiidd//sseennssoorr..hh>> to listen to input events and sensors directly from native code 
Include <<aannddrrooiidd//rreecctt..hh>>, <<aannddrrooiidd//wwiinnddooww..hh>>, <<aannddrrooiidd//nnaattiivvee__wwiinnddooww..hh>>, and 
<<aannddrrooiidd//nnaattiivvee__wwiinnddooww__jjnnii..hh>> for window management from native code 
Includes ability to lock/unlock the pixel buffer to draw directly into it 
Include <<aannddrrooiidd//ccoonnffiigguurraattiioonn..hh>>, <<aannddrrooiidd//aasssseett__mmaannaaggeerr..hh>>, 
<<aannddrrooiidd//ssttoorraaggee__mmaannaaggeerr..hh>>, and <<aannddrrooiidd//oobbbb..hh>> for direct access to the assets embedded in 
our ..aappkk files Opaque Binary Blob (OBB) files 
All access is read-only 
Requires that our code be linked to lliibbaannddrrooiidd..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== --llaannddrrooiidd in our 
AAnnddrrooiidd..mmkk file 
Since API 9 (Android 2.3) 
With the exception of the libraries listed above, the native system libraries in the Android platform are not 
considered "stable" and may change in future platform versions. Unless our library is being built for a specific 
Android ROM, we should only make use of the stable libraries provided by the NDK. 
All the header files are available under: //ppaatthh//ttoo//nnddkk--iinnssttaallllaattiioonn--ddiirr//ppllaattffoorrmmss//aannddrrooiidd-- 
99//aarrcchh--aarrmm//uussrr//iinncclluuddee// 
See //ppaatthh//ttoo//nnddkk--iinnssttaallllaattiioonn--ddiirr//ddooccss//SSTTAABBLLEE--AAPPIISS..hhttmmll for the complete reference of 
NDK’s stable APIs.
Lab: NDK 
The objective of this lab is to test your understanding of JNI and NDK. We will do so by 
adding JNI code to an existing application. 
1. Start by importing LogNative application into Eclipse 
1. Menu Bar → File → Import… → Git → Projects from Git → Next > 
2. Under Select Repository Source select URI → Next > 
3. Under Source Git Repository → Location → URI: enter 
https://github.com/marakana/LLooggNNaattiivvee..ggiitt → Next > 
4. Under Branch Selection, leave all branches selected (checked) → Next > 
5. Under Local Destination → Destination specify directory of your choice (e.g. 
~~//aannddrrooiidd//wwoorrkkssppaaccee//LLooggNNaattiivvee) → Next > 
6. Under Select a wizard to use for importing projects, leave Wizard for project import as 
Import existing projects → Next > 
7. Under Import Projects → Projects, leave LogNative as selected (checked) → Finish 
This project can also be downloaded as a ZIP file 
2. Examine and test your project in Eclipse 
1. Run the application on a device/emulator 
2. Enter some tag and message to log, click on the Log button and observe via aaddbb 
llooggccaatt that your message get logged (assuming Java was selected) 
3. Implement ccoomm..mmaarraakkaannaa..aannddrrooiidd..llooggnnaattiivvee..LLooggLLiibb..llooggNN((iinntt pprriioorriittyy,, 
SSttrriinngg ttaagg,, SSttrriinngg mmssgg)) in C 
1. Mark the method as nnaattiivvee 
2. Remove its body 
3. Extract its function prototype into a C header file (hint: jjaavvaahh) 
4. Implement the function by taking advantage of <<aannddrrooiidd//lloogg..hh>> (i.e.
/ssyysstteemm//lliibb//lliibblloogg..ssoo) 
5. Provide the makefile(s) 
4. Build (via nnddkk--bbuuiilldd) 
5. Run your application 
6. Test by selecting NNaattiivvee in the UI and checking that the log tag/message shows up in 
aaddbb llooggccaatt 
7. As a bonus: 
1. Throw jjaavvaa..llaanngg..NNuullllPPooiinntteerrEExxcceeppttiioonn if ttaagg or mmssgg are null 
2. Throw jjaavvaa..llaanngg..IIlllleeggaallAArrgguummeennttEExxcceeppttiioonn if pprriioorriittyy is not one of the 
allowed types or if ttaagg or mmssgg are empty 
Don’t forget to convert ttaagg and mmssgg strings from the Java format (jjssttrriinngg) to native format (cchhaarr **) before 
trying to use them in iinntt ____aannddrrooiidd__lloogg__wwrriittee((iinntt pprriioo,, ccoonnsstt cchhaarr **ttaagg,, ccoonnsstt cchhaarr 
**tteexxtt)). Be sure to free the native strings before returning from the native method. Finally, don’t forget to tell 
the linker about your use of the log library. 
The solution is provided: 
As a ZIP archive: https://github.com/marakana/LogNative/zipball/solution 
By Git: ggiitt cclloonnee https://github.com/marakana/LogNative.git --bb ssoolluuttiioonn
Summary of NDK Module 
In this module, you learned how Android uses JNI to bridge between the world of Java and 
the native code. You also learned how NDK makes the process of working with JNI simpler by 
providing tools and framework for developing native libraries as well as packaging them with 
the app. 
Thank you! 
Marko Gargenta & Marakana Team 
@MarkoGargenta 
Special thanks to Aleksandar (Sasa) Gargenta as well as the rest of Marakana team for 
research related to NDK. 
Slides & video of this presentation is available at Marakana.com 
Yamba source code is available at https://github.com/marakana/ 
(c) Marakana.com

Contenu connexe

Tendances

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
 
Intro to GPGPU Programming with Cuda
Intro to GPGPU Programming with CudaIntro to GPGPU Programming with Cuda
Intro to GPGPU Programming with CudaRob Gillen
 
GDC2011 - Implementation and Application of the Real-Time Helper-Joint System
GDC2011 - Implementation and Application of the Real-Time Helper-Joint SystemGDC2011 - Implementation and Application of the Real-Time Helper-Joint System
GDC2011 - Implementation and Application of the Real-Time Helper-Joint SystemJubok Kim
 
【Unite Tokyo 2018】“100 Must-see Assets for 2018” by Virtual YouTuber, Cyber G...
【Unite Tokyo 2018】“100 Must-see Assets for 2018” by Virtual YouTuber, Cyber G...【Unite Tokyo 2018】“100 Must-see Assets for 2018” by Virtual YouTuber, Cyber G...
【Unite Tokyo 2018】“100 Must-see Assets for 2018” by Virtual YouTuber, Cyber G...Unity Technologies Japan K.K.
 
Optimizing unity games (Google IO 2014)
Optimizing unity games (Google IO 2014)Optimizing unity games (Google IO 2014)
Optimizing unity games (Google IO 2014)Alexander Dolbilov
 
シェーダーを活用した3Dライブ演出のアップデート ~『ラブライブ!スクールアイドルフェスティバル ALL STARS』(スクスタ)の開発事例~​
シェーダーを活用した3Dライブ演出のアップデート ~『ラブライブ!スクールアイドルフェスティバル ALL STARS』(スクスタ)の開発事例~​シェーダーを活用した3Dライブ演出のアップデート ~『ラブライブ!スクールアイドルフェスティバル ALL STARS』(スクスタ)の開発事例~​
シェーダーを活用した3Dライブ演出のアップデート ~『ラブライブ!スクールアイドルフェスティバル ALL STARS』(スクスタ)の開発事例~​KLab Inc. / Tech
 
AGDK tutorial step by step
AGDK tutorial step by stepAGDK tutorial step by step
AGDK tutorial step by stepJungsoo Nam
 
Java on the GPU: Where are we now?
Java on the GPU: Where are we now?Java on the GPU: Where are we now?
Java on the GPU: Where are we now?Dmitry Alexandrov
 
Android NDK and the x86 Platform
Android NDK and the x86 PlatformAndroid NDK and the x86 Platform
Android NDK and the x86 PlatformSebastian Mauer
 
Unity - Internals: memory and performance
Unity - Internals: memory and performanceUnity - Internals: memory and performance
Unity - Internals: memory and performanceCodemotion
 
[Gdc2012] 디아블로3 ragdolls
[Gdc2012] 디아블로3 ragdolls[Gdc2012] 디아블로3 ragdolls
[Gdc2012] 디아블로3 ragdollsMinGeun Park
 
OpenCVとPCLでのRealSenseのサポート状況+α
OpenCVとPCLでのRealSenseのサポート状況+αOpenCVとPCLでのRealSenseのサポート状況+α
OpenCVとPCLでのRealSenseのサポート状況+αTsukasa Sugiura
 
Rendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
Rendering Techniques for Augmented Reality and a Look Ahead at AR FoundationRendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
Rendering Techniques for Augmented Reality and a Look Ahead at AR FoundationUnity Technologies
 
Uncharted3 effect technique
Uncharted3 effect techniqueUncharted3 effect technique
Uncharted3 effect techniqueMinGeun Park
 
Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008Ryan Chou
 

Tendances (20)

Android ndk
Android ndkAndroid ndk
Android ndk
 
NDK Introduction
NDK IntroductionNDK Introduction
NDK Introduction
 
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)
 
Intro to GPGPU Programming with Cuda
Intro to GPGPU Programming with CudaIntro to GPGPU Programming with Cuda
Intro to GPGPU Programming with Cuda
 
GDC2011 - Implementation and Application of the Real-Time Helper-Joint System
GDC2011 - Implementation and Application of the Real-Time Helper-Joint SystemGDC2011 - Implementation and Application of the Real-Time Helper-Joint System
GDC2011 - Implementation and Application of the Real-Time Helper-Joint System
 
【Unite Tokyo 2018】“100 Must-see Assets for 2018” by Virtual YouTuber, Cyber G...
【Unite Tokyo 2018】“100 Must-see Assets for 2018” by Virtual YouTuber, Cyber G...【Unite Tokyo 2018】“100 Must-see Assets for 2018” by Virtual YouTuber, Cyber G...
【Unite Tokyo 2018】“100 Must-see Assets for 2018” by Virtual YouTuber, Cyber G...
 
Deep Learning Edge
Deep Learning Edge Deep Learning Edge
Deep Learning Edge
 
Optimizing unity games (Google IO 2014)
Optimizing unity games (Google IO 2014)Optimizing unity games (Google IO 2014)
Optimizing unity games (Google IO 2014)
 
シェーダーを活用した3Dライブ演出のアップデート ~『ラブライブ!スクールアイドルフェスティバル ALL STARS』(スクスタ)の開発事例~​
シェーダーを活用した3Dライブ演出のアップデート ~『ラブライブ!スクールアイドルフェスティバル ALL STARS』(スクスタ)の開発事例~​シェーダーを活用した3Dライブ演出のアップデート ~『ラブライブ!スクールアイドルフェスティバル ALL STARS』(スクスタ)の開発事例~​
シェーダーを活用した3Dライブ演出のアップデート ~『ラブライブ!スクールアイドルフェスティバル ALL STARS』(スクスタ)の開発事例~​
 
Android ndk: Entering the native world
Android ndk: Entering the native worldAndroid ndk: Entering the native world
Android ndk: Entering the native world
 
AGDK tutorial step by step
AGDK tutorial step by stepAGDK tutorial step by step
AGDK tutorial step by step
 
Java on the GPU: Where are we now?
Java on the GPU: Where are we now?Java on the GPU: Where are we now?
Java on the GPU: Where are we now?
 
Android NDK and the x86 Platform
Android NDK and the x86 PlatformAndroid NDK and the x86 Platform
Android NDK and the x86 Platform
 
Unity - Internals: memory and performance
Unity - Internals: memory and performanceUnity - Internals: memory and performance
Unity - Internals: memory and performance
 
[Gdc2012] 디아블로3 ragdolls
[Gdc2012] 디아블로3 ragdolls[Gdc2012] 디아블로3 ragdolls
[Gdc2012] 디아블로3 ragdolls
 
OpenCVとPCLでのRealSenseのサポート状況+α
OpenCVとPCLでのRealSenseのサポート状況+αOpenCVとPCLでのRealSenseのサポート状況+α
OpenCVとPCLでのRealSenseのサポート状況+α
 
Rendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
Rendering Techniques for Augmented Reality and a Look Ahead at AR FoundationRendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
Rendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
 
Uncharted3 effect technique
Uncharted3 effect techniqueUncharted3 effect technique
Uncharted3 effect technique
 
Duel of Two Libraries: Cairo & Skia
Duel of Two Libraries: Cairo & SkiaDuel of Two Libraries: Cairo & Skia
Duel of Two Libraries: Cairo & Skia
 
Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008
 

En vedette

Application parallelisation Android - Klaas Vangend
Application parallelisation Android - Klaas VangendApplication parallelisation Android - Klaas Vangend
Application parallelisation Android - Klaas Vangendナム-Nam Nguyễn
 
CEDEC 2015 Cocos2d-x と社内基盤の付き合い方 〜アップストリームファーストを目指して〜
CEDEC 2015 Cocos2d-x と社内基盤の付き合い方 〜アップストリームファーストを目指して〜CEDEC 2015 Cocos2d-x と社内基盤の付き合い方 〜アップストリームファーストを目指して〜
CEDEC 2015 Cocos2d-x と社内基盤の付き合い方 〜アップストリームファーストを目指して〜Drecom Co., Ltd.
 
Aiming 開発ゲームの裏側
Aiming 開発ゲームの裏側Aiming 開発ゲームの裏側
Aiming 開発ゲームの裏側Katsutoshi Makino
 
Tabc vol3 テクニカルアーティストを始めるにあたって
Tabc vol3 テクニカルアーティストを始めるにあたってTabc vol3 テクニカルアーティストを始めるにあたって
Tabc vol3 テクニカルアーティストを始めるにあたってfumoto kazuhiro
 
中級グラフィックス入門~シャドウマッピング総まとめ~
中級グラフィックス入門~シャドウマッピング総まとめ~中級グラフィックス入門~シャドウマッピング総まとめ~
中級グラフィックス入門~シャドウマッピング総まとめ~ProjectAsura
 
Weighted Blended Order Independent Transparency
Weighted Blended Order Independent TransparencyWeighted Blended Order Independent Transparency
Weighted Blended Order Independent Transparencyzokweiron
 
レイトレ合宿3!!! 5分間アピールプレゼン―Pocol
レイトレ合宿3!!! 5分間アピールプレゼン―Pocolレイトレ合宿3!!! 5分間アピールプレゼン―Pocol
レイトレ合宿3!!! 5分間アピールプレゼン―PocolProjectAsura
 
Unity & VR (Unity Roadshow 2016)
Unity & VR (Unity Roadshow 2016)Unity & VR (Unity Roadshow 2016)
Unity & VR (Unity Roadshow 2016)ozlael ozlael
 
Unity * スマートフォン開発で学んだこと
Unity * スマートフォン開発で学んだことUnity * スマートフォン開発で学んだこと
Unity * スマートフォン開発で学んだことKatsutoshi Makino
 
ACES 1.0 OpenColorIO config - Siggraph 2015
ACES 1.0 OpenColorIO config - Siggraph 2015ACES 1.0 OpenColorIO config - Siggraph 2015
ACES 1.0 OpenColorIO config - Siggraph 2015hpduiker
 
CEDEC 2016 Metal と Vulkan を用いた水彩画レンダリング技法の紹介
CEDEC 2016 Metal と Vulkan を用いた水彩画レンダリング技法の紹介CEDEC 2016 Metal と Vulkan を用いた水彩画レンダリング技法の紹介
CEDEC 2016 Metal と Vulkan を用いた水彩画レンダリング技法の紹介Drecom Co., Ltd.
 
ACEScg: A Common Color Encoding for Visual Effects Applications - DigiPro 2015
ACEScg: A Common Color Encoding for Visual Effects Applications - DigiPro 2015ACEScg: A Common Color Encoding for Visual Effects Applications - DigiPro 2015
ACEScg: A Common Color Encoding for Visual Effects Applications - DigiPro 2015hpduiker
 
뭣이 중헌디? 성능 프로파일링도 모름서 - 유니티 성능 프로파일링 가이드 (IGC16)
뭣이 중헌디? 성능 프로파일링도 모름서 - 유니티 성능 프로파일링 가이드 (IGC16)뭣이 중헌디? 성능 프로파일링도 모름서 - 유니티 성능 프로파일링 가이드 (IGC16)
뭣이 중헌디? 성능 프로파일링도 모름서 - 유니티 성능 프로파일링 가이드 (IGC16)ozlael ozlael
 
Penner pre-integrated skin rendering (siggraph 2011 advances in real-time r...
Penner   pre-integrated skin rendering (siggraph 2011 advances in real-time r...Penner   pre-integrated skin rendering (siggraph 2011 advances in real-time r...
Penner pre-integrated skin rendering (siggraph 2011 advances in real-time r...JP Lee
 
声の実体化体験 - HTML5でつくるデジタルインスタレーション -
声の実体化体験 - HTML5でつくるデジタルインスタレーション -声の実体化体験 - HTML5でつくるデジタルインスタレーション -
声の実体化体験 - HTML5でつくるデジタルインスタレーション -Yamato Honda
 
Kansai cedec 2015_fumoto
Kansai cedec 2015_fumotoKansai cedec 2015_fumoto
Kansai cedec 2015_fumotofumoto kazuhiro
 
AI in Games- Steering, Wander and Flocking behavior
AI in Games- Steering, Wander and Flocking behaviorAI in Games- Steering, Wander and Flocking behavior
AI in Games- Steering, Wander and Flocking behaviorナム-Nam Nguyễn
 
Shadow gunのサンプルから学べるモバイル最適化
Shadow gunのサンプルから学べるモバイル最適化Shadow gunのサンプルから学べるモバイル最適化
Shadow gunのサンプルから学べるモバイル最適化Katsutoshi Makino
 
レイトレ合宿2!! 3分間アピールプレゼン―Pocol
レイトレ合宿2!! 3分間アピールプレゼン―Pocolレイトレ合宿2!! 3分間アピールプレゼン―Pocol
レイトレ合宿2!! 3分間アピールプレゼン―PocolProjectAsura
 

En vedette (20)

Application parallelisation Android - Klaas Vangend
Application parallelisation Android - Klaas VangendApplication parallelisation Android - Klaas Vangend
Application parallelisation Android - Klaas Vangend
 
CEDEC 2015 Cocos2d-x と社内基盤の付き合い方 〜アップストリームファーストを目指して〜
CEDEC 2015 Cocos2d-x と社内基盤の付き合い方 〜アップストリームファーストを目指して〜CEDEC 2015 Cocos2d-x と社内基盤の付き合い方 〜アップストリームファーストを目指して〜
CEDEC 2015 Cocos2d-x と社内基盤の付き合い方 〜アップストリームファーストを目指して〜
 
Aiming 開発ゲームの裏側
Aiming 開発ゲームの裏側Aiming 開発ゲームの裏側
Aiming 開発ゲームの裏側
 
Tabc vol3 テクニカルアーティストを始めるにあたって
Tabc vol3 テクニカルアーティストを始めるにあたってTabc vol3 テクニカルアーティストを始めるにあたって
Tabc vol3 テクニカルアーティストを始めるにあたって
 
中級グラフィックス入門~シャドウマッピング総まとめ~
中級グラフィックス入門~シャドウマッピング総まとめ~中級グラフィックス入門~シャドウマッピング総まとめ~
中級グラフィックス入門~シャドウマッピング総まとめ~
 
Weighted Blended Order Independent Transparency
Weighted Blended Order Independent TransparencyWeighted Blended Order Independent Transparency
Weighted Blended Order Independent Transparency
 
レイトレ合宿3!!! 5分間アピールプレゼン―Pocol
レイトレ合宿3!!! 5分間アピールプレゼン―Pocolレイトレ合宿3!!! 5分間アピールプレゼン―Pocol
レイトレ合宿3!!! 5分間アピールプレゼン―Pocol
 
Unity & VR (Unity Roadshow 2016)
Unity & VR (Unity Roadshow 2016)Unity & VR (Unity Roadshow 2016)
Unity & VR (Unity Roadshow 2016)
 
Unity * スマートフォン開発で学んだこと
Unity * スマートフォン開発で学んだことUnity * スマートフォン開発で学んだこと
Unity * スマートフォン開発で学んだこと
 
ACES 1.0 OpenColorIO config - Siggraph 2015
ACES 1.0 OpenColorIO config - Siggraph 2015ACES 1.0 OpenColorIO config - Siggraph 2015
ACES 1.0 OpenColorIO config - Siggraph 2015
 
CEDEC 2016 Metal と Vulkan を用いた水彩画レンダリング技法の紹介
CEDEC 2016 Metal と Vulkan を用いた水彩画レンダリング技法の紹介CEDEC 2016 Metal と Vulkan を用いた水彩画レンダリング技法の紹介
CEDEC 2016 Metal と Vulkan を用いた水彩画レンダリング技法の紹介
 
ACEScg: A Common Color Encoding for Visual Effects Applications - DigiPro 2015
ACEScg: A Common Color Encoding for Visual Effects Applications - DigiPro 2015ACEScg: A Common Color Encoding for Visual Effects Applications - DigiPro 2015
ACEScg: A Common Color Encoding for Visual Effects Applications - DigiPro 2015
 
뭣이 중헌디? 성능 프로파일링도 모름서 - 유니티 성능 프로파일링 가이드 (IGC16)
뭣이 중헌디? 성능 프로파일링도 모름서 - 유니티 성능 프로파일링 가이드 (IGC16)뭣이 중헌디? 성능 프로파일링도 모름서 - 유니티 성능 프로파일링 가이드 (IGC16)
뭣이 중헌디? 성능 프로파일링도 모름서 - 유니티 성능 프로파일링 가이드 (IGC16)
 
Penner pre-integrated skin rendering (siggraph 2011 advances in real-time r...
Penner   pre-integrated skin rendering (siggraph 2011 advances in real-time r...Penner   pre-integrated skin rendering (siggraph 2011 advances in real-time r...
Penner pre-integrated skin rendering (siggraph 2011 advances in real-time r...
 
Aclt1
Aclt1Aclt1
Aclt1
 
声の実体化体験 - HTML5でつくるデジタルインスタレーション -
声の実体化体験 - HTML5でつくるデジタルインスタレーション -声の実体化体験 - HTML5でつくるデジタルインスタレーション -
声の実体化体験 - HTML5でつくるデジタルインスタレーション -
 
Kansai cedec 2015_fumoto
Kansai cedec 2015_fumotoKansai cedec 2015_fumoto
Kansai cedec 2015_fumoto
 
AI in Games- Steering, Wander and Flocking behavior
AI in Games- Steering, Wander and Flocking behaviorAI in Games- Steering, Wander and Flocking behavior
AI in Games- Steering, Wander and Flocking behavior
 
Shadow gunのサンプルから学べるモバイル最適化
Shadow gunのサンプルから学べるモバイル最適化Shadow gunのサンプルから学べるモバイル最適化
Shadow gunのサンプルから学べるモバイル最適化
 
レイトレ合宿2!! 3分間アピールプレゼン―Pocol
レイトレ合宿2!! 3分間アピールプレゼン―Pocolレイトレ合宿2!! 3分間アピールプレゼン―Pocol
レイトレ合宿2!! 3分間アピールプレゼン―Pocol
 

Similaire à Getting Native with 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 2014Paris Android User Group
 
Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDKKirill Kounik
 
Android ndk - Introduction
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - IntroductionRakesh Jha
 
Native development kit (ndk) introduction
Native development kit (ndk)  introductionNative development kit (ndk)  introduction
Native development kit (ndk) introductionRakesh Jha
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application DevelopmentRamesh Prasad
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDKBeMyApp
 
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
 
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
 
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 NDKSebastian Mauer
 
Android Developer Meetup
Android Developer MeetupAndroid Developer Meetup
Android Developer MeetupMedialets
 
NDK Programming in Android
NDK Programming in AndroidNDK Programming in Android
NDK Programming in AndroidArvind Devaraj
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)Ron Munitz
 
Exploring Next Generation Buildpacks - Anand Rao & Scott Deeg
Exploring Next Generation Buildpacks - Anand Rao & Scott DeegExploring Next Generation Buildpacks - Anand Rao & Scott Deeg
Exploring Next Generation Buildpacks - Anand Rao & Scott DeegVMware Tanzu
 
Android NDK Intro
Android NDK IntroAndroid NDK Intro
Android NDK IntroGiles Payne
 
LinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik BytecodeLinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik BytecodeAlain Leon
 

Similaire à Getting Native with NDK (20)

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
Android ndkAndroid ndk
Android ndk
 
Getting started with the NDK
Getting started with the NDKGetting started with the NDK
Getting started with the NDK
 
Android NDK
Android NDKAndroid NDK
Android NDK
 
Android ndk - Introduction
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - Introduction
 
Native development kit (ndk) introduction
Native development kit (ndk)  introductionNative development kit (ndk)  introduction
Native development kit (ndk) introduction
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the 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
 
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
 
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
 
Core Android
Core AndroidCore Android
Core Android
 
Android Developer Meetup
Android Developer MeetupAndroid Developer Meetup
Android Developer Meetup
 
NDK Programming in Android
NDK Programming in AndroidNDK Programming in Android
NDK Programming in Android
 
NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)
 
Exploring Next Generation Buildpacks - Anand Rao & Scott Deeg
Exploring Next Generation Buildpacks - Anand Rao & Scott DeegExploring Next Generation Buildpacks - Anand Rao & Scott Deeg
Exploring Next Generation Buildpacks - Anand Rao & Scott Deeg
 
Android basics
Android basicsAndroid basics
Android basics
 
Android NDK Intro
Android NDK IntroAndroid NDK Intro
Android NDK Intro
 
LinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik BytecodeLinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik Bytecode
 

Plus de ナム-Nam Nguyễn

Improved Alpha-Tested Magnification for Vector Textures and Special Effects
Improved Alpha-Tested Magnification for Vector Textures and Special EffectsImproved Alpha-Tested Magnification for Vector Textures and Special Effects
Improved Alpha-Tested Magnification for Vector Textures and Special Effectsナム-Nam Nguyễn
 
Unite 2013 optimizing unity games for mobile platforms
Unite 2013 optimizing unity games for mobile platformsUnite 2013 optimizing unity games for mobile platforms
Unite 2013 optimizing unity games for mobile platformsナム-Nam Nguyễn
 
China mobile games and entertainment group
China mobile games and entertainment group China mobile games and entertainment group
China mobile games and entertainment group ナム-Nam Nguyễn
 
Success stories compilation of game-based learning initiatives in adults educ...
Success stories compilation of game-based learning initiatives in adults educ...Success stories compilation of game-based learning initiatives in adults educ...
Success stories compilation of game-based learning initiatives in adults educ...ナム-Nam Nguyễn
 
CEO Survey Report of Japanese Video Game Developers - Mirko Ernkvist
CEO Survey Report of Japanese Video Game Developers - Mirko ErnkvistCEO Survey Report of Japanese Video Game Developers - Mirko Ernkvist
CEO Survey Report of Japanese Video Game Developers - Mirko Ernkvistナム-Nam Nguyễn
 
Possibilities of non commercial game
Possibilities of non commercial gamePossibilities of non commercial game
Possibilities of non commercial gameナム-Nam Nguyễn
 
Children's Books, Stories and Songs - Children literature
Children's Books, Stories and Songs - Children literatureChildren's Books, Stories and Songs - Children literature
Children's Books, Stories and Songs - Children literatureナム-Nam Nguyễn
 
Physics for Game Programmers: Spatial Data Structures
Physics for Game Programmers: Spatial Data StructuresPhysics for Game Programmers: Spatial Data Structures
Physics for Game Programmers: Spatial Data Structuresナム-Nam Nguyễn
 
The Economics of the “China Price”
The Economics of the “China Price”The Economics of the “China Price”
The Economics of the “China Price”ナム-Nam Nguyễn
 
Playability and Player Experience Research
Playability and Player Experience ResearchPlayability and Player Experience Research
Playability and Player Experience Researchナム-Nam Nguyễn
 
Android Lifecycle Basics in Practice.
Android Lifecycle Basics in Practice.Android Lifecycle Basics in Practice.
Android Lifecycle Basics in Practice.ナム-Nam Nguyễn
 
Practical Source Code for Ship Motions Time Domain Numerical Analysis and Its...
Practical Source Code for Ship Motions Time Domain Numerical Analysis and Its...Practical Source Code for Ship Motions Time Domain Numerical Analysis and Its...
Practical Source Code for Ship Motions Time Domain Numerical Analysis and Its...ナム-Nam Nguyễn
 
Luoc su duc phat thich nu hue ngan core- da chuyen
Luoc su duc phat   thich nu hue ngan core- da chuyenLuoc su duc phat   thich nu hue ngan core- da chuyen
Luoc su duc phat thich nu hue ngan core- da chuyenナム-Nam Nguyễn
 
Japanese web browser preferences | 世論 what japan thinks
Japanese web browser preferences | 世論 what japan thinksJapanese web browser preferences | 世論 what japan thinks
Japanese web browser preferences | 世論 what japan thinksナム-Nam Nguyễn
 

Plus de ナム-Nam Nguyễn (19)

Bullet Physic Engine SDK
Bullet Physic Engine SDKBullet Physic Engine SDK
Bullet Physic Engine SDK
 
Improved Alpha-Tested Magnification for Vector Textures and Special Effects
Improved Alpha-Tested Magnification for Vector Textures and Special EffectsImproved Alpha-Tested Magnification for Vector Textures and Special Effects
Improved Alpha-Tested Magnification for Vector Textures and Special Effects
 
Unite 2013 optimizing unity games for mobile platforms
Unite 2013 optimizing unity games for mobile platformsUnite 2013 optimizing unity games for mobile platforms
Unite 2013 optimizing unity games for mobile platforms
 
China mobile games and entertainment group
China mobile games and entertainment group China mobile games and entertainment group
China mobile games and entertainment group
 
Success stories compilation of game-based learning initiatives in adults educ...
Success stories compilation of game-based learning initiatives in adults educ...Success stories compilation of game-based learning initiatives in adults educ...
Success stories compilation of game-based learning initiatives in adults educ...
 
CEO Survey Report of Japanese Video Game Developers - Mirko Ernkvist
CEO Survey Report of Japanese Video Game Developers - Mirko ErnkvistCEO Survey Report of Japanese Video Game Developers - Mirko Ernkvist
CEO Survey Report of Japanese Video Game Developers - Mirko Ernkvist
 
Abusing mobilegames
Abusing mobilegamesAbusing mobilegames
Abusing mobilegames
 
Possibilities of non commercial game
Possibilities of non commercial gamePossibilities of non commercial game
Possibilities of non commercial game
 
Children's Books, Stories and Songs - Children literature
Children's Books, Stories and Songs - Children literatureChildren's Books, Stories and Songs - Children literature
Children's Books, Stories and Songs - Children literature
 
MGI Big data full report
MGI Big data full reportMGI Big data full report
MGI Big data full report
 
Ai.game.wisdom
Ai.game.wisdomAi.game.wisdom
Ai.game.wisdom
 
Physics for Game Programmers: Spatial Data Structures
Physics for Game Programmers: Spatial Data StructuresPhysics for Game Programmers: Spatial Data Structures
Physics for Game Programmers: Spatial Data Structures
 
The Economics of the “China Price”
The Economics of the “China Price”The Economics of the “China Price”
The Economics of the “China Price”
 
Smoothed Particle Hydrodynamics
Smoothed Particle HydrodynamicsSmoothed Particle Hydrodynamics
Smoothed Particle Hydrodynamics
 
Playability and Player Experience Research
Playability and Player Experience ResearchPlayability and Player Experience Research
Playability and Player Experience Research
 
Android Lifecycle Basics in Practice.
Android Lifecycle Basics in Practice.Android Lifecycle Basics in Practice.
Android Lifecycle Basics in Practice.
 
Practical Source Code for Ship Motions Time Domain Numerical Analysis and Its...
Practical Source Code for Ship Motions Time Domain Numerical Analysis and Its...Practical Source Code for Ship Motions Time Domain Numerical Analysis and Its...
Practical Source Code for Ship Motions Time Domain Numerical Analysis and Its...
 
Luoc su duc phat thich nu hue ngan core- da chuyen
Luoc su duc phat   thich nu hue ngan core- da chuyenLuoc su duc phat   thich nu hue ngan core- da chuyen
Luoc su duc phat thich nu hue ngan core- da chuyen
 
Japanese web browser preferences | 世論 what japan thinks
Japanese web browser preferences | 世論 what japan thinksJapanese web browser preferences | 世論 what japan thinks
Japanese web browser preferences | 世論 what japan thinks
 

Dernier

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 

Dernier (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 

Getting Native with NDK

  • 2. About Marko Gargenta Marko Gargenta Entrepreneur, Author, Speaker Developer of Android Bootcamp for Marakana. Instructor for 1,000s of developers on Android at Qualcomm, Cisco, Motorola, Intel, DoD and other great orgs. Author of Learning Android published by O’Reilly. Speaker at OSCON (4x), ACM, IEEE(2x), SDC(2x), AnDevCon(3x), DroidCon. Co-Founder of SFAndroid.org Co-Chair of Android Open conference: Android Open
  • 3. Objectives of NDK Module Android is put together of about equal part Java and C. So, no wonder that we need an easy way to bridge between these two totally different worlds. Java offers Java Native Interface (JNI) as a framework connecting the world of Java to the native code. Android goes a step further by packaging other useful tools and libraries into a Native Development Kit, or NDK. NDK makes developing C/C++ code that works with an Android app much simpler than if one was to do it by hand. Topics covered include: What is in NDK? Why NDK? Java Native Interface (JNI) Using NDK NDK and JNI by Example NDK’s Stable APIs Lab: NDK
  • 4. NDK in Action Using NDK to connect Activity to native code
  • 6. What is in NDK? NDK is a toolchain Cross-compiler, linker, what you need to build for ARM, x86, MIPS, etc. NDK provides a way to bundle lib.so into your APK The native library needs to be loadable in a secure way. NDK "standardizes" various native platforms It provides headers for lliibbcc, lliibbmm, lliibbzz, lliibblloogg, lliibbjjnniiggrraahhiiccss, OpenGL/OpenSL ES, JNI headers, minimal C++ support headers, and Android native app APIs. NDK comes with docs and samples Helps you get up to speed with native development. Android’s Dalvik VM allows our applications written in Java to call methods implemented in native code through the Java Native Interface (JNI) For example: package com.marakana.android.fetchurl; public class FetchUrl { public static native byte[] fetch(String url); static { System.loadLibrary("fetchurl"); } } NDK is a tool-chain to build and cross-compile our native code for the device-specific architecture At the moment, NDK supports ARMv5TE, ARMv7-A, x86 (since r6), and mips (since r8) ABIs For example, we would implement native ffeettcchh method in C and compile it into a library lliibbffeettcchhuurrll..ssoo NDK offers a way to package our native code library (as lliibb<<ssoommeetthhiinngg>>..ssoo) into the APK file so we can distribute it with our application easily For example, our library would be packaged as lliibbss//aarrmmeeaabbii//lliibbffeettcchhuurrll..ssoo in the APK NDK provides a set of native system headers that will be supported for the future releases of Android platform (lliibbcc, lliibbmm, lliibbzz, lliibblloogg, lliibbjjnniiggrraahhiiccss, OpenGL/OpenSL ES, JNI headers, minimal C++ support headers, and Android native app APIs) NDK comes with extensive documentation, sample code, and examples As of ADT r20, NDK also adds a plugin to ADT that enables debugging NDK projects in Eclipse and requires:
  • 7. CDT (v7.0.2 or 8.0.2) for Eclipse from http://download.eclipse.org/tools/cdt/releases/indigo ADT (r20) with SDK/NDK plugins for Eclipse from https://dl-ssl.google.com/android/eclipse/ with SDK/NDK paths configured Before an Eclipse project app can be debugged, it must have: native support (project properties → Android Tools → Add native support) enabled NNDDKK__DDEEBBUUGG==11 (project properties → C/C++ Build → Build Command → nnddkk--bbuuiilldd NNDDKK__DDEEBBUUGG==11) set To debug an Eclipse project app: Set the break point(s) as desired Select project → Run → Debug As → Android Native Application
  • 8. Why NDK? For performance Sometimes, native code still runs faster. For legacy support You may have that C/C++ code you’d like to use in your app. For access to low-level libraries In a rare case when there is no Java API to do something. For cross-platform development C is the new portable language. But Adding JNI to your app will make it more complex. Plus Java often offers much richer APIs, memory protection, OOP, productivity. NDK allows us to develop parts of our Android application in C/C++ Generally, we do not develop native-only apps via NDK Android’s Gingerbread (2.3) release supports NNaattiivveeAAccttiivviittyy, which allows handling lifecycle callbacks in native code, so we can now develop native-only apps, No support for native services, broadcast receivers, content providers, etc. NDK code still subject to security sandboxing - we don’t get extra permissions for running natively Main motivation for native code is performance (CPU-intensive, self-contained, low-memory footprint code) and the re-use of legacy code For system integrators, NDK offers access to low-level libraries (e.g. access to user-space HAL) Using NDK always increases complexity of applications, so it should only be used when it’s essential to the application Programming in Java offers richer APIs, memory protection and management, higher-level language constructs (OOP), all of which generally results in higher productivity
  • 9. Using NDK with C NDK Process Using C
  • 10. Using NDK with C++ NDK Process Using C++
  • 11. NDK and JNI by Example NDK is best explained via an example (based on Fibonacci) The code is available As a ZIP archive: https://github.com/marakana/FibonacciNative/zipball/master By Git: ggiitt cclloonnee https://github.com/marakana/FibonacciNative.git Start by creating a new Android Project Project Name: FibonacciNative Build Target: Android 2.2 (API 8) or later Application Name: Fibonacci Native Package: ccoomm..mmaarraakkaannaa..aannddrrooiidd..ffiibboonnaacccciinnaattiivvee Create Activity: FFiibboonnaacccciiAAccttiivviittyy
  • 12. Fibonacci - Java Native Function Prototypes We start off by defining C function prototypes as nnaattiivvee Java methods (wrapped in some class): FFiibboonnaacccciiNNaattiivvee//ssrrcc//ccoomm//mmaarraakkaannaa//aannddrrooiidd//ffiibboonnaacccciinnaattiivvee//FFiibbLLiibb..jjaavvaa
  • 13. package com.marakana.android.fibonaccinative; import android.util.Log; public class FibLib { private static final String TAG = "FibLib"; private static long fib(long n) { return n <= 0 ? 0 : n == 1 ? 1 : fib(n - 1) + fib(n - 2); } // Recursive Java implementation of the Fibonacci algorithm // (included for comparison only) public static long fibJR(long n) { Log.d(TAG, "fibJR(" + n + ")"); return fib(n); } // Function prototype for future native recursive implementation // of the Fibonacci algorithm public native static long fibNR(long n); // Iterative Java implementation of the Fibonacci algorithm // (included for comparison only) public static long fibJI(long n) { Log.d(TAG, "fibJI(" + n + ")"); long previous = -1; long result = 1; for (long i = 0; i <= n; i++) { long sum = result + previous; previous = result; result = sum; } return result; } // Function prototype for future iterative recursive implementation // of the Fibonacci algorithm public native static long fibNI(long n); static { // as defined by LOCAL_MODULE in Android.mk System.loadLibrary("com_marakana_android_fibonaccinative_FibLib"); } }
  • 14. Fibonacci - Function Prototypes in a C Header File We then extract our C header file with our function prototypes: 1. On the command line, change to your project’s root directory $ cd /path/to/workspace/FibonacciNative 2. Create jjnnii sub-directory 3. Extract the C header file from ccoomm..mmaarraakkaannaa..aannddrrooiidd..ffiibboonnaacccciinnaattiivvee..FFiibbLLiibb class: Prior to ADT r14, compiled class files were kept directly in the bbiinn// directory, so in our jjaavvaahh command we would’ve used --ccllaassssppaatthh bbiinn instead. 4. Check out the resulting file: FFiibboonnaacccciiNNaattiivvee//jjnnii//ccoomm__mmaarraakkaannaa__aannddrrooiidd__ffiibboonnaacccciinnaattiivvee__FFiibbLLiibb..hh $ mkdir jni $ javah -jni -classpath bin/classes -d jni com.marakana.android.fibonaccinative.FibLib
  • 15. /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class com_marakana_android_fibonaccinative_FibLib */ #ifndef _Included_com_marakana_android_fibonaccinative_FibLib #define _Included_com_marakana_android_fibonaccinative_FibLib #ifdef __cplusplus extern "C" { #endif /* * Class: com_marakana_android_fibonaccinative_FibLib * Method: fibNR * Signature: (J)J */ JNIEXPORT jlong JNICALL Java_com_marakana_android_fibonaccinative_FibLib_fibNR (JNIEnv *, jclass, jlong); /* * Class: com_marakana_android_fibonaccinative_FibLib * Method: fibNI * Signature: (J)J */ JNIEXPORT jlong JNICALL Java_com_marakana_android_fibonaccinative_FibLib_fibNI (JNIEnv *, jclass, jlong); #ifdef __cplusplus } #endif #endif The function prototype names are name-spaced to the classname they are found in.
  • 16. Fibonacci - Provide C Implementation We provide the C implementation of com_marakana_android_ffiibboonnaaccccii__FFiibbLLiibb..hh header file: FFiibboonnaacccciiNNaattiivvee//jjnnii//ccoomm__mmaarraakkaannaa__aannddrrooiidd__ffiibboonnaacccciinnaattiivvee__FFiibbLLiibb..cc /* Include the header file that was created via "javah -jni" command */ #include "com_marakana_android_fibonaccinative_FibLib.h" #include <android/log.h> /* Recursive implementation of the fibonacci algorithm (in a helper function) */ static jlong fib(jlong n) { return n <= 0 ? 0 : n == 1 ? 1 : fib(n - 1) + fib(n - 2); } /* Actual implementation of JNI-defined `fibNR` (recursive) function */ JNIEXPORT jlong JNICALL Java_com_marakana_android_fibonaccinative_FibLib_fibNR (JNIEnv *env, jclass clazz, jlong n) { __android_log_print(ANDROID_LOG_DEBUG, "FibLib.c", "fibNR(%lld)", n); return fib(n); } /* Actual implementation of JNI-defined `fibNI` (iterative) function */ JNIEXPORT jlong JNICALL Java_com_marakana_android_fibonaccinative_FibLib_fibNI (JNIEnv *env, jclass clazz, jlong n) { jlong previous = -1; jlong result = 1; jlong i; __android_log_print(ANDROID_LOG_DEBUG, "FibLib.c", "fibNI(%lld)", n); for (i = 0; i <= n; i++) { jlong sum = result + previous; previous = result; result = sum; } return result; }
  • 17. Fibonacci - An Alternative Implementation (C++) We could also use an alternative mechanism of linking native-code to managed code by pre-registering our functions. This leads to earlier detection of method-function mismatch issues, a slight performance improvement, and spares us the redundancy of the header file and the use of the jjaavvaahh command. See Registering Native Methods and JNI_OnLoad FFiibboonnaacccciiNNaattiivvee//jjnnii//ccoomm__mmaarraakkaannaa__aannddrrooiidd__ffiibboonnaacccciinnaattiivvee__FFiibbLLiibb..ccpppp
  • 18. #include <jni.h> #include <android/log.h> namespace com_marakana_android_fibonaccinative { static jlong fib(jlong n) { return n <= 0 ? 0 : n == 1 ? 1 : fib(n - 1) + fib(n - 2); } static jlong fibNR(JNIEnv *env, jclass clazz, jlong n) { __android_log_print(ANDROID_LOG_DEBUG, "FibLib.c", "fibNR(%lld)", n); return fib(n); } static jlong fibNI(JNIEnv *env, jclass clazz, jlong n) { jlong previous = -1; jlong result = 1; jlong i; __android_log_print(ANDROID_LOG_DEBUG, "FibLib.c", "fibNI(%lld)", n); for (i = 0; i <= n; i++) { jlong sum = result + previous; previous = result; result = sum; } return result; } static JNINativeMethod method_table[] = { { "fibNR", "(J)J", (void *) fibNR }, { "fibNI", "(J)J", (void *) fibNI } }; } using namespace com_marakana_android_fibonaccinative; extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) { JNIEnv* env; if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { return JNI_ERR; } else { jclass clazz = env->FindClass("com/marakana/android/fibonaccinative/FibLib"); if (clazz) { jint ret = env->RegisterNatives(clazz, method_table, sizeof(method_table) / sizeof(method_table[0])); env->DeleteLocalRef(clazz); return ret == 0 ? JNI_VERSION_1_6 : JNI_ERR; } else { return JNI_ERR; } } } Most of the Android’s JNI-based shared libraries are built using this, "alternative", approach where the functions are pre-registered.
  • 19. Fibonacci - Makefile We need a AAnnddrrooiidd..mmkk makefile, which will be used by NDK to compile our JNI code into a shared library: FFiibboonnaacccciiNNaattiivvee//jjnnii//AAnnddrrooiidd..mmkk # Defines the root to all other relative paths # The macro function my-dir, provided by the build system, # specifies the path of the current directory (i.e. the # directory containing the Android.mk file itself) LOCAL_PATH := $(call my-dir) # Clear all LOCAL_XXX variables with the exception of # LOCAL_PATH (this is needed because all variables are global) include $(CLEAR_VARS) # List all of our C files to be compiled (header file # dependencies are automatically computed) LOCAL_SRC_FILES := com_marakana_android_fibonaccinative_FibLib.c # The name of our shared module (this name will be prepended # by lib and postfixed by .so) LOCAL_MODULE := com_marakana_android_fibonaccinative_FibLib # We need to tell the linker about our use of the liblog.so LOCAL_LDLIBS += -llog # Collects all LOCAL_XXX variables since "include $(CLEAR_VARS)" # and determines what to build (in this case a shared library) include $(BUILD_SHARED_LIBRARY) It’s easiest to copy the AAnnddrrooiidd..mmkk file from another (sample) project and adjust LLOOCCAALL__SSRRCC__FFIILLEESS and LLOOCCAALL__MMOODDUULLEE as necessary See //ppaatthh//ttoo//nnddkk--iinnssttaallllaattiioonn--ddiirr//ddooccss//AANNDDRROOIIDD--MMKK..hhttmmll for the complete reference of Android make files (build system)
  • 20. Fibonacci - Compile Our Shared Module Finally, from the root of our project (i.e. FFiibboonnaacccciiNNaattiivvee//), we run nnddkk--bbuuiilldd to build our code into a shared library (FFiibboonnaacccciiNNaattiivvee//lliibbss//aarrmmeeaabbii//lliibbccoomm__mmaarraakkaannaa__aannddrrooiidd__ffiibboonnaaccccii__FFiibbLLiibb..$ ndk-build Compile thumb : com_marakana_android_fibonaccinative_FibLib <= com_marakana_android_fibonaccinative_FibLib.c SharedLibrary : libcom_marakana_android_fibonaccinative_FibLib.so Install : libcom_marakana_android_fibonaccinative_FibLib.so => libs/armeabi/libcom_marakana_android_fibonaccinative_FibLib.so The command nnddkk--bbuuiilldd comes from the NDK’s installation directory (e.g. //ppaatthh//ttoo//aannddrrooiidd--nnddkk--rr55bb), so it’s easiest if we add this directory to our PPAATTHH. On Windows, older version of NDK required Cygwin (a Unix-like environment and command-line interface for Microsoft Windows) to provide "shell" (bash) and "make" (gmake) to nnddkk--bbuuiilldd. Controlling CPU Application Binary Interface (ABI) By default, the NDK will generate machine code for the aarrmmeeaabbii - i.e. ARMv5TE with support for Thumb-1. In addition to ARMv5, NDK also comes with the toolchains necessary to build code for: ARMv7-A (including hardware FPU/VFPv3-D16, Thumb-2, VFPv3-D32/ThumbEE, and SIMD/NEON) x86 (as of r6) MIPS (as of r8) We can explicitly select ABIs using AAPPPP__AABBII variable: $ ndk-build APP_ABI=armeabi $ ndk-build APP_ABI=armeabi-v7a $ ndk-build APP_ABI=x86 $ ndk-build APP_ABI=mips We can also combine them, thereby building a "fat binary": $ ndk-build "APP_ABI=armeabi armeabi-v7a x86 mips" $ ndk-build APP_ABI=all Finally, we can also persist our choice of ABI, by saving AAPPPP__AABBII in a AApppplliiccaattiioonn..mmkk file: jjnnii//AApppplliiccaattiioonn..mmkk: APP_ABI := all Each ABI-specific library, gets packaged as lliibb//<<AABBII>>//lliibb<<nnaammee>>..ssoo inside our APK.
  • 21. Upon installation, the library that best matches the native ABI of the device it will execute on, will get copied to /data/data/<package>/lliibb//lliibb<<nnaammee>>..ssoo. To remove all generated binaries, run: $ ndk-build clean Clean: com_marakana_android_fibonaccinative_FibLib [armeabi] Clean: stdc++ [armeabi]
  • 22. Fibonacci - Client We can now build the "client" of our library (in this case a simple activity) to use our FFiibbLLiibb library. Fibonacci - String Resources FFiibboonnaacccciiNNaattiivvee//rreess//vvaalluueess//ssttrriinnggss..xxmmll <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Get Your Fibonacci Numbers Here!</string> <string name="fibJR">fibJR</string> <string name="fibJI">fibJI</string> <string name="fibNR">fibNR</string> <string name="fibNI">fibNI</string> <string name="app_name">FibonacciNative</string> <string name="button">Get Fibonacci Result</string> Fibonacci - User Interface (Layout) Fibonacci Native Main Layout FFiibboonnaacccciiNNaattiivvee//rreess//llaayyoouutt//mmaaiinn..xxmmll </resources> <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <!-- This is just a simple title ("Get Your Fibonacci Here!") --> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/hello" android:textSize="25sp" /> <!-- This is the entry box for our number "n" --> <EditText
  • 23. android:id="@+id/input" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:gravity="right" android:inputType="number" > <requestFocus /> </EditText> <!-- This radio group allows the user to select the fibonacci implementation type --> <RadioGroup android:id="@+id/type" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioButton android:id="@+id/type_fib_jr" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/fibJR" /> <RadioButton android:id="@+id/type_fib_ji" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/fibJI" /> <RadioButton android:id="@+id/type_fib_nr" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/fibNR" /> <RadioButton android:id="@+id/type_fib_ni" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/fibNI" /> </RadioGroup> <!-- This button allows the user to trigger fibonacci calculation --> <Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/button" /> <!-- This is the output area for the fibonacci result --> <TextView android:id="@+id/output" android:layout_width="match_parent"
  • 24. android:layout_height="match_parent" android:gravity="center" android:textSize="20sp" /> </LinearLayout> Fibonacci - FFiibboonnaacccciiAAccttiivviittyy FFiibboonnaacccciiNNaattiivvee//ssrrcc//ccoomm//mmaarraakkaannaa//aannddrrooiidd//ffiibboonnaacccciinnaattiivvee//FFiibboonnaacccciiAAccttiivviittyy..jjaavvaa package com.marakana.android.fibonaccinative; import android.app.Activity; import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Bundle; import android.os.SystemClock; import android.text.TextUtils; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.RadioGroup; import android.widget.TextView; public class FibonacciActivity extends Activity implements OnClickListener { private EditText input; private RadioGroup type; private TextView output; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.input = (EditText) super.findViewById(R.id.input); this.type = (RadioGroup) super.findViewById(R.id.type); this.output = (TextView) super.findViewById(R.id.output); Button button = (Button) super.findViewById(R.id.button); button.setOnClickListener(this); } public void onClick(View view) { String s = this.input.getText().toString(); if (TextUtils.isEmpty(s)) { return; } final ProgressDialog dialog = ProgressDialog.show(this, "", "Calculating...", true); final long n = Long.parseLong(s); new AsyncTask<Void, Void, String>() { @Override
  • 25. protected String doInBackground(Void... params) { long result = 0; long t = SystemClock.uptimeMillis(); switch (FibonacciActivity.this.type.getCheckedRadioButtonId()) { case R.id.type_fib_jr: result = FibLib.fibJR(n); break; case R.id.type_fib_ji: result = FibLib.fibJI(n); break; case R.id.type_fib_nr: result = FibLib.fibNR(n); break; case R.id.type_fib_ni: result = FibLib.fibNI(n); break; } t = SystemClock.uptimeMillis() - t; return String.format("fib(%d)=%d in %d ms", n, result, t); } @Override protected void onPostExecute(String result) { dialog.dismiss(); FibonacciActivity.this.output.setText(result); } }.execute(); } }
  • 26. Fibonacci - Result Fibonacci Native Result
  • 27. NDK’s Stable APIs The header files for NDK stable APIs are available at /path/to/ndk/platforms/<android-platform>/<arch-nnaammee>>//uussrr//iinncclluuddee.
  • 28. Android-specific Log Support Include <<aannddrrooiidd//lloogg..hh>> to access various functionality that can be used to send log messages to the kernel (i.e. logcat buffers) from our native code Requires that our code be linked to //ssyysstteemm//lliibb//lliibblloogg..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== --lllloogg in our AAnnddrrooiidd..mmkk file
  • 29. ZLib Compression Library Include <<zzlliibb..hh>> and <<zzccoonnff..hh>> to access ZLib compression library See hhttttpp::////wwwwww..zzlliibb..nneett//mmaannuuaall..hhttmmll for more info on ZLib Requires that our code be linked to //ssyysstteemm//lliibb//lliibbzz..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== --llzz in our AAnnddrrooiidd..mmkk file
  • 30. The OpenGL ES 1.x Library Include <<GGLLEESS//ggll..hh>> and <<GGLLEESS//gglleexxtt..hh>> to access OpenGL ES 1.x rendering calls from native code The "1.x" here refers to both versions 1.0 and 1.1 Using 1.1 requires OpenGL-capable GPU Using 1.0 is universally supported since Android includes software renderer for GPU-less devices Requires that we include <<uusseess--ffeeaattuurree>> tag in our manifest file to indicate the actual OpenGL version that we expect Requires that our code be linked to //ssyysstteemm//lliibb//lliibbGGLLEESSvv11__CCMM..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== -- llGGLLEESSvv11__CCMM..ssoo in our AAnnddrrooiidd..mmkk file Since API 4 (Android 1.6)
  • 31. The OpenGL ES 2.0 Library Include <<GGLLEESS22//ggll22..hh>> and <<GGLLEESS22//ggll22eexxtt..hh>> to access OpenGL ES 2.0 rendering calls from native code Enables the use of vertex and fragment shaders via the GLSL language Since not all devices support OpenGL 2.0, we should include <<uusseess--ffeeaattuurree>> tag in our manifest file to indicate this requirement Requires that our code be linked to //ssyysstteemm//lliibb//lliibbGGLLEESSvv22..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== -- llGGLLEESSvv22..ssoo in our AAnnddrrooiidd..mmkk file Since API 4 (Android 2.0)
  • 32. The jjnniiggrraapphhiiccss Library Include <<aannddrrooiidd//bbiittmmaapp..hh>> to reliably access the pixel buffers of Java bitmap objects from native code Requires that our code be linked to //ssyysstteemm//lliibb//lliibbjjnniiggrraapphhiiccss..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== -- lljjnniiggrraapphhiiccss in our AAnnddrrooiidd..mmkk file Since API 8 (Android 2.2)
  • 33. The OpenSL ES native audio Library Include <<SSLLEESS//OOppeennSSLLEESS..hh>> and <<SSLLEESS//OOppeennSSLLEESS__PPllaattffoorrmm..hh>> to perform audio input and output from native code Based on Khronos Group OpenSL ES™ 1.0.1 Requires that our code be linked to //ssyysstteemm//lliibb//lliibbOOppeennSSLLEESS..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== -- llOOppeennSSLLEESS in our AAnnddrrooiidd..mmkk file Since API 9 (Android 2.3)
  • 34. The Android native application APIs Makes it possible to write our entire application in native code Mainly added for gaming Our code still depends on the Dalvik VM since most of the platform features are managed in the VM and accessed via JNI (Native → Java) Include <android/nnaattiivvee__aaccttiivviittyy..hh>> to write an Android activity (with its life-cycle callbacks) in native code A native activity would serve as the main entry point into our native application Include <<aannddrrooiidd//llooooppeerr..hh>>, <<aannddrrooiidd//iinnppuutt..hh>>, <<aannddrrooiidd//kkeeyyccooddeess..hh>>, and <<aannddrrooiidd//sseennssoorr..hh>> to listen to input events and sensors directly from native code Include <<aannddrrooiidd//rreecctt..hh>>, <<aannddrrooiidd//wwiinnddooww..hh>>, <<aannddrrooiidd//nnaattiivvee__wwiinnddooww..hh>>, and <<aannddrrooiidd//nnaattiivvee__wwiinnddooww__jjnnii..hh>> for window management from native code Includes ability to lock/unlock the pixel buffer to draw directly into it Include <<aannddrrooiidd//ccoonnffiigguurraattiioonn..hh>>, <<aannddrrooiidd//aasssseett__mmaannaaggeerr..hh>>, <<aannddrrooiidd//ssttoorraaggee__mmaannaaggeerr..hh>>, and <<aannddrrooiidd//oobbbb..hh>> for direct access to the assets embedded in our ..aappkk files Opaque Binary Blob (OBB) files All access is read-only Requires that our code be linked to lliibbaannddrrooiidd..ssoo with LLOOCCAALL__LLDDLLIIBBSS ++== --llaannddrrooiidd in our AAnnddrrooiidd..mmkk file Since API 9 (Android 2.3) With the exception of the libraries listed above, the native system libraries in the Android platform are not considered "stable" and may change in future platform versions. Unless our library is being built for a specific Android ROM, we should only make use of the stable libraries provided by the NDK. All the header files are available under: //ppaatthh//ttoo//nnddkk--iinnssttaallllaattiioonn--ddiirr//ppllaattffoorrmmss//aannddrrooiidd-- 99//aarrcchh--aarrmm//uussrr//iinncclluuddee// See //ppaatthh//ttoo//nnddkk--iinnssttaallllaattiioonn--ddiirr//ddooccss//SSTTAABBLLEE--AAPPIISS..hhttmmll for the complete reference of NDK’s stable APIs.
  • 35. Lab: NDK The objective of this lab is to test your understanding of JNI and NDK. We will do so by adding JNI code to an existing application. 1. Start by importing LogNative application into Eclipse 1. Menu Bar → File → Import… → Git → Projects from Git → Next > 2. Under Select Repository Source select URI → Next > 3. Under Source Git Repository → Location → URI: enter https://github.com/marakana/LLooggNNaattiivvee..ggiitt → Next > 4. Under Branch Selection, leave all branches selected (checked) → Next > 5. Under Local Destination → Destination specify directory of your choice (e.g. ~~//aannddrrooiidd//wwoorrkkssppaaccee//LLooggNNaattiivvee) → Next > 6. Under Select a wizard to use for importing projects, leave Wizard for project import as Import existing projects → Next > 7. Under Import Projects → Projects, leave LogNative as selected (checked) → Finish This project can also be downloaded as a ZIP file 2. Examine and test your project in Eclipse 1. Run the application on a device/emulator 2. Enter some tag and message to log, click on the Log button and observe via aaddbb llooggccaatt that your message get logged (assuming Java was selected) 3. Implement ccoomm..mmaarraakkaannaa..aannddrrooiidd..llooggnnaattiivvee..LLooggLLiibb..llooggNN((iinntt pprriioorriittyy,, SSttrriinngg ttaagg,, SSttrriinngg mmssgg)) in C 1. Mark the method as nnaattiivvee 2. Remove its body 3. Extract its function prototype into a C header file (hint: jjaavvaahh) 4. Implement the function by taking advantage of <<aannddrrooiidd//lloogg..hh>> (i.e.
  • 36. /ssyysstteemm//lliibb//lliibblloogg..ssoo) 5. Provide the makefile(s) 4. Build (via nnddkk--bbuuiilldd) 5. Run your application 6. Test by selecting NNaattiivvee in the UI and checking that the log tag/message shows up in aaddbb llooggccaatt 7. As a bonus: 1. Throw jjaavvaa..llaanngg..NNuullllPPooiinntteerrEExxcceeppttiioonn if ttaagg or mmssgg are null 2. Throw jjaavvaa..llaanngg..IIlllleeggaallAArrgguummeennttEExxcceeppttiioonn if pprriioorriittyy is not one of the allowed types or if ttaagg or mmssgg are empty Don’t forget to convert ttaagg and mmssgg strings from the Java format (jjssttrriinngg) to native format (cchhaarr **) before trying to use them in iinntt ____aannddrrooiidd__lloogg__wwrriittee((iinntt pprriioo,, ccoonnsstt cchhaarr **ttaagg,, ccoonnsstt cchhaarr **tteexxtt)). Be sure to free the native strings before returning from the native method. Finally, don’t forget to tell the linker about your use of the log library. The solution is provided: As a ZIP archive: https://github.com/marakana/LogNative/zipball/solution By Git: ggiitt cclloonnee https://github.com/marakana/LogNative.git --bb ssoolluuttiioonn
  • 37. Summary of NDK Module In this module, you learned how Android uses JNI to bridge between the world of Java and the native code. You also learned how NDK makes the process of working with JNI simpler by providing tools and framework for developing native libraries as well as packaging them with the app. Thank you! Marko Gargenta & Marakana Team @MarkoGargenta Special thanks to Aleksandar (Sasa) Gargenta as well as the rest of Marakana team for research related to NDK. Slides & video of this presentation is available at Marakana.com Yamba source code is available at https://github.com/marakana/ (c) Marakana.com