Developing Fault-Tolerant, !“German Engineered” Android Apps	  Andrew	  Levy	  andrew@cri/ercism.com	  CEO,	  co-­‐founder...
[droidcon	  ~]$	  whoami	  •  Andrew	  Levy	     –  Co-­‐founder	  &	  CEO	  @Cri/ercism	  •  Cri/ercism	     –  Real-­‐Cm...
What’s	  Ahead	    1.    TesCng	  DifficulCes	    2.    Top	  5	  Android	  Crashes	    3.    iOS	  vs	  Android,	  which	  ...
Android Device DiversityExample	  app	  shortly	  a_er	  launch:	  has	  30k	  DAU,	  175k	  unique	  users,	  50	  differe...
iOS FragmentationThis	  app	  has	  over	  850,000	  users,	  26	  diff	  app	  versions,	  12	  different	  devices	       ...
iOS	  5.0.1	     iOS	  5.1	  How Many iOS Versions Released?                                                              ...
Android Testing!Build	  &	  Test	  	  •  Integrated	  TesCng	  Tools	  in	  your	  IDE	       •  OEMs	  (developer.samsung...
Top 5 Android Crashes!               +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3...
Top 5 Android Crashes!               +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3...
java.lang.NullPointerException 	  •  “works	  for	  me”	  is	  not	  a	  good	  test,	  there	  are	  a	     thousand	  An...
Top 5 Android Crashes!               +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3...
Top 5 Android Crashes!               +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3...
java.lang.OutOfMemoryError	  Memory	  Leak	  in	  Dalvik:	  Keeping	  a	  reference	  to	  an	  object	  longer	  than	  n...
java.lang.OutOfMemoryError	         Memory	  Leak	  in	  Dalvik:	  Keeping	  a	  reference	  to	  an	  object	  longer	  t...
java.lang.OutOfMemoryError	  •  What	  about	  the	  NDK?	     –  In	  the	  past	  some	  devs	  built	  their	  C++	  co...
Top 5 Android Crashes!               +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3...
Top 5 Android Crashes!               +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3...
android.view.WindowManager           $BadTokenException	  Biggest	  Culprit:	  Dialogs	  	  •  Common	  error	  for	  begi...
android.view.WindowManager           $BadTokenException	  Biggest	  Culprit:	  Dialogs	  	  •  Anything	  that	  changes	 ...
Top 5 Android Crashes!               +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3...
Top 5 Android Crashes!               +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3...
java.lang.IllegalArgumentException!       (extends java.lang.RuntimeException) 	  	  •  Common	  Examples:	      –  Conten...
java.lang.RuntimeException 	  •  Common	  Pixalls	      –  Forge{ng	  to	  add	  an	  AcCvity	  to	  the	  Manifest	      ...
Top 5 Android Crashes!               +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3...
Top 5 Android Crashes!               +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3...
android.database.sqlite.SQLiteException 	   •  Use	  the	  database	  helper,	  accessing	  DB	  file	  directly	      pron...
Crashes	  on	  iOS	  &	  Android	             www.cri&ercism.com	  -­‐	  @cri&ercism	  
Crashes	  on	  iOS	  &	  Android	                                                            Hard	  to	  read	  pie	  char...
www.cri&ercism.com	  -­‐	  @cri&ercism	  
www.cri&ercism.com	  -­‐	  @cri&ercism	  
Questions?!                                 Come find us at"Andrew	  Levy	  andrew@cri/ercism.com	  @cri/ercism	  and	  @an...
Upcoming SlideShare
Loading in …5
×

droidcon 2012: Developing Fault Tolerant, “German-Engineered” Android Apps, Andrew Levy, Crittercism

1,232 views

Published on

German engineering is world renowned for high quality and stability – how come its Android apps can’t be the same? I’m co-founder and CEO of Crittercism, a real-time crash reporting and error analysis platform for mobile apps. Our SDK has recorded hundreds of millions of app loads, and is used by both indie developers and large enterprises like Netflix and AT&T. I have deep insights into what issues are plaguing Android developers the most, which Android platforms are the most difficult to develop on, and finally, which devices cause the most crashes.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,232
On SlideShare
0
From Embeds
0
Number of Embeds
63
Actions
Shares
0
Downloads
23
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

droidcon 2012: Developing Fault Tolerant, “German-Engineered” Android Apps, Andrew Levy, Crittercism

  1. 1. Developing Fault-Tolerant, !“German Engineered” Android Apps  Andrew  Levy  andrew@cri/ercism.com  CEO,  co-­‐founder  Cri/ercism  
  2. 2. [droidcon  ~]$  whoami  •  Andrew  Levy   –  Co-­‐founder  &  CEO  @Cri/ercism  •  Cri/ercism   –  Real-­‐Cme  crash  reports  and  error  analysis  for  mobile   developers   –  Analyzed  well  over  a  billion  applicaCon  loads  in  the   past  few  months   –  Backed  by  Google  Ventures,  Kleiner-­‐Perkins,  and   others   www.cri&ercism.com  -­‐  @cri&ercism  
  3. 3. What’s  Ahead   1.  TesCng  DifficulCes   2.  Top  5  Android  Crashes   3.  iOS  vs  Android,  which  crashes  less???   4.  Quick  peak  at  Cri/ercism’s  Error  Analysis   5.  QuesCons   6.  Free  SCckers   www.cri&ercism.com  -­‐  @cri&ercism  
  4. 4. Android Device DiversityExample  app  shortly  a_er  launch:  has  30k  DAU,  175k  unique  users,  50  different  devices   www.cri&ercism.com  -­‐  @cri&ercism  
  5. 5. iOS FragmentationThis  app  has  over  850,000  users,  26  diff  app  versions,  12  different  devices   www.cri&ercism.com  -­‐  @cri&ercism  
  6. 6. iOS  5.0.1   iOS  5.1  How Many iOS Versions Released? November  10   March  7   2011   2012   4.2.5 February 7, 2011 4.2.6 February 10, 2011 4.3 March 9, 2011 4.3.1 March 25, 2011 4.2.7 April 14, 2011 4.3.2 April 14, 20111.0 2.0 3.2.1 4.2.8June 29, 2007 July 11, 2008 July 15, 2010 May 4, 2011 1.1 1.1.5 4.0.1 4.2.9 September 14, 2007 July 15, 2008 July 15, 2010 July 15, 2011 1.1.1 2.0.2 3.0 3.2.2 4.3.4 September 27, 2007 August 18, 2008 June 17, 2009 August 11, 2010 July 15, 2011 1.1.2 2.1 3.0.1 3.1.3 4.0.2 4.2.10 November 12, 2007 September 9, 2008 July 31, 2009 February 2, 2010 August 11, 2010 July 25, 2011 1.0.2 1.1.4 2.2 3.1 4.0 4.2.1 4.3.5 August 21, 2007 February 26, 2008 November 21, 2008 September 9, 2009 June 21, 2010 November 22, 2010 July 25, 2011 1.0.1 1.1.3 2.0.1 2.2.1 3.1.2 3.2 4.1 4.3.3 5.0 July 31, 2007 January 15, 2008 August 4, 2008 January 27, 2009 October 8, 2009 April 3, 2010 September 8, 2010 May 4, 2011 October 12, 2011 iOS Versions 2008 2009 2010 2011 2012 www.cri&ercism.com  -­‐  @cri&ercism  
  7. 7. Android Testing!Build  &  Test    •  Integrated  TesCng  Tools  in  your  IDE   •  OEMs  (developer.samsung.com,  developer.motorola.com,  etc)   •  3rd  Party  SoluCons   •  RoboCum,  MonkeyRunner,  Robolectric,  etc    •  Remote  Device  TesCng   •  Also  offered  by  OEMs   •  Device  Anywhere,  uTest,  Mob4Hire,  Perfecto  Mobile,  etc.  •  Crashes  sCll  make  it  out  into  the  wild   •  QA  Matrix/PermutaCons     www.cri&ercism.com  -­‐  @cri&ercism  
  8. 8. Top 5 Android Crashes! +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3.  android.view.WindowManager$BadTokenException"!4.  java.lang.IllegalArgumentException & java.lang.RuntimeException!5.  android.database.sqlite.SQLiteException! www.cri&ercism.com  -­‐  @cri&ercism  
  9. 9. Top 5 Android Crashes! +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3.  android.view.WindowManager$BadTokenException"!4.  java.lang.IllegalArgumentException & java.lang.RuntimeException!5.  android.database.sqlite.SQLiteException! www.cri&ercism.com  -­‐  @cri&ercism  
  10. 10. java.lang.NullPointerException  •  “works  for  me”  is  not  a  good  test,  there  are  a   thousand  Android  devices   –  Assume  the  worst,  common  places  of  NPE:   •  #1  locaCon  in  code  for  NPEs  seems  to  be  onResume()   –  Probably  due  to  devs  assuming  class  members  accessible  a_er   onPause()   •  Data  from  intents   •  Peripheral/Sensor  data  (Camera,  GPS,  etc)   –  Some  of  these  errors  can  be  device/manufacturer  specific   •  Broadcast  receivers   www.cri&ercism.com  -­‐  @cri&ercism  
  11. 11. Top 5 Android Crashes! +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3.  android.view.WindowManager$BadTokenException"!4.  java.lang.IllegalArgumentException & java.lang.RuntimeException!5.  android.database.sqlite.SQLiteException! www.cri&ercism.com  -­‐  @cri&ercism  
  12. 12. Top 5 Android Crashes! +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3.  android.view.WindowManager$BadTokenException"!4.  java.lang.IllegalArgumentException & java.lang.RuntimeException!5.  android.database.sqlite.SQLiteException! www.cri&ercism.com  -­‐  @cri&ercism  
  13. 13. java.lang.OutOfMemoryError  Memory  Leak  in  Dalvik:  Keeping  a  reference  to  an  object  longer  than  needed            Not  the  best  idea:            try          {            //  allocate  lots  of  objects          }          catch(OutOfMemoryError  oom)          {            //  recycle  some  objects          }     www.cri&ercism.com  -­‐  @cri&ercism  
  14. 14. java.lang.OutOfMemoryError   Memory  Leak  in  Dalvik:  Keeping  a  reference  to  an  object  longer  than  needed    Biggest  Culprit:  Bitmaps  –  memory  usage   •  width  px  *  height  px  *  4  bytes  (for  ARGB  images)    –  So_References,  recycle  –  Pre  Honeycomb  (<3.0)  naCve  heap,  now  in  the  normal   heap   •  Use  hprof  -­‐-­‐  if  using  Eclipse,  Memory  Analyzer  (MAT)    ListViews  -­‐  Use  convertView  &  viewHolder  Pa/ern   www.cri&ercism.com  -­‐  @cri&ercism  
  15. 15. java.lang.OutOfMemoryError  •  What  about  the  NDK?   –  In  the  past  some  devs  built  their  C++  code  on   other  plaxorms,  then  used  tools  on  that  plaxorm   to  analyze   –  New  as  of  November  5,  2011:     •  Valgrind  3.7.0  adds  preliminary  ARM  Android  support   (2.3.x)   –  May  need  rooted  AOSP  build,  need  libc  with  debug  symbols   www.cri&ercism.com  -­‐  @cri&ercism  
  16. 16. Top 5 Android Crashes! +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3.  android.view.WindowManager$BadTokenException"!4.  java.lang.IllegalArgumentException & java.lang.RuntimeException!5.  android.database.sqlite.SQLiteException! www.cri&ercism.com  -­‐  @cri&ercism  
  17. 17. Top 5 Android Crashes! +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3.  android.view.WindowManager$BadTokenException"!4.  java.lang.IllegalArgumentException & java.lang.RuntimeException!5.  android.database.sqlite.SQLiteException! www.cri&ercism.com  -­‐  @cri&ercism  
  18. 18. android.view.WindowManager $BadTokenException  Biggest  Culprit:  Dialogs    •  Common  error  for  beginners,  creaCng  a  dialog  via   getApplicaConContext()   –  Android  docs  are  wrong,  need  to  create  dialog  in  context  of  an  AcCvity     www.cri&ercism.com  -­‐  @cri&ercism  
  19. 19. android.view.WindowManager $BadTokenException  Biggest  Culprit:  Dialogs    •  Anything  that  changes  the  context  of  the  acCvity  will  cause  issues   –  Showing  a  dialog  a_er  acCvity’s  onPause  is  called  (phone  call,  Back,  Home,  etc)   –  Examples   •  Screen  RotaCon  during  a  ProgressBar   –  The  most  common  (and  not  recommended)  fix:     »  Add  android:configChanges="orientaCon”  to  manifest,  just   onConfiguraConChanged  is  called   –  Recommended:     »  save  your  instance  state,  re-­‐set  any  acCvity  context  references  to  the  new   one   •  Launch  dialog  with  an  old/null  context   –  Be  sure  to  use  DialogFragment,  old  dialogs  are  deprecated   www.cri&ercism.com  -­‐  @cri&ercism  
  20. 20. Top 5 Android Crashes! +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3.  android.view.WindowManager$BadTokenException"!4.  java.lang.IllegalArgumentException & java.lang.RuntimeException!5.  android.database.sqlite.SQLiteException! www.cri&ercism.com  -­‐  @cri&ercism  
  21. 21. Top 5 Android Crashes! +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3.  android.view.WindowManager$BadTokenException"!4.  java.lang.IllegalArgumentException & java.lang.RuntimeException!5.  android.database.sqlite.SQLiteException! www.cri&ercism.com  -­‐  @cri&ercism  
  22. 22. java.lang.IllegalArgumentException! (extends java.lang.RuntimeException)    •  Common  Examples:   –  ContentProvider  does  not  exist   •  i.e.  try  the  Network  LocaCon  Provider  in  the  emulator   •  Don’t  use  undocumented  Content  Providers   –  Using  unknown  or  invalid  View  IDs   •  Confusing  a  string  idenCfier  and  integer  value  wrt  setValue()   –  AcCvity  is  finished  already,  but  you  call  dismiss  on  a  dialog   www.cri&ercism.com  -­‐  @cri&ercism  
  23. 23. java.lang.RuntimeException  •  Common  Pixalls   –  Forge{ng  to  add  an  AcCvity  to  the  Manifest   –  Failing  to  close  a  camera  service  before  using  it  again   •  Some  phones  have  a  race  condiCon  with  releasing  the  camera,  be   sure  to  make  these  calls  in  surfaceDestroyed   1.  cameraObject.setPreviewCallback(null);      //  prevent  race  condiCon   2.  cameraObject.stopPreview();   3.  cameraObject.release();   –  Loading  UI  elements  directly  from  a  background  thread   –  Trying  to  use  a  recycled  bitmap   www.cri&ercism.com  -­‐  @cri&ercism  
  24. 24. Top 5 Android Crashes! +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3.  android.view.WindowManager$BadTokenException"!4.  java.lang.IllegalArgumentException & java.lang.RuntimeException!5.  android.database.sqlite.SQLiteException! www.cri&ercism.com  -­‐  @cri&ercism  
  25. 25. Top 5 Android Crashes! +85% of crashes!1.  java.lang.NullPointerException!!2.  java.lang.OutOfMemoryError"!3.  android.view.WindowManager$BadTokenException"!4.  java.lang.IllegalArgumentException & java.lang.RuntimeException!5.  android.database.sqlite.SQLiteException! www.cri&ercism.com  -­‐  @cri&ercism  
  26. 26. android.database.sqlite.SQLiteException   •  Use  the  database  helper,  accessing  DB  file  directly   prone  to  errors   –  Read/write  permissions,  SD  card  issues,  etc.   •  Use  only  one  SQLite  connecCon   –  Even  if  you  use  threads,  share  one  connecCon   •  Prepared  Queries  with  unknown  columns  is  a  common   mistake   •  SQL  Syntax  Errors   www.cri&ercism.com  -­‐  @cri&ercism  
  27. 27. Crashes  on  iOS  &  Android   www.cri&ercism.com  -­‐  @cri&ercism  
  28. 28. Crashes  on  iOS  &  Android   Hard  to  read  pie  chart   www.cri&ercism.com  -­‐  @cri&ercism  
  29. 29. www.cri&ercism.com  -­‐  @cri&ercism  
  30. 30. www.cri&ercism.com  -­‐  @cri&ercism  
  31. 31. Questions?! Come find us at"Andrew  Levy  andrew@cri/ercism.com  @cri/ercism  and  @andrewmlevy  

×