Android NDK Intro

Android NDK Intro
Tokyo Android Meetup 21st July 2016
About The Presenter
Giles Payne
Android Developer - TenTen Corp
Developing for Android since Cupcake
BA Honours Mathematics and Computation, Oxford University
Country of Origin: Scotland
What is the Android NDK?
A set of tools for building/debugging C/C++ code to run on Android
Invoked from Java via JNI(Java Native Interface)
Available for download at https://developer.android.com/ndk/index.html
Android NDK - Why?
Performance
Order of magnitude speedup for performance critical code
Code reuse
Existing code C/C++ base can be ported to Android without total rewrite in Java
Large amount of libraries written in C/C++ can be reused (boost/cocos2d-x/OpenCV)
Cross platform development
iOS and other mobile OSs all support C/C++
NDK How To
Declare method as native with no body
public native void myNativeMethod();
Use javah to generate native stub
javah -o "MyClass.h" -classpath "/home/giles/myjavalibs" com.example.MyClass
Add implementation to stub and build C/C++ lib
extern "C" void Java_com_example_MyClass_myNativeMethod(JNIEnv* env, jobject this) {
/* do stuff */
}
What if I need to call back out to Java?
jclass myjclass = (*env)->GetObjectClass(env, myjobj);
jmethodID myMethodId = (*env)->GetMethodID(env, myjclass, "myMethod", "()Ljava/lang/String;");
jstring jstrResult = (jstring)(*env)->CallObjectMethod(env, myjobj, myMethodId);
Reference:
http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html
Android NDK Gotchas
Managing your own reference counting
Check you have correct calls to NewStringUTF/ReleaseStringUTFChars
Create/delete global references using NewGlobalRef/DeleteGlobalRef
Library state on second run
Native libraries will not be unloaded after the calling Java activity exits!
Libraries need to be completely reinitialized when calling activity restarts. Hint:
extern int __bss_start;
extern int _end;
void reStart() {
void* bssBackup = native_backup_bss(); /* back-up somethings that need to be remembered */
memset((void*)__bss_start, 0 , _end-__bss_start); /* clear all memory that was initially zeroed */
Android NDK with autotools
Inspect verbose output to get the correct compiler linker flags. Might look
something like:
./configure --with-gcc=$ANDROID_NDK/toolchains/$ANDROID_NDK_TOOLCHAIN/bin/arm-linux-androideabi-gcc --with-
ld=$ANDROID_NDK/toolchains/$ANDROID_NDK_TOOLCHAIN/bin/arm-linux-androideabi-ld --build=i386-unknown-linux --
host=arm-unknown-linux CFLAGS="-w -I$ANDROID_NDK/platforms/android-18/arch-arm/usr/include -march=armv5te -
DANDROID -mtune=xscale -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64" LDFLAGS="--
sysroot=$ANDROID_NDK/platforms/android-18/arch-arm -lgcc -no-canonical-prefixes -Wl,-z,noexecstack -lc -lm -llog"
NDK Chip Architecture Support
ARM - nearly all smartphones use ARM chips
x86 - recently x86 tablets becoming more common
MIPs - not widely used
Android NDK Debugging: The Old Way
Set up port forwarding for android emulator
adb forward tcp:1234 tcp:1234
Run gdbserver on device/emulator
gdbserver :1234 ondevicebinary args
Run gdb on PC
./arm-linux-androideabi-gdb.exe
Select file
file onPCbinary
Set shared object search path
set solib-search-path .
Run
target remote :1234
Android NDK Debugging: The New Way
Demo!
1 of 11

Recommended

Intro to introducing rust to ruby by
Intro to introducing rust to rubyIntro to introducing rust to ruby
Intro to introducing rust to rubyAnthony Broad-Crawford
570 views20 slides
Droidcon Summary 2021 by
Droidcon Summary 2021Droidcon Summary 2021
Droidcon Summary 2021Bartosz Kosarzycki
179 views47 slides
Standalone Android Apps in Python by
Standalone Android Apps in PythonStandalone Android Apps in Python
Standalone Android Apps in PythonBaptiste Lagarde
7.7K views19 slides
Debug JNI code with ndk-gdb and eclipse GUI by
Debug JNI code with ndk-gdb and eclipse GUIDebug JNI code with ndk-gdb and eclipse GUI
Debug JNI code with ndk-gdb and eclipse GUITom Chen
1.4K views14 slides
Review: Apitrace and Vogl by
Review: Apitrace and VoglReview: Apitrace and Vogl
Review: Apitrace and VoglGao Yunzhong
212 views5 slides
Using openCV 3.2.0 with CodeBlocks by
Using openCV 3.2.0 with CodeBlocksUsing openCV 3.2.0 with CodeBlocks
Using openCV 3.2.0 with CodeBlocksWei-Wen Hsu
13.4K views40 slides

More Related Content

What's hot

Docker deploy by
Docker deployDocker deploy
Docker deployEric Ahn
398 views9 slides
Cross Platform App Development with C++ by
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++Joan Puig Sanz
1.6K views35 slides
Run Go applications on Pico using TinyGo by
Run Go applications on Pico using TinyGo Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo Yu-Shuan Hsieh
527 views28 slides
TDC2018SP | Trilha Containers - CI/CD com Docker e Drone by
TDC2018SP | Trilha Containers - CI/CD com Docker e DroneTDC2018SP | Trilha Containers - CI/CD com Docker e Drone
TDC2018SP | Trilha Containers - CI/CD com Docker e Dronetdc-globalcode
438 views57 slides
.Net Core by
.Net Core.Net Core
.Net CoreVinícius Tonial Sossella
138 views20 slides
Common design patterns (migang 16 May 2012) by
Common design patterns (migang 16 May 2012)Common design patterns (migang 16 May 2012)
Common design patterns (migang 16 May 2012)Steven Smith
1.4K views42 slides

What's hot(18)

Docker deploy by Eric Ahn
Docker deployDocker deploy
Docker deploy
Eric Ahn398 views
Cross Platform App Development with C++ by Joan Puig Sanz
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
Joan Puig Sanz1.6K views
Run Go applications on Pico using TinyGo by Yu-Shuan Hsieh
Run Go applications on Pico using TinyGo Run Go applications on Pico using TinyGo
Run Go applications on Pico using TinyGo
Yu-Shuan Hsieh527 views
TDC2018SP | Trilha Containers - CI/CD com Docker e Drone by tdc-globalcode
TDC2018SP | Trilha Containers - CI/CD com Docker e DroneTDC2018SP | Trilha Containers - CI/CD com Docker e Drone
TDC2018SP | Trilha Containers - CI/CD com Docker e Drone
tdc-globalcode438 views
Common design patterns (migang 16 May 2012) by Steven Smith
Common design patterns (migang 16 May 2012)Common design patterns (migang 16 May 2012)
Common design patterns (migang 16 May 2012)
Steven Smith1.4K views
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit, by Farshid Pirahansiah
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit, Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
Install, Compile, Setup, Setting OpenCV 3.2, Visual C++ 2015, Win 64bit,
Farshid Pirahansiah5.7K views
Mobile C++ by gdgut
Mobile C++Mobile C++
Mobile C++
gdgut987 views
NDK Programming in Android by Arvind Devaraj
NDK Programming in AndroidNDK Programming in Android
NDK Programming in Android
Arvind Devaraj2.3K views
HOW TO RUN RSTUDIO SERVERS ANYWHERE WITH CONTAINERS - HPC, CLOUD, AND LOCALLY by Wendy Wong
HOW TO RUN RSTUDIO SERVERS ANYWHERE WITH CONTAINERS - HPC, CLOUD, AND LOCALLYHOW TO RUN RSTUDIO SERVERS ANYWHERE WITH CONTAINERS - HPC, CLOUD, AND LOCALLY
HOW TO RUN RSTUDIO SERVERS ANYWHERE WITH CONTAINERS - HPC, CLOUD, AND LOCALLY
Wendy Wong617 views
July 2015 Android Taipei - Anti-Decompiler by SUKI by Suki Huang
July 2015 Android Taipei - Anti-Decompiler by SUKIJuly 2015 Android Taipei - Anti-Decompiler by SUKI
July 2015 Android Taipei - Anti-Decompiler by SUKI
Suki Huang2K views
Take care of hundred containers and not go crazy by Honza Horák
Take care of hundred containers and not go crazyTake care of hundred containers and not go crazy
Take care of hundred containers and not go crazy
Honza Horák49 views
Common Workflow Language (CWL) - George Carvalho by George Carvalho
Common Workflow Language (CWL) -  George CarvalhoCommon Workflow Language (CWL) -  George Carvalho
Common Workflow Language (CWL) - George Carvalho
George Carvalho309 views
Native development kit (ndk) introduction by Rakesh Jha
Native development kit (ndk)  introductionNative development kit (ndk)  introduction
Native development kit (ndk) introduction
Rakesh Jha1.4K views
Guide: How to Build OpenCV 3.0.0 by André Moreira
Guide: How to Build OpenCV 3.0.0Guide: How to Build OpenCV 3.0.0
Guide: How to Build OpenCV 3.0.0
André Moreira53.2K views
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ... by Yoshifumi Kawai
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
Yoshifumi Kawai4.6K views

Viewers also liked

Pablofernandez4 a hipervinculo by
Pablofernandez4 a hipervinculoPablofernandez4 a hipervinculo
Pablofernandez4 a hipervinculoPabloFernandezAlonso
361 views22 slides
Sport tourism product of greece 2008 by goutzioupas george by
Sport tourism product of greece 2008 by goutzioupas georgeSport tourism product of greece 2008 by goutzioupas george
Sport tourism product of greece 2008 by goutzioupas georgeGeorge Goutzioupas
621 views105 slides
Electricidad y electrónica by
Electricidad y electrónicaElectricidad y electrónica
Electricidad y electrónicajuana0910
490 views19 slides
Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1] by
Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]
Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]rusell rivera urbina
249 views20 slides
Sanctum Consulting can help people travel to Greece for tourist visa by
 Sanctum Consulting can help people travel to Greece for tourist visa   Sanctum Consulting can help people travel to Greece for tourist visa
Sanctum Consulting can help people travel to Greece for tourist visa Sanctum Business Consulting Pvt Ltd
95 views19 slides
Responsabilidad social corporativa 2 by
Responsabilidad social  corporativa 2Responsabilidad social  corporativa 2
Responsabilidad social corporativa 2kariosmara
205 views51 slides

Viewers also liked(20)

Sport tourism product of greece 2008 by goutzioupas george by George Goutzioupas
Sport tourism product of greece 2008 by goutzioupas georgeSport tourism product of greece 2008 by goutzioupas george
Sport tourism product of greece 2008 by goutzioupas george
George Goutzioupas621 views
Electricidad y electrónica by juana0910
Electricidad y electrónicaElectricidad y electrónica
Electricidad y electrónica
juana0910490 views
Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1] by rusell rivera urbina
Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]
Manual 1. -ley_nâ°_30225_-_nueva_ley_de_contrtaciones_lce.doc_(1)[1]
Responsabilidad social corporativa 2 by kariosmara
Responsabilidad social  corporativa 2Responsabilidad social  corporativa 2
Responsabilidad social corporativa 2
kariosmara205 views
Glossario de Search Engine Marketing by Pablo Almeida
Glossario de Search Engine MarketingGlossario de Search Engine Marketing
Glossario de Search Engine Marketing
Pablo Almeida650 views
Gestion y Asesoramiento en la compraventa de vehiculos by J.M.A.S
Gestion y Asesoramiento en la compraventa de vehiculosGestion y Asesoramiento en la compraventa de vehiculos
Gestion y Asesoramiento en la compraventa de vehiculos
J.M.A.S268 views
Five IT Considerations for the Media-Centric Hotel Room by Samsung Business USA
Five IT Considerations for the Media-Centric Hotel RoomFive IT Considerations for the Media-Centric Hotel Room
Five IT Considerations for the Media-Centric Hotel Room
Presentacion seguridad internet balvina by BAlvina Barrera
Presentacion seguridad internet balvinaPresentacion seguridad internet balvina
Presentacion seguridad internet balvina
BAlvina Barrera168 views
Hoja de vida by estefa0825
Hoja de vidaHoja de vida
Hoja de vida
estefa0825232 views
Unidad educativa diana y gissela by gissexsj
Unidad educativa diana y gisselaUnidad educativa diana y gissela
Unidad educativa diana y gissela
gissexsj132 views
Ley islamica by capri_6969
Ley islamicaLey islamica
Ley islamica
capri_6969324 views
What we have in common by AdinaTeodora
What we have in commonWhat we have in common
What we have in common
AdinaTeodora134 views
Final presentation research project mergers and acquisitions-august 2014 by m... by Mostafa Talaat
Final presentation research project mergers and acquisitions-august 2014 by m...Final presentation research project mergers and acquisitions-august 2014 by m...
Final presentation research project mergers and acquisitions-august 2014 by m...
Mostafa Talaat536 views
IPE-DHL"gestione dei flussi di approvvigionamento dei materiali operativi" 2015 by IPE Business School
IPE-DHL"gestione dei flussi di approvvigionamento dei materiali operativi" 2015IPE-DHL"gestione dei flussi di approvvigionamento dei materiali operativi" 2015
IPE-DHL"gestione dei flussi di approvvigionamento dei materiali operativi" 2015

Similar to Android NDK Intro

Getting started with the NDK by
Getting started with the NDKGetting started with the NDK
Getting started with the NDKKirill Kounik
686 views30 slides
Using the android ndk - DroidCon Paris 2014 by
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Paris Android User Group
981 views39 slides
Using the Android Native Development Kit (NDK) by
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Xavier Hallade
11.1K views52 slides
Getting Native with NDK by
Getting Native with NDKGetting Native with NDK
Getting Native with NDKナム-Nam Nguyễn
754 views37 slides
Using the Android Native Development Kit (NDK) by
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)DroidConTLV
5.6K views40 slides
Android Native Development Kit by
Android Native Development KitAndroid Native Development Kit
Android Native Development KitPeter R. Egli
2.8K views16 slides

Similar to Android NDK Intro(20)

Getting started with the NDK by Kirill Kounik
Getting started with the NDKGetting started with the NDK
Getting started with the NDK
Kirill Kounik686 views
Using the Android Native Development Kit (NDK) by Xavier Hallade
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)
Xavier Hallade11.1K views
Using the Android Native Development Kit (NDK) by DroidConTLV
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)
DroidConTLV5.6K views
Android Native Development Kit by Peter R. Egli
Android Native Development KitAndroid Native Development Kit
Android Native Development Kit
Peter R. Egli2.8K views
Introduction to the Android NDK by BeMyApp
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDK
BeMyApp1.4K views
Advance Android Application Development by Ramesh Prasad
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
Ramesh Prasad3.3K views
Android ndk - Introduction by Rakesh Jha
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - Introduction
Rakesh Jha678 views
Working with the AOSP - Linaro Connect Asia 2013 by Opersys inc.
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
Opersys inc.5.1K views
Android on IA devices and Intel Tools by Xavier Hallade
Android on IA devices and Intel ToolsAndroid on IA devices and Intel Tools
Android on IA devices and Intel Tools
Xavier Hallade3.8K views
DLL Design with Building Blocks by Max Kleiner
DLL Design with Building BlocksDLL Design with Building Blocks
DLL Design with Building Blocks
Max Kleiner1.5K views
Running native code on Android #OSDCfr 2012 by Cédric Deltheil
Running native code on Android #OSDCfr 2012Running native code on Android #OSDCfr 2012
Running native code on Android #OSDCfr 2012
Cédric Deltheil900 views
Hacking the Codename One Source Code - Part V - Transcript.pdf by ShaiAlmog1
Hacking the Codename One Source Code - Part V - Transcript.pdfHacking the Codename One Source Code - Part V - Transcript.pdf
Hacking the Codename One Source Code - Part V - Transcript.pdf
ShaiAlmog1291 views
Настройка окружения для кросскомпиляции проектов на основе docker'a by corehard_by
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'a
corehard_by174 views
NDK Primer (Wearable DevCon 2014) by Ron Munitz
NDK Primer (Wearable DevCon 2014)NDK Primer (Wearable DevCon 2014)
NDK Primer (Wearable DevCon 2014)
Ron Munitz223 views

Recently uploaded

2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx by
2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx
2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptxlwang78
165 views19 slides
Robotics in construction enterprise by
Robotics in construction enterpriseRobotics in construction enterprise
Robotics in construction enterpriseKhalid Abdel Naser Abdel Rahim
5 views1 slide
Global airborne satcom market report by
Global airborne satcom market reportGlobal airborne satcom market report
Global airborne satcom market reportdefencereport78
6 views13 slides
REACTJS.pdf by
REACTJS.pdfREACTJS.pdf
REACTJS.pdfArthyR3
35 views16 slides
Searching in Data Structure by
Searching in Data StructureSearching in Data Structure
Searching in Data Structureraghavbirla63
14 views8 slides
START Newsletter 3 by
START Newsletter 3START Newsletter 3
START Newsletter 3Start Project
6 views25 slides

Recently uploaded(20)

2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx by lwang78
2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx
2023Dec ASU Wang NETR Group Research Focus and Facility Overview.pptx
lwang78165 views
REACTJS.pdf by ArthyR3
REACTJS.pdfREACTJS.pdf
REACTJS.pdf
ArthyR335 views
Searching in Data Structure by raghavbirla63
Searching in Data StructureSearching in Data Structure
Searching in Data Structure
raghavbirla6314 views
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc... by csegroupvn
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...
csegroupvn6 views
Design_Discover_Develop_Campaign.pptx by ShivanshSeth6
Design_Discover_Develop_Campaign.pptxDesign_Discover_Develop_Campaign.pptx
Design_Discover_Develop_Campaign.pptx
ShivanshSeth645 views
Design of machine elements-UNIT 3.pptx by gopinathcreddy
Design of machine elements-UNIT 3.pptxDesign of machine elements-UNIT 3.pptx
Design of machine elements-UNIT 3.pptx
gopinathcreddy34 views
Web Dev Session 1.pptx by VedVekhande
Web Dev Session 1.pptxWeb Dev Session 1.pptx
Web Dev Session 1.pptx
VedVekhande13 views
MongoDB.pdf by ArthyR3
MongoDB.pdfMongoDB.pdf
MongoDB.pdf
ArthyR349 views
_MAKRIADI-FOTEINI_diploma thesis.pptx by fotinimakriadi
_MAKRIADI-FOTEINI_diploma thesis.pptx_MAKRIADI-FOTEINI_diploma thesis.pptx
_MAKRIADI-FOTEINI_diploma thesis.pptx
fotinimakriadi10 views
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf by AlhamduKure
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdfASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf
ASSIGNMENTS ON FUZZY LOGIC IN TRAFFIC FLOW.pdf
AlhamduKure6 views
Ansari: Practical experiences with an LLM-based Islamic Assistant by M Waleed Kadous
Ansari: Practical experiences with an LLM-based Islamic AssistantAnsari: Practical experiences with an LLM-based Islamic Assistant
Ansari: Practical experiences with an LLM-based Islamic Assistant
M Waleed Kadous7 views

Android NDK Intro

  • 1. Android NDK Intro Tokyo Android Meetup 21st July 2016
  • 2. About The Presenter Giles Payne Android Developer - TenTen Corp Developing for Android since Cupcake BA Honours Mathematics and Computation, Oxford University Country of Origin: Scotland
  • 3. What is the Android NDK? A set of tools for building/debugging C/C++ code to run on Android Invoked from Java via JNI(Java Native Interface) Available for download at https://developer.android.com/ndk/index.html
  • 4. Android NDK - Why? Performance Order of magnitude speedup for performance critical code Code reuse Existing code C/C++ base can be ported to Android without total rewrite in Java Large amount of libraries written in C/C++ can be reused (boost/cocos2d-x/OpenCV) Cross platform development iOS and other mobile OSs all support C/C++
  • 5. NDK How To Declare method as native with no body public native void myNativeMethod(); Use javah to generate native stub javah -o "MyClass.h" -classpath "/home/giles/myjavalibs" com.example.MyClass Add implementation to stub and build C/C++ lib extern "C" void Java_com_example_MyClass_myNativeMethod(JNIEnv* env, jobject this) { /* do stuff */ }
  • 6. What if I need to call back out to Java? jclass myjclass = (*env)->GetObjectClass(env, myjobj); jmethodID myMethodId = (*env)->GetMethodID(env, myjclass, "myMethod", "()Ljava/lang/String;"); jstring jstrResult = (jstring)(*env)->CallObjectMethod(env, myjobj, myMethodId); Reference: http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html
  • 7. Android NDK Gotchas Managing your own reference counting Check you have correct calls to NewStringUTF/ReleaseStringUTFChars Create/delete global references using NewGlobalRef/DeleteGlobalRef Library state on second run Native libraries will not be unloaded after the calling Java activity exits! Libraries need to be completely reinitialized when calling activity restarts. Hint: extern int __bss_start; extern int _end; void reStart() { void* bssBackup = native_backup_bss(); /* back-up somethings that need to be remembered */ memset((void*)__bss_start, 0 , _end-__bss_start); /* clear all memory that was initially zeroed */
  • 8. Android NDK with autotools Inspect verbose output to get the correct compiler linker flags. Might look something like: ./configure --with-gcc=$ANDROID_NDK/toolchains/$ANDROID_NDK_TOOLCHAIN/bin/arm-linux-androideabi-gcc --with- ld=$ANDROID_NDK/toolchains/$ANDROID_NDK_TOOLCHAIN/bin/arm-linux-androideabi-ld --build=i386-unknown-linux -- host=arm-unknown-linux CFLAGS="-w -I$ANDROID_NDK/platforms/android-18/arch-arm/usr/include -march=armv5te - DANDROID -mtune=xscale -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64" LDFLAGS="-- sysroot=$ANDROID_NDK/platforms/android-18/arch-arm -lgcc -no-canonical-prefixes -Wl,-z,noexecstack -lc -lm -llog"
  • 9. NDK Chip Architecture Support ARM - nearly all smartphones use ARM chips x86 - recently x86 tablets becoming more common MIPs - not widely used
  • 10. Android NDK Debugging: The Old Way Set up port forwarding for android emulator adb forward tcp:1234 tcp:1234 Run gdbserver on device/emulator gdbserver :1234 ondevicebinary args Run gdb on PC ./arm-linux-androideabi-gdb.exe Select file file onPCbinary Set shared object search path set solib-search-path . Run target remote :1234
  • 11. Android NDK Debugging: The New Way Demo!