Post on 15-Jul-2015
Android NDK Intoduction
Rahul Tripathi
Agenda
The Android Native Development Kit (NDK)
NDK Info
What , Why , Why not ?
Requirement Tools & Installation of NDK
Developing an ADD application that uses the NDK
Final Output
NDK info Android Native Development Kit (Android NDK)
Developer(s) - Google
Initial release - June 2009; 5 years ago
Stable release -
10d / December 2014; 2 months ago
Written in- C and C++
Operating system- Cross-platform
Available in- English
Type- IDE, SDK
Website-
developer.android.com/tools/sdk/ndk/index.ht
ml
Native Development Kit What , Why ,Why Not?
The NDK is a toolset that allows you to implement parts of your app using native-code languages such as C and C++.
What is it?
Build scripts/toolkit to incorporate native code in Android * apps via the Java NativeInterface (JNI)
Why use it?
Performancee.g., complex algorithms, multimedia applications, games
Why not use it?Performance improvement isn’t alwaysguaranteed, in contrary to the addedcomplexity
NDK Build Process
1. 3.
2.
Dalvik Application
Android NDK Application
What is JNI ?
Android is put together of about equal part Java and C.
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.
NDK - System and Software Requirements
The Android SDK
A complete Android SDK installation (including all dependencies) is required.
Android 1.5 SDK or later version is required.
Supported operating systems
Windows XP (32-bit) or Vista (32- or 64-bit)
Mac OS X 10.4.8 or later (x86 only)
Linux (32 or 64-bit; Ubuntu 8.04, or other Linux distributions)
Required development tools
For all development platforms, GNU Make 3.81 or later is required. Earlier versions of GNU Make might work but have not been tested.
A recent version of awk (either GNU Awk or Nawk) is also required.
For Windows, Cygwin 1.7 or higher is required. The NDK will not work with Cygwin 1.5 installations.
How to Install NDK
On Linux and Mac OS X (Darwin):
Download the appropriate package from this page.
Open a terminal window.
Go to the directory to which you downloaded the package.
Run chmod a+x on the downloaded package.
Execute the package. For example:
ndk$ chmod a+x android-ndk-r10c-darwin-x86_64.binndk$ ./android-ndk-r10c-darwin-x86_64.bin
The folder containing the NDK extracts itself.
Note that you can also use a program like 7z to extract the package.
On Windows:
Download the appropriate package from this page.
Navigate to the folder to which you downloaded the package.
Double-click the downloaded file. The folder containing the NDK extracts itself.
Configure NDKNow Open Eclipse and Configure NDK .
Go to window Option on the top.
Click Preference :
In Android ----> Select NDK ----> Give the path of your
NDK Which you have Extracted by Terminal .
(Note : Please Don't Make any Space in Contains Path Folder)
You have to download For NDK ..
Click Help : Install New Software ----> Select Release / Juno Link ..
Now Select
C/C++ GCC Cross Compiler Support
C/C++ GDB Hardware Debugging
Now Finish ....
Now Start With Project
Create a Android Application Project -->
Right Click on project -->
Select Android tool -->
Add Native Support -->
NDK Project Explorer in Eclipse
Jni FolderC/C++ File
Android.mk file
Application.mk file
After do that, your project has a folder called “jni”. Inside this folder, you have the
Android.mk file, which goes your library configuration for the compiler. And there is a
another file with .cpp (C++) extension, this is where your native code goes.You have to
create A file in side jni folder Application.mk which describe which native 'modules' (i.e.
static/shared libraries) are needed by your application.
Now Here is .Java , .MK
Android.MK & Application.MK
Android.mk :- sub-makefile that describes the C++
static libraries and *.so files you want to build.
Application.mk :- contains settings that apply to
all the C/C++ code (processor type, API level,
standard library, project-wide compiler options)
Calling Native From Java
• Create an activity .JAVA .
• Write A native method in side that Activity .
• JNI program uses a static initializer to load a shared library
("myjni.dll" in Windows or "libmyjni.so" in Ubuntu). It
declares a native method.
Create A JNI .h Header File Using "Javah"Generating C/C++ Header File using "javah" Utility
Now We Have to Create Header File (.h) under JNI Folder .
Using Terminal/Cygwin
Go to your bin directory using cd command .. On Terminal/Cygwin .
No.....
You Can Create Manual Javah Builder ...
Header file for C/C++ Programs
Run javah utility on the class file to create a header file for C/C++ programs.
C/C++ Implementation Write Your C/C++ Code
JNI environment interface function
What is Javah ?
Java is bundled with JDK .it Has command to generate c header file from a
java class. this file provide connective glue that allow your java and c code to
intract.
How to find your Javah from Terminal :
Which Javah
Setting up Automatic NDK Builds in
Eclipse Start by right clicking on your android project and select Properties. In the resulting
dialog, choose the Builders entry in the list to the left and press the New... button:
Here We Go .......... NDK Build
NDK Build Finish ....
Generated
Shared Library .So File
1. The Android OS loads the Java code and starts
executing it
2. The Java code calls System.loadLibrary() to load
a native library.
3. The Java code starts calling functions from the
native code.
Final Output
Thank You