SlideShare une entreprise Scribd logo
1  sur  28
Android NDK
NDK Overview
•
•
•
•
•
•

Allows to run C/C++ programs
Used for performance critical applications
Executed natively without interpretation
Can call and be called from Java
Uses JNI
Used in many libraries like
graphics(OpenGLES), audio etc and other
places where underlying processor is accessed
NDK Overview
NDK Overview
•
•
•
•
•
•

Install NDK
Install Cygwin
Create a basic project : add C/C++ files
Generate the headers
Generate library (.so) using ndk­build
Load the library
Step 1: Installing the Android NDK
• Android NDK itself and place it on our
filesystem.
• Can get NDK from the official Android site
• Be sure that there are no spaces in the path.
• Extract it to C:,
• so the path is C:android­ndk­r6.
Step 1: Installing the Android NDK
http://developer.android.com/tools/sdk/ndk/index.html

NDK is download to local dir C:Softwareandroid­ndk­r9­windows­x86android­ndk­r9
Step 2: Installing Cygwin
• Android is Linux based, and thus it is no
surprise that when build native code for it,
need some Linux tools.
• On Windows, NDK supports Cygwin 1.7.x and
above.
• It’s just a set of software that emulates Unix
environment on Windows
• get Cygwin, go to cygwin.com
Step 2: Install Cygwin
• Cygwin’s setup.exe will download and run..

• Choose Install from Internet, then click Next, then
choose the installation directory
(be sure to choose a directory path that contains no spaces in it) like –
C:/cygwin
Step 2: Installing Cygwin

DEVREL Branch
Step 3: Making a Basic NDK App
• The general idea of using NDK in apps is to
put your native pieces of code into libraries
that you can then consume from the Java
code.
Step 3: Making a Basic NDK App
Create Activity similar to
other projects

Right click on the "SampleNDK"
project­> Select "New"­> Select
"Folder"­>Type "jni"

Add Android.mk and
native.c
Step 4: Generate Headers
• Check if class files are generated in this dir
workspaceNDKSamplebinclasses
• Issue javah command from this dir
javah ­jni com.samplendk.SampleNDKActivity

Make sure classpath includes current dir + android sdk path
Step 4: Generate Headers
Step 5
Create Library (.so) using NDK Build
• create a binary library from the C source that we
wrote,
• use a combination of Cygwin and Android NDK
tools.
• Launch the Cygwin console and cd to project dir
• the command line is: ndk­build

/cygdrive/c/Software/android­ndk­r9­
windows­x86/android­ndk­r9/ndk­build
Create Library (.so) using NDK Build
Create Library (.so) using NDK Build
• a successful run of the ndk­build tool will
create an .so file in a new folder called libs.
• The .so file is the binary library that will be
included into the application .apk package
and will be available for the Java code of the
app to link to.
Step 6 : Loading the library (.so)
public class Ndk_testActivity extends Activity {
// load the library ­ name matches jni/Android.mk
static {
System.loadLibrary("ndkfoo");
}
// declare the native code function ­ must match ndk_test.c private native
String invokeNativeFunction();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// this is where we call the native code
String hello = invokeNativeFunction();
new AlertDialog.Builder(this).setMessage(hello).show();
}
}
Backup slides
All about JNI
• Java Native Interface (JNI)
• The JNI is a part of the Java platform,
programmers can address interoperability
issues once, and expect their solution to work
with all implementations of the Java platform.
“Applications written in the Java programming
language as well as in native (C, C++, etc.)
programming languages.”
Java Platform do
• Java platforms are commonly deployed on top of
a host environment.
For example, the Java Runtime Environment (JRE) is
a Sun product that supports the Java platform on
existing operating systems such as Solaris and
Windows.
• The Java platform offers a set of features that
applications can rely on independent of the
underlying host environment.
Role of the JNI
•

The JNI is a powerful feature that allows you to take advantage of the Java
platform, but still utilize code written in other languages. As a part of the Java
virtual machine implementation, the JNI is a two­way interface that allows Java
applications to invoke native code and vice versa. Figure ­
JNI ­ Two­way interface
• As a two­way interface, the JNI can support two types of native
code:
­ Native libraries and
­ Native applications.
­ Applications call native methods in the same way that they call
methods implemented in the Java programming language.
­ An invocation interface :
Native applications can link with a native library that implements
the Java virtual machine, and then ..
Use the invocation interface to execute software components
written in the Java programming language.
For example, a web browser written in C can execute downloaded
applets in an embedded Java virtual machine implemention.
When the JNI becomes useful ?
The following scenarios:
• Targeted Java API might not support certain host­dependent
features needed by an application.
• May want to access an existing native library and are not willing to
pay for the overhead of copying and transmitting data across
different processes.
• Loading a native library into the existing process hosting the
application requires less system resources than starting a new
process and loading the library into that process.
• If a 3D­intensive application spends most of its time in graphics
rendering, you may find it necessary to write the core portion of a
graphics library in assembly code to achieve maximum
performance. Like, Games, Ex­H/W ….
• Have role on the JDK
­ The JNI was first supported in JDK release 1.1. Internally.
­ Java 'jdk' is the 'Java Development Kit' and it allows you to
compile Java programs.
How to code with JNI
Android.mk files
We'll leave most of the file as it is.
• LOCAL_PATH ­ this line should be left as it is since your source file
('example.c') is in the same directory as the 'Android.mk' file.
• include $(CLEAR_VARS) ­ this line should be left as it is. It is
required.
• LOCAL_MODULE ­ this line should be changed to match your
module name. For this tutorial we'll change it to 'example'. This
name should not have any spaces in it as it will be made into the
actual library's name ('libexample.so' for us).
• LOCAL_CFLAGS ­ This line can be left as it is. It is for compiler flags.
• LOCAL_SRC_FILES ­ this line should be changed to 'example.c' since
that's our source file.
• LOCAL_LDLIBS ­ leave this the same.
• include $(BUILD_SHARED_LIBRARY) ­ leave this the same.
How to configure a script for making a
library and an Android.mk file
• Configure script to generate the
– config.h and config.mak files.
– http://code.google.com/p/awesomeguy/wiki/JNITuto
rial#Overview
– CV Ready + Cygwin Devel Branch + NDK set
– YA cam recorder + ffmpeg test project for making
ffmpeg library + Color Conversion yuv2rgb
– halfninja­android­ffmpeg­x264­04b62f2 need ffmpeg
library
– Test the project + ffmpeg tutorial search
���������������������������������������������������������������������������
���������������������������������������������������������������������������������
�����������������������������������������������������

Contenu connexe

Tendances

Android ndk - Introduction
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - IntroductionRakesh Jha
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Paris Android User Group
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineChun-Yu Wang
 
Android Developer Meetup
Android Developer MeetupAndroid Developer Meetup
Android Developer MeetupMedialets
 
LinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik BytecodeLinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik BytecodeAlain Leon
 
Understanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer toolUnderstanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer toolGabor Paller
 
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019corehard_by
 
How to reverse engineer Android applications
How to reverse engineer Android applicationsHow to reverse engineer Android applications
How to reverse engineer Android applicationshubx
 
Reverse engineering android apps
Reverse engineering android appsReverse engineering android apps
Reverse engineering android appsPranay Airan
 
Build and run applications in a dockerless kubernetes world
Build and run applications in a dockerless kubernetes worldBuild and run applications in a dockerless kubernetes world
Build and run applications in a dockerless kubernetes worldJorge Morales
 
ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...
ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...
ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...ZongXian Shen
 
Google ART (Android RunTime)
Google ART (Android RunTime)Google ART (Android RunTime)
Google ART (Android RunTime)Niraj Solanke
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0Michael Vorburger
 
Entwicker camp2007 calling-the-c-api-from-lotusscript
Entwicker camp2007 calling-the-c-api-from-lotusscriptEntwicker camp2007 calling-the-c-api-from-lotusscript
Entwicker camp2007 calling-the-c-api-from-lotusscriptBill Buchan
 

Tendances (20)

Android ndk
Android ndkAndroid ndk
Android ndk
 
Android NDK
Android NDKAndroid NDK
Android NDK
 
Android ndk - Introduction
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - Introduction
 
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
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machine
 
Android Developer Meetup
Android Developer MeetupAndroid Developer Meetup
Android Developer Meetup
 
PIC your malware
PIC your malwarePIC your malware
PIC your malware
 
Android NDK: Entrando no Mundo Nativo
Android NDK: Entrando no Mundo NativoAndroid NDK: Entrando no Mundo Nativo
Android NDK: Entrando no Mundo Nativo
 
LinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik BytecodeLinkedIn - Disassembling Dalvik Bytecode
LinkedIn - Disassembling Dalvik Bytecode
 
Understanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer toolUnderstanding the Dalvik bytecode with the Dedexer tool
Understanding the Dalvik bytecode with the Dedexer tool
 
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
 
How to reverse engineer Android applications
How to reverse engineer Android applicationsHow to reverse engineer Android applications
How to reverse engineer Android applications
 
Reverse engineering android apps
Reverse engineering android appsReverse engineering android apps
Reverse engineering android apps
 
Build and run applications in a dockerless kubernetes world
Build and run applications in a dockerless kubernetes worldBuild and run applications in a dockerless kubernetes world
Build and run applications in a dockerless kubernetes world
 
ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...
ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...
ProbeDroid - Crafting Your Own Dynamic Instrument Tool on Android for App Beh...
 
Reverse Engineering Android Application
Reverse Engineering Android ApplicationReverse Engineering Android Application
Reverse Engineering Android Application
 
Google ART (Android RunTime)
Google ART (Android RunTime)Google ART (Android RunTime)
Google ART (Android RunTime)
 
OpenDaylight Developer Experience 2.0
 OpenDaylight Developer Experience 2.0 OpenDaylight Developer Experience 2.0
OpenDaylight Developer Experience 2.0
 
Deep Dive into the AOSP
Deep Dive into the AOSPDeep Dive into the AOSP
Deep Dive into the AOSP
 
Entwicker camp2007 calling-the-c-api-from-lotusscript
Entwicker camp2007 calling-the-c-api-from-lotusscriptEntwicker camp2007 calling-the-c-api-from-lotusscript
Entwicker camp2007 calling-the-c-api-from-lotusscript
 

Similaire à NDK Programming in Android

PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptRajeshSukte1
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptCDSukte
 
Writing Android Libraries
Writing Android LibrariesWriting Android Libraries
Writing Android Librariesemanuelez
 
Android Architecture design programming with java
Android Architecture design programming with javaAndroid Architecture design programming with java
Android Architecture design programming with javassuser471dfb
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operatorkamal kotecha
 
Introduction to java
Introduction to java Introduction to java
Introduction to java Java Lover
 
Notes of java first unit
Notes of java first unitNotes of java first unit
Notes of java first unitgowher172236
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language Hitesh-Java
 
Session 02 - Elements of Java Language
Session 02 - Elements of Java LanguageSession 02 - Elements of Java Language
Session 02 - Elements of Java LanguagePawanMM
 
Intoduction to java
Intoduction to javaIntoduction to java
Intoduction to javajalinder123
 
Dr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to javaDr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to javaDrRajeshreeKhande
 
Java in a world of containers
Java in a world of containersJava in a world of containers
Java in a world of containersDocker, Inc.
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Arun Gupta
 

Similaire à NDK Programming in Android (20)

Android ndk
Android ndkAndroid ndk
Android ndk
 
109842496 jni
109842496 jni109842496 jni
109842496 jni
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
 
Writing Android Libraries
Writing Android LibrariesWriting Android Libraries
Writing Android Libraries
 
Android Architecture design programming with java
Android Architecture design programming with javaAndroid Architecture design programming with java
Android Architecture design programming with java
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Notes of java first unit
Notes of java first unitNotes of java first unit
Notes of java first unit
 
JAVA First Day
JAVA First DayJAVA First Day
JAVA First Day
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
 
Session 02 - Elements of Java Language
Session 02 - Elements of Java LanguageSession 02 - Elements of Java Language
Session 02 - Elements of Java Language
 
Intoduction to java
Intoduction to javaIntoduction to java
Intoduction to java
 
Dr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to javaDr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to java
 
Introduction to JAVA
Introduction to JAVAIntroduction to JAVA
Introduction to JAVA
 
Java in a world of containers
Java in a world of containersJava in a world of containers
Java in a world of containers
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
 

Plus de Arvind Devaraj

Deep learning for NLP and Transformer
 Deep learning for NLP  and Transformer Deep learning for NLP  and Transformer
Deep learning for NLP and TransformerArvind Devaraj
 
NLP using transformers
NLP using transformers NLP using transformers
NLP using transformers Arvind Devaraj
 
Career options for CS and IT students
Career options for CS and IT studentsCareer options for CS and IT students
Career options for CS and IT studentsArvind Devaraj
 
Static Analysis of Computer programs
Static Analysis of Computer programs Static Analysis of Computer programs
Static Analysis of Computer programs Arvind Devaraj
 
Yourstory Android Workshop
Yourstory Android WorkshopYourstory Android Workshop
Yourstory Android WorkshopArvind Devaraj
 
Android High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptAndroid High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptArvind Devaraj
 
OpenGLES Android Graphics
OpenGLES Android GraphicsOpenGLES Android Graphics
OpenGLES Android GraphicsArvind Devaraj
 
AIDL - Android Interface Definition Language
AIDL  - Android Interface Definition LanguageAIDL  - Android Interface Definition Language
AIDL - Android Interface Definition LanguageArvind Devaraj
 
Google Cloud Messaging
Google Cloud MessagingGoogle Cloud Messaging
Google Cloud MessagingArvind Devaraj
 
OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android Arvind Devaraj
 
Sorting (introduction)
 Sorting (introduction) Sorting (introduction)
Sorting (introduction)Arvind Devaraj
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)Arvind Devaraj
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open glArvind Devaraj
 
Signal Processing Introduction using Fourier Transforms
Signal Processing Introduction using Fourier TransformsSignal Processing Introduction using Fourier Transforms
Signal Processing Introduction using Fourier TransformsArvind Devaraj
 

Plus de Arvind Devaraj (20)

Deep learning for NLP and Transformer
 Deep learning for NLP  and Transformer Deep learning for NLP  and Transformer
Deep learning for NLP and Transformer
 
NLP using transformers
NLP using transformers NLP using transformers
NLP using transformers
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Career hunt pitch
Career hunt pitchCareer hunt pitch
Career hunt pitch
 
Career options for CS and IT students
Career options for CS and IT studentsCareer options for CS and IT students
Career options for CS and IT students
 
Careerhunt ebook
Careerhunt ebookCareerhunt ebook
Careerhunt ebook
 
Static Analysis of Computer programs
Static Analysis of Computer programs Static Analysis of Computer programs
Static Analysis of Computer programs
 
Hyperbook
HyperbookHyperbook
Hyperbook
 
Yourstory Android Workshop
Yourstory Android WorkshopYourstory Android Workshop
Yourstory Android Workshop
 
Android High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptAndroid High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscript
 
OpenGLES Android Graphics
OpenGLES Android GraphicsOpenGLES Android Graphics
OpenGLES Android Graphics
 
Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
 
AIDL - Android Interface Definition Language
AIDL  - Android Interface Definition LanguageAIDL  - Android Interface Definition Language
AIDL - Android Interface Definition Language
 
Google Cloud Messaging
Google Cloud MessagingGoogle Cloud Messaging
Google Cloud Messaging
 
OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android
 
Operating system
Operating systemOperating system
Operating system
 
Sorting (introduction)
 Sorting (introduction) Sorting (introduction)
Sorting (introduction)
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open gl
 
Signal Processing Introduction using Fourier Transforms
Signal Processing Introduction using Fourier TransformsSignal Processing Introduction using Fourier Transforms
Signal Processing Introduction using Fourier Transforms
 

Dernier

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Dernier (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

NDK Programming in Android

  • 2. NDK Overview • • • • • • Allows to run C/C++ programs Used for performance critical applications Executed natively without interpretation Can call and be called from Java Uses JNI Used in many libraries like graphics(OpenGLES), audio etc and other places where underlying processor is accessed
  • 4. NDK Overview • • • • • • Install NDK Install Cygwin Create a basic project : add C/C++ files Generate the headers Generate library (.so) using ndk­build Load the library
  • 5. Step 1: Installing the Android NDK • Android NDK itself and place it on our filesystem. • Can get NDK from the official Android site • Be sure that there are no spaces in the path. • Extract it to C:, • so the path is C:android­ndk­r6.
  • 6. Step 1: Installing the Android NDK http://developer.android.com/tools/sdk/ndk/index.html NDK is download to local dir C:Softwareandroid­ndk­r9­windows­x86android­ndk­r9
  • 7. Step 2: Installing Cygwin • Android is Linux based, and thus it is no surprise that when build native code for it, need some Linux tools. • On Windows, NDK supports Cygwin 1.7.x and above. • It’s just a set of software that emulates Unix environment on Windows • get Cygwin, go to cygwin.com
  • 8. Step 2: Install Cygwin • Cygwin’s setup.exe will download and run.. • Choose Install from Internet, then click Next, then choose the installation directory (be sure to choose a directory path that contains no spaces in it) like – C:/cygwin
  • 9. Step 2: Installing Cygwin DEVREL Branch
  • 10. Step 3: Making a Basic NDK App • The general idea of using NDK in apps is to put your native pieces of code into libraries that you can then consume from the Java code.
  • 11. Step 3: Making a Basic NDK App Create Activity similar to other projects Right click on the "SampleNDK" project­> Select "New"­> Select "Folder"­>Type "jni" Add Android.mk and native.c
  • 12. Step 4: Generate Headers • Check if class files are generated in this dir workspaceNDKSamplebinclasses • Issue javah command from this dir javah ­jni com.samplendk.SampleNDKActivity Make sure classpath includes current dir + android sdk path
  • 13. Step 4: Generate Headers
  • 14. Step 5 Create Library (.so) using NDK Build • create a binary library from the C source that we wrote, • use a combination of Cygwin and Android NDK tools. • Launch the Cygwin console and cd to project dir • the command line is: ndk­build /cygdrive/c/Software/android­ndk­r9­ windows­x86/android­ndk­r9/ndk­build
  • 15. Create Library (.so) using NDK Build
  • 16. Create Library (.so) using NDK Build • a successful run of the ndk­build tool will create an .so file in a new folder called libs. • The .so file is the binary library that will be included into the application .apk package and will be available for the Java code of the app to link to.
  • 17. Step 6 : Loading the library (.so) public class Ndk_testActivity extends Activity { // load the library ­ name matches jni/Android.mk static { System.loadLibrary("ndkfoo"); } // declare the native code function ­ must match ndk_test.c private native String invokeNativeFunction(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // this is where we call the native code String hello = invokeNativeFunction(); new AlertDialog.Builder(this).setMessage(hello).show(); } }
  • 18.
  • 20. All about JNI • Java Native Interface (JNI) • The JNI is a part of the Java platform, programmers can address interoperability issues once, and expect their solution to work with all implementations of the Java platform. “Applications written in the Java programming language as well as in native (C, C++, etc.) programming languages.”
  • 21. Java Platform do • Java platforms are commonly deployed on top of a host environment. For example, the Java Runtime Environment (JRE) is a Sun product that supports the Java platform on existing operating systems such as Solaris and Windows. • The Java platform offers a set of features that applications can rely on independent of the underlying host environment.
  • 22. Role of the JNI • The JNI is a powerful feature that allows you to take advantage of the Java platform, but still utilize code written in other languages. As a part of the Java virtual machine implementation, the JNI is a two­way interface that allows Java applications to invoke native code and vice versa. Figure ­
  • 23. JNI ­ Two­way interface • As a two­way interface, the JNI can support two types of native code: ­ Native libraries and ­ Native applications. ­ Applications call native methods in the same way that they call methods implemented in the Java programming language. ­ An invocation interface : Native applications can link with a native library that implements the Java virtual machine, and then .. Use the invocation interface to execute software components written in the Java programming language. For example, a web browser written in C can execute downloaded applets in an embedded Java virtual machine implemention.
  • 24. When the JNI becomes useful ? The following scenarios: • Targeted Java API might not support certain host­dependent features needed by an application. • May want to access an existing native library and are not willing to pay for the overhead of copying and transmitting data across different processes. • Loading a native library into the existing process hosting the application requires less system resources than starting a new process and loading the library into that process. • If a 3D­intensive application spends most of its time in graphics rendering, you may find it necessary to write the core portion of a graphics library in assembly code to achieve maximum performance. Like, Games, Ex­H/W …. • Have role on the JDK ­ The JNI was first supported in JDK release 1.1. Internally. ­ Java 'jdk' is the 'Java Development Kit' and it allows you to compile Java programs.
  • 25. How to code with JNI
  • 26. Android.mk files We'll leave most of the file as it is. • LOCAL_PATH ­ this line should be left as it is since your source file ('example.c') is in the same directory as the 'Android.mk' file. • include $(CLEAR_VARS) ­ this line should be left as it is. It is required. • LOCAL_MODULE ­ this line should be changed to match your module name. For this tutorial we'll change it to 'example'. This name should not have any spaces in it as it will be made into the actual library's name ('libexample.so' for us). • LOCAL_CFLAGS ­ This line can be left as it is. It is for compiler flags. • LOCAL_SRC_FILES ­ this line should be changed to 'example.c' since that's our source file. • LOCAL_LDLIBS ­ leave this the same. • include $(BUILD_SHARED_LIBRARY) ­ leave this the same.
  • 27. How to configure a script for making a library and an Android.mk file • Configure script to generate the – config.h and config.mak files. – http://code.google.com/p/awesomeguy/wiki/JNITuto rial#Overview – CV Ready + Cygwin Devel Branch + NDK set – YA cam recorder + ffmpeg test project for making ffmpeg library + Color Conversion yuv2rgb – halfninja­android­ffmpeg­x264­04b62f2 need ffmpeg library – Test the project + ffmpeg tutorial search