SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
Developing Fault-Tolerant, !
“German Engineered” Android Apps	
  




Andrew	
  Levy	
  
andrew@cri/ercism.com	
  
CEO,	
  co-­‐founder	
  Cri/ercism	
  
[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	
  
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	
  
Android Device Diversity
Example	
  app	
  shortly	
  a_er	
  launch:	
  has	
  30k	
  DAU,	
  175k	
  unique	
  users,	
  50	
  different	
  devices	
  




                                             www.cri&ercism.com	
  -­‐	
  @cri&ercism	
  
iOS Fragmentation




This	
  app	
  has	
  over	
  850,000	
  users,	
  
26	
  diff	
  app	
  versions,	
  12	
  different	
  
devices	
  




                                                      www.cri&ercism.com	
  -­‐	
  @cri&ercism	
  
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, 2011

1.0                                       2.0                                                                                   3.2.1                            4.2.8
June 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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
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	
  
Crashes	
  on	
  iOS	
  &	
  Android	
  




           www.cri&ercism.com	
  -­‐	
  @cri&ercism	
  
Crashes	
  on	
  iOS	
  &	
  Android	
  




                                                          Hard	
  to	
  read	
  pie	
  chart	
  
           www.cri&ercism.com	
  -­‐	
  @cri&ercism	
  
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	
  @andrewmlevy	
  

Más contenido relacionado

Más de Droidcon Berlin

Droidcon de 2014 google cast
Droidcon de 2014   google castDroidcon de 2014   google cast
Droidcon de 2014 google castDroidcon Berlin
 
Android programming -_pushing_the_limits
Android programming -_pushing_the_limitsAndroid programming -_pushing_the_limits
Android programming -_pushing_the_limitsDroidcon Berlin
 
Android industrial mobility
Android industrial mobility Android industrial mobility
Android industrial mobility Droidcon Berlin
 
From sensor data_to_android_and_back
From sensor data_to_android_and_backFrom sensor data_to_android_and_back
From sensor data_to_android_and_backDroidcon Berlin
 
Testing and Building Android
Testing and Building AndroidTesting and Building Android
Testing and Building AndroidDroidcon Berlin
 
Matchinguu droidcon presentation
Matchinguu droidcon presentationMatchinguu droidcon presentation
Matchinguu droidcon presentationDroidcon Berlin
 
Cgm life sdk_droidcon_2014_v3
Cgm life sdk_droidcon_2014_v3Cgm life sdk_droidcon_2014_v3
Cgm life sdk_droidcon_2014_v3Droidcon Berlin
 
Raesch, gries droidcon 2014
Raesch, gries   droidcon 2014Raesch, gries   droidcon 2014
Raesch, gries droidcon 2014Droidcon Berlin
 
Android open gl2_droidcon_2014
Android open gl2_droidcon_2014Android open gl2_droidcon_2014
Android open gl2_droidcon_2014Droidcon Berlin
 
20140508 quantified self droidcon
20140508 quantified self droidcon20140508 quantified self droidcon
20140508 quantified self droidconDroidcon Berlin
 
Tuning android for low ram devices
Tuning android for low ram devicesTuning android for low ram devices
Tuning android for low ram devicesDroidcon Berlin
 
Froyo to kit kat two years developing & maintaining deliradio
Froyo to kit kat   two years developing & maintaining deliradioFroyo to kit kat   two years developing & maintaining deliradio
Froyo to kit kat two years developing & maintaining deliradioDroidcon Berlin
 
Droidcon2013 security genes_trendmicro
Droidcon2013 security genes_trendmicroDroidcon2013 security genes_trendmicro
Droidcon2013 security genes_trendmicroDroidcon Berlin
 
Droidcon2013 commercialsuccess rannenberg
Droidcon2013 commercialsuccess rannenbergDroidcon2013 commercialsuccess rannenberg
Droidcon2013 commercialsuccess rannenbergDroidcon Berlin
 
Droidcon2013 bootstrap luedeke
Droidcon2013 bootstrap luedekeDroidcon2013 bootstrap luedeke
Droidcon2013 bootstrap luedekeDroidcon Berlin
 

Más de Droidcon Berlin (20)

Droidcon de 2014 google cast
Droidcon de 2014   google castDroidcon de 2014   google cast
Droidcon de 2014 google cast
 
Android programming -_pushing_the_limits
Android programming -_pushing_the_limitsAndroid programming -_pushing_the_limits
Android programming -_pushing_the_limits
 
crashing in style
crashing in stylecrashing in style
crashing in style
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
 
Android industrial mobility
Android industrial mobility Android industrial mobility
Android industrial mobility
 
Details matter in ux
Details matter in uxDetails matter in ux
Details matter in ux
 
From sensor data_to_android_and_back
From sensor data_to_android_and_backFrom sensor data_to_android_and_back
From sensor data_to_android_and_back
 
droidparts
droidpartsdroidparts
droidparts
 
5 tips of monetization
5 tips of monetization5 tips of monetization
5 tips of monetization
 
Testing and Building Android
Testing and Building AndroidTesting and Building Android
Testing and Building Android
 
Matchinguu droidcon presentation
Matchinguu droidcon presentationMatchinguu droidcon presentation
Matchinguu droidcon presentation
 
Cgm life sdk_droidcon_2014_v3
Cgm life sdk_droidcon_2014_v3Cgm life sdk_droidcon_2014_v3
Cgm life sdk_droidcon_2014_v3
 
Raesch, gries droidcon 2014
Raesch, gries   droidcon 2014Raesch, gries   droidcon 2014
Raesch, gries droidcon 2014
 
Android open gl2_droidcon_2014
Android open gl2_droidcon_2014Android open gl2_droidcon_2014
Android open gl2_droidcon_2014
 
20140508 quantified self droidcon
20140508 quantified self droidcon20140508 quantified self droidcon
20140508 quantified self droidcon
 
Tuning android for low ram devices
Tuning android for low ram devicesTuning android for low ram devices
Tuning android for low ram devices
 
Froyo to kit kat two years developing & maintaining deliradio
Froyo to kit kat   two years developing & maintaining deliradioFroyo to kit kat   two years developing & maintaining deliradio
Froyo to kit kat two years developing & maintaining deliradio
 
Droidcon2013 security genes_trendmicro
Droidcon2013 security genes_trendmicroDroidcon2013 security genes_trendmicro
Droidcon2013 security genes_trendmicro
 
Droidcon2013 commercialsuccess rannenberg
Droidcon2013 commercialsuccess rannenbergDroidcon2013 commercialsuccess rannenberg
Droidcon2013 commercialsuccess rannenberg
 
Droidcon2013 bootstrap luedeke
Droidcon2013 bootstrap luedekeDroidcon2013 bootstrap luedeke
Droidcon2013 bootstrap luedeke
 

Último

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Último (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Developing Fault-Tolerant Android Apps

  • 1. Developing Fault-Tolerant, ! “German Engineered” Android Apps   Andrew  Levy   andrew@cri/ercism.com   CEO,  co-­‐founder  Cri/ercism  
  • 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. 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. Android Device Diversity Example  app  shortly  a_er  launch:  has  30k  DAU,  175k  unique  users,  50  different  devices   www.cri&ercism.com  -­‐  @cri&ercism  
  • 5. iOS Fragmentation This  app  has  over  850,000  users,   26  diff  app  versions,  12  different   devices   www.cri&ercism.com  -­‐  @cri&ercism  
  • 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, 2011 1.0 2.0 3.2.1 4.2.8 June 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. Crashes  on  iOS  &  Android   www.cri&ercism.com  -­‐  @cri&ercism  
  • 28. Crashes  on  iOS  &  Android   Hard  to  read  pie  chart   www.cri&ercism.com  -­‐  @cri&ercism  
  • 31. Questions?! Come find us at" Andrew  Levy   andrew@cri/ercism.com   @cri/ercism  and  @andrewmlevy