SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
Android	
  
         Internals	
  Overview	
  
                Marko	
  Gargenta	
  
                marakana.com	
  




© 2011
About	
  Marko	
  Gargenta	
  
     Developer of Android Bootcamp for Marakana.

     Instructor for 1,000s of developers on Android at
     Qualcomm, Cisco, Motorola, Texas Instruments, Sony-
     Ericsson, Sharp, NetGear, DoD and other great orgs.

     Author of Learning Android published by O’Reilly.

     Speaker at OSCON, ACM, IEEE, SDC, AnDevCon.

     Founder of SFAndroid.org




© 2011
Agenda	
  

         •    Android	
  Startup	
  &	
  Run>me	
  
         •    Layer	
  Interac>on	
  
         •    NDK	
  
         •    AIDL	
  
         •    Summary	
  




© 2011
ANDROID	
  	
  
         STARTUP	
  &	
  	
  
         RUNTIME	
  

© 2011
Run>me	
  Overview	
  




© 2011
The	
  Stack	
  




© 2011
LAYER	
  INTERACTION	
  

© 2011
Layer	
  Interac>ons
                                              	
  

         There are three main
         scenarios for your app to talk
         to native library:

         -  Directly
         -  Via native service
         -  Via native daemon

         It will depend on the type of
         app and type of native library
         which method works best.




© 2011
Audio	
  Framework	
  




© 2011
Camera	
  and	
  Video	
  Framework	
  




© 2011
Java	
  Na>ve	
  Interface	
  


     JNI defines naming and coding
     convention so that Java VM can find
     and call native code.

     JNI is built into JVM to provide
     access to OS I/O and others.

     Your JNI code runs on top Java VM.




© 2011
Building	
  and	
  Running	
  JNI	
  Code	
  




© 2011
NATIVE	
  
         DEVELOPMENT	
  
         KIT	
  


© 2011
What’s	
  in	
  NDK?	
  
         Tools to build and cross-compile your native code for the
         device architecture (ARMv5TE and ARMv7-A; x86 in
         future releases)

         A way to package your library into the APK file so you can
         distribute your application easily


         A set of native system headers that will be supported for
         the future releases of Android platform (libc, libm, libz,
         liblog, libjnigrahics, OpenGL/OpenSL ES, JNI headers,
         minimal C++ support headers, and Android native app
         APIs)

         (some) documentation, sample code and examples



© 2011
Why	
  NDK?	
  
         NDK allows you to develop parts of your Android
         application in C/C++.

         You cannot develop native-only apps in NDK –
         though 2.3 now supports NativeActivity,
         which allows handling lifecycle callbacks in native
         code, but access to Services and Content
         Providers still requires JNI.

         NDK code still subject to security sandboxing.

         Main motivation for native code is performance
         (CPU-intensive, self-contained, low-memory
         footprint code) and the re-use of legacy code.




© 2011
Using	
  NDK	
  




© 2011
Fibonacci	
  Example	
  




         Fibonacci algorithm is easy to implement both in Java and
         C, to compare speed differences.




© 2011
Implemen>ng	
  Java	
  Library	
  

         1.  Use	
  Java	
  keyword	
  native to	
  declare	
  
             future	
  C	
  methods	
  
         2.  Use	
  System.loadLibrary()	
  to	
  load	
  
             the	
  na>ve	
  module	
  
         3.  Process	
  your	
  Java	
  library	
  with	
  	
  
             javah –jni to	
  get	
  the	
  header	
  file	
  s	
  




© 2011
Implemen>ng	
  C	
  Code	
  
         1.    Place	
  all	
  your	
  C	
  code	
  in	
  /jni/ folder	
  
         2.    Copy	
  header	
  file	
  into	
  this	
  folder	
  
         3.    Create	
  C	
  file	
  and	
  include	
  the	
  header	
  file	
  
         4.    Create	
  Android.mk	
  file	
  
         5.    Run	
  ndk-build	
  in	
  root	
  of	
  your	
  project	
  
               to	
  create	
  library	
  module	
  in	
  /lib/!




© 2011
ANDROID	
  INTERFACE	
  DEFINITION	
  
         LANGUAGE	
  

© 2011
Binder	
  IPC	
  




     High-performance IPC: shared memory, per-process thread pool, synchronous
© 2011
Implemen>ng	
  Remote	
  Server
                                          	
  
         1.  Define	
  the	
  interface	
  as	
  an	
  AIDL	
  file	
  
         2.  Implement	
  the	
  remote	
  service	
  
         3.  Declare	
  it	
  in	
  Android	
  Manifest	
  




© 2011
Implemen>ng	
  Remote	
  Client
                                           	
  
         1.  Copy	
  the	
  AIDL	
  file	
  
         2.  Implement	
  ServiceConnection
             object	
  
             –  Use	
  Stub().asInterface()	
  to	
  cast	
  
                IBinder to	
  service	
  
         3.  Bind	
  to	
  the	
  service	
  
         4.  Call	
  the	
  remote	
  service	
  
             –  Handle	
  RemoteException!


© 2011
Summary	
  
              Android is open and complete system for
              mobile development. It is based on Java
              and augmented with XML, with lower
              levels written in C/C++.

              It takes about 3-5 days of intensive
              training to learn Android application
              development for someone who has basic
              Java (or similar) experience.




              Marko Gargenta, Marakana.com
              marko@marakana.com
              +1-415-647-7000



© 2011

Mais conteúdo relacionado

Mais procurados

An Introduction To Android
An Introduction To AndroidAn Introduction To Android
An Introduction To Android
GoogleTecTalks
 
2011 android
2011 android2011 android
2011 android
vpedapolu
 
Droid con 2012 bangalore v2.0
Droid con 2012   bangalore v2.0Droid con 2012   bangalore v2.0
Droid con 2012 bangalore v2.0
Premchander Rao
 
Android architecture
Android architectureAndroid architecture
Android architecture
Hari Krishna
 
Droid con berlin_the_bb10_android_runtime
Droid con berlin_the_bb10_android_runtimeDroid con berlin_the_bb10_android_runtime
Droid con berlin_the_bb10_android_runtime
Droidcon Berlin
 
Forum Nokia Dev. Camp - WRT training Paris_17&18 Nov.
Forum Nokia Dev. Camp - WRT training Paris_17&18 Nov.Forum Nokia Dev. Camp - WRT training Paris_17&18 Nov.
Forum Nokia Dev. Camp - WRT training Paris_17&18 Nov.
DALEZ
 

Mais procurados (19)

Android Beyond The Phone
Android Beyond The PhoneAndroid Beyond The Phone
Android Beyond The Phone
 
Android: A 9,000-foot Overview
Android: A 9,000-foot OverviewAndroid: A 9,000-foot Overview
Android: A 9,000-foot Overview
 
An Introduction To Android
An Introduction To AndroidAn Introduction To Android
An Introduction To Android
 
2011 android
2011 android2011 android
2011 android
 
Android Services Black Magic by Aleksandar Gargenta
Android Services Black Magic by Aleksandar GargentaAndroid Services Black Magic by Aleksandar Gargenta
Android Services Black Magic by Aleksandar Gargenta
 
Droid con 2012 bangalore v2.0
Droid con 2012   bangalore v2.0Droid con 2012   bangalore v2.0
Droid con 2012 bangalore v2.0
 
The anatomy and philosophy of Android - Google I/O 2009
The anatomy and philosophy of Android - Google I/O 2009The anatomy and philosophy of Android - Google I/O 2009
The anatomy and philosophy of Android - Google I/O 2009
 
Slides bootcamp21
Slides bootcamp21Slides bootcamp21
Slides bootcamp21
 
Nokia Qt SDK in action - Qt developer days 2010
Nokia Qt SDK in action - Qt developer days 2010Nokia Qt SDK in action - Qt developer days 2010
Nokia Qt SDK in action - Qt developer days 2010
 
Meego의 현재와 미래(2)
Meego의 현재와 미래(2)Meego의 현재와 미래(2)
Meego의 현재와 미래(2)
 
Android architecture
Android architectureAndroid architecture
Android architecture
 
Droid con berlin_the_bb10_android_runtime
Droid con berlin_the_bb10_android_runtimeDroid con berlin_the_bb10_android_runtime
Droid con berlin_the_bb10_android_runtime
 
Qt - for stack overflow developer conference
Qt - for stack overflow developer conferenceQt - for stack overflow developer conference
Qt - for stack overflow developer conference
 
Forum Nokia Dev. Camp - WRT training Paris_17&18 Nov.
Forum Nokia Dev. Camp - WRT training Paris_17&18 Nov.Forum Nokia Dev. Camp - WRT training Paris_17&18 Nov.
Forum Nokia Dev. Camp - WRT training Paris_17&18 Nov.
 
Qt S60 Technical Presentation Fn Stripped
Qt S60 Technical Presentation Fn StrippedQt S60 Technical Presentation Fn Stripped
Qt S60 Technical Presentation Fn Stripped
 
ARM
ARMARM
ARM
 
Introduction To Android
Introduction To AndroidIntroduction To Android
Introduction To Android
 
Develop Ruby Applications Fast | TubroRuby
Develop Ruby Applications Fast | TubroRubyDevelop Ruby Applications Fast | TubroRuby
Develop Ruby Applications Fast | TubroRuby
 
Connected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discoveryConnected World in android - Local data sharing and service discovery
Connected World in android - Local data sharing and service discovery
 

Destaque

Android NDK and the x86 Platform
Android NDK and the x86 PlatformAndroid NDK and the x86 Platform
Android NDK and the x86 Platform
Sebastian Mauer
 
Relative clauses
Relative clausesRelative clauses
Relative clauses
Sonia
 
eTwiningový maraton - ZS Nemsova
eTwiningový maraton - ZS NemsovaeTwiningový maraton - ZS Nemsova
eTwiningový maraton - ZS Nemsova
ivanabrabcova
 
Llenguatge ciències
Llenguatge ciènciesLlenguatge ciències
Llenguatge ciències
Arnau Cerdà
 
Was sagen die Sagen ... von unserer region
Was sagen die Sagen ... von unserer regionWas sagen die Sagen ... von unserer region
Was sagen die Sagen ... von unserer region
ivanabrabcova
 

Destaque (20)

Android on Intel platforms : current state, near-future, future & developers ...
Android on Intel platforms : current state, near-future, future & developers ...Android on Intel platforms : current state, near-future, future & developers ...
Android on Intel platforms : current state, near-future, future & developers ...
 
Android NDK and the x86 Platform
Android NDK and the x86 PlatformAndroid NDK and the x86 Platform
Android NDK and the x86 Platform
 
Relative clauses
Relative clausesRelative clauses
Relative clauses
 
Wordpress33 base
Wordpress33 base Wordpress33 base
Wordpress33 base
 
eTwiningový maraton - ZS Nemsova
eTwiningový maraton - ZS NemsovaeTwiningový maraton - ZS Nemsova
eTwiningový maraton - ZS Nemsova
 
Keyboard Access APIs
Keyboard Access APIsKeyboard Access APIs
Keyboard Access APIs
 
Greenwashing, Marketing a Sustainable future (rev1
Greenwashing, Marketing a Sustainable future (rev1Greenwashing, Marketing a Sustainable future (rev1
Greenwashing, Marketing a Sustainable future (rev1
 
Turbulent Times Leadership for Sales Managers
Turbulent Times Leadership for Sales ManagersTurbulent Times Leadership for Sales Managers
Turbulent Times Leadership for Sales Managers
 
Office 365 ( 0365) opastusta
Office  365 ( 0365) opastustaOffice  365 ( 0365) opastusta
Office 365 ( 0365) opastusta
 
Unit 5
Unit 5Unit 5
Unit 5
 
Llenguatge ciències
Llenguatge ciènciesLlenguatge ciències
Llenguatge ciències
 
Healthcare2.0 Turning Hell care into healthcare
Healthcare2.0 Turning Hell care into healthcareHealthcare2.0 Turning Hell care into healthcare
Healthcare2.0 Turning Hell care into healthcare
 
Mães na Internet e o Cenário em Cuiabá
Mães na Internet e o Cenário em CuiabáMães na Internet e o Cenário em Cuiabá
Mães na Internet e o Cenário em Cuiabá
 
Oracle Warehouse Builder - JUGM 2010
Oracle Warehouse Builder - JUGM 2010Oracle Warehouse Builder - JUGM 2010
Oracle Warehouse Builder - JUGM 2010
 
Clin infect dis. 2015-o'neill-1871-7
Clin infect dis. 2015-o'neill-1871-7Clin infect dis. 2015-o'neill-1871-7
Clin infect dis. 2015-o'neill-1871-7
 
Blogging and How It Complements Your Marketing Strategy
Blogging and How It Complements Your Marketing StrategyBlogging and How It Complements Your Marketing Strategy
Blogging and How It Complements Your Marketing Strategy
 
Dossier de premsa acord Derpartament de Cultura, Gremi d'Empresaris de Cinema...
Dossier de premsa acord Derpartament de Cultura, Gremi d'Empresaris de Cinema...Dossier de premsa acord Derpartament de Cultura, Gremi d'Empresaris de Cinema...
Dossier de premsa acord Derpartament de Cultura, Gremi d'Empresaris de Cinema...
 
Guida a Linkedin: profilo personale e aziendale
Guida a Linkedin: profilo personale e aziendaleGuida a Linkedin: profilo personale e aziendale
Guida a Linkedin: profilo personale e aziendale
 
Was sagen die Sagen ... von unserer region
Was sagen die Sagen ... von unserer regionWas sagen die Sagen ... von unserer region
Was sagen die Sagen ... von unserer region
 
Rekonstrukce šaten
Rekonstrukce šatenRekonstrukce šaten
Rekonstrukce šaten
 

Semelhante a Android Internals

Android 110521210945-phpapp01
Android 110521210945-phpapp01Android 110521210945-phpapp01
Android 110521210945-phpapp01
Mona AlRekabi
 
C,c++,java,php,.net training institute in delhi, best training institute for ...
C,c++,java,php,.net training institute in delhi, best training institute for ...C,c++,java,php,.net training institute in delhi, best training institute for ...
C,c++,java,php,.net training institute in delhi, best training institute for ...
MCM COmpetitive Classes
 
Developing and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-androidDeveloping and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-android
Elvis Jon Freddy Sitinjak
 
MonoTouch 5.2 Introduction
MonoTouch 5.2 IntroductionMonoTouch 5.2 Introduction
MonoTouch 5.2 Introduction
Xamarin
 

Semelhante a Android Internals (20)

Using the NDK and Renderscript
Using the NDK and RenderscriptUsing the NDK and Renderscript
Using the NDK and Renderscript
 
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 110521210945-phpapp01
Android 110521210945-phpapp01Android 110521210945-phpapp01
Android 110521210945-phpapp01
 
Android NDK
Android NDKAndroid NDK
Android NDK
 
Android ndk
Android ndkAndroid ndk
Android ndk
 
C,c++,java,php,.net training institute in delhi, best training institute for ...
C,c++,java,php,.net training institute in delhi, best training institute for ...C,c++,java,php,.net training institute in delhi, best training institute for ...
C,c++,java,php,.net training institute in delhi, best training institute for ...
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
 
document
documentdocument
document
 
Android ndk - Introduction
Android ndk  - IntroductionAndroid ndk  - Introduction
Android ndk - Introduction
 
Developing and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-androidDeveloping and-benchmarking-native-linux-applications-on-android
Developing and-benchmarking-native-linux-applications-on-android
 
Mobile application development
Mobile application developmentMobile application development
Mobile application development
 
MonoTouch 5.2 Introduction
MonoTouch 5.2 IntroductionMonoTouch 5.2 Introduction
MonoTouch 5.2 Introduction
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Session i
Session iSession i
Session i
 
Basic of Android App Development
Basic of Android App DevelopmentBasic of Android App Development
Basic of Android App Development
 
Collaborative and agile development of mobile applications
Collaborative and agile development of mobile applicationsCollaborative and agile development of mobile applications
Collaborative and agile development of mobile applications
 
Session 1 beccse
Session 1 beccseSession 1 beccse
Session 1 beccse
 
Show and Tell: Building Applications on Cisco Open SDN Controller
Show and Tell: Building Applications on Cisco Open SDN Controller Show and Tell: Building Applications on Cisco Open SDN Controller
Show and Tell: Building Applications on Cisco Open SDN Controller
 
Lecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptxLecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptx
 
Android
AndroidAndroid
Android
 

Mais de Marko Gargenta

Marakana android-java developers
Marakana android-java developersMarakana android-java developers
Marakana android-java developers
Marko Gargenta
 

Mais de Marko Gargenta (8)

LTE: Building New Killer Apps
LTE: Building New Killer AppsLTE: Building New Killer Apps
LTE: Building New Killer Apps
 
Java Champion Wanted
Java Champion WantedJava Champion Wanted
Java Champion Wanted
 
Marakana Android User Interface
Marakana Android User InterfaceMarakana Android User Interface
Marakana Android User Interface
 
Marakana android-java developers
Marakana android-java developersMarakana android-java developers
Marakana android-java developers
 
Scrum Overview
Scrum OverviewScrum Overview
Scrum Overview
 
Why Python by Marilyn Davis, Marakana
Why Python by Marilyn Davis, MarakanaWhy Python by Marilyn Davis, Marakana
Why Python by Marilyn Davis, Marakana
 
Jens Østergaard on Why Scrum Is So Hard
Jens Østergaard on Why Scrum Is So HardJens Østergaard on Why Scrum Is So Hard
Jens Østergaard on Why Scrum Is So Hard
 
Jens Østergaard on Why Scrum Is So Hard
Jens Østergaard on Why Scrum Is So HardJens Østergaard on Why Scrum Is So Hard
Jens Østergaard on Why Scrum Is So Hard
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Android Internals

  • 1. Android   Internals  Overview   Marko  Gargenta   marakana.com   © 2011
  • 2. About  Marko  Gargenta   Developer of Android Bootcamp for Marakana. Instructor for 1,000s of developers on Android at Qualcomm, Cisco, Motorola, Texas Instruments, Sony- Ericsson, Sharp, NetGear, DoD and other great orgs. Author of Learning Android published by O’Reilly. Speaker at OSCON, ACM, IEEE, SDC, AnDevCon. Founder of SFAndroid.org © 2011
  • 3. Agenda   •  Android  Startup  &  Run>me   •  Layer  Interac>on   •  NDK   •  AIDL   •  Summary   © 2011
  • 4. ANDROID     STARTUP  &     RUNTIME   © 2011
  • 8. Layer  Interac>ons   There are three main scenarios for your app to talk to native library: -  Directly -  Via native service -  Via native daemon It will depend on the type of app and type of native library which method works best. © 2011
  • 10. Camera  and  Video  Framework   © 2011
  • 11. Java  Na>ve  Interface   JNI defines naming and coding convention so that Java VM can find and call native code. JNI is built into JVM to provide access to OS I/O and others. Your JNI code runs on top Java VM. © 2011
  • 12. Building  and  Running  JNI  Code   © 2011
  • 13. NATIVE   DEVELOPMENT   KIT   © 2011
  • 14. What’s  in  NDK?   Tools to build and cross-compile your native code for the device architecture (ARMv5TE and ARMv7-A; x86 in future releases) A way to package your library into the APK file so you can distribute your application easily A set of native system headers that will be supported for the future releases of Android platform (libc, libm, libz, liblog, libjnigrahics, OpenGL/OpenSL ES, JNI headers, minimal C++ support headers, and Android native app APIs) (some) documentation, sample code and examples © 2011
  • 15. Why  NDK?   NDK allows you to develop parts of your Android application in C/C++. You cannot develop native-only apps in NDK – though 2.3 now supports NativeActivity, which allows handling lifecycle callbacks in native code, but access to Services and Content Providers still requires JNI. NDK code still subject to security sandboxing. Main motivation for native code is performance (CPU-intensive, self-contained, low-memory footprint code) and the re-use of legacy code. © 2011
  • 17. Fibonacci  Example   Fibonacci algorithm is easy to implement both in Java and C, to compare speed differences. © 2011
  • 18. Implemen>ng  Java  Library   1.  Use  Java  keyword  native to  declare   future  C  methods   2.  Use  System.loadLibrary()  to  load   the  na>ve  module   3.  Process  your  Java  library  with     javah –jni to  get  the  header  file  s   © 2011
  • 19. Implemen>ng  C  Code   1.  Place  all  your  C  code  in  /jni/ folder   2.  Copy  header  file  into  this  folder   3.  Create  C  file  and  include  the  header  file   4.  Create  Android.mk  file   5.  Run  ndk-build  in  root  of  your  project   to  create  library  module  in  /lib/! © 2011
  • 20. ANDROID  INTERFACE  DEFINITION   LANGUAGE   © 2011
  • 21. Binder  IPC   High-performance IPC: shared memory, per-process thread pool, synchronous © 2011
  • 22. Implemen>ng  Remote  Server   1.  Define  the  interface  as  an  AIDL  file   2.  Implement  the  remote  service   3.  Declare  it  in  Android  Manifest   © 2011
  • 23. Implemen>ng  Remote  Client   1.  Copy  the  AIDL  file   2.  Implement  ServiceConnection object   –  Use  Stub().asInterface()  to  cast   IBinder to  service   3.  Bind  to  the  service   4.  Call  the  remote  service   –  Handle  RemoteException! © 2011
  • 24. Summary   Android is open and complete system for mobile development. It is based on Java and augmented with XML, with lower levels written in C/C++. It takes about 3-5 days of intensive training to learn Android application development for someone who has basic Java (or similar) experience. Marko Gargenta, Marakana.com marko@marakana.com +1-415-647-7000 © 2011