SlideShare uma empresa Scribd logo
1 de 31
Developing Fault-Tolerant,
“German Engineered” Android Apps




Andrew Levy
andrew@crittercism.com
CEO, co-founder Crittercism
[droidcon ~]$ whoami
• Andrew Levy
  – Co-founder & CEO @Crittercism

• Crittercism
  – Real-time crash reports and error analysis for mobile
    developers
  – Analyzed well over a billion application loads in the
    past few months
  – Backed by Google Ventures, Kleiner-Perkins, and
    others

                    www.crittercism.com - @crittercism
What’s Ahead
 1.   Testing Difficulties
 2.   Top 5 Android Crashes
 3.   iOS vs Android, which crashes less???
 4.   Quick peak at Crittercism’s Error Analysis
 5.   Questions
 6.   Free Stickers




                   www.crittercism.com - @crittercism
Android Device Diversity
Example app shortly after launch: has 30k DAU, 175k unique users, 50 different devices




                               www.crittercism.com - @crittercism
iOS Fragmentation




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




                                  www.crittercism.com - @crittercism
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                             J 11, 2008
                                           uly                                                                                J 15, 2010
                                                                                                                               uly                           May 4, 2011

        1.1                               1.1.5                                                                               4.0.1                                     4.2.9
        September 14, 2007                J 15, 2008
                                           uly                                                                                J 15, 2010
                                                                                                                               uly                                      J 15, 2011
                                                                                                                                                                         uly

          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                        J 15, 2011
                                                                                                                                                                         uly

                1.1.2                              2.1                                3.0.1                3.1.3                 4.0.2                                  4.2.10
                November 12, 2007                  September 9, 2008                  J 31, 2009
                                                                                       uly                 February 2, 2010      August 11, 2010                        J 25, 2011
                                                                                                                                                                         uly

     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           J 25, 2011
                                                                                                                                                                         uly

   1.0.1               1.1.3                   2.0.1               2.2.1                      3.1.2              3.2                4.1                      4.3.3              5.0
   J 31, 2007
    uly                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.crittercism.com - @crittercism
Android Testing
Build & Test

• Integrated Testing Tools in your IDE
    • OEMs (developer.samsung.com, developer.motorola.com, etc)
    • 3rd Party Solutions
        • Robotium, MonkeyRunner, Robolectric, etc

• Remote Device Testing
   • Also offered by OEMs
   • Device Anywhere, uTest, Mob4Hire, Perfecto Mobile, etc.

• Crashes still make it out into the wild
   • QA Matrix/Permutations



                            www.crittercism.com - @crittercism
Top 5 Android Crashes
               +85% of crashes
1. java.lang.NullPointerException

1. java.lang.OutOfMemoryError

2. android.view.WindowManager$BadTokenException

3. java.lang.IllegalArgumentException &
   java.lang.RuntimeException

4. android.database.sqlite.SQLiteException
                     www.crittercism.com - @crittercism
Top 5 Android Crashes
               +85% of crashes
1. java.lang.NullPointerException

1. java.lang.OutOfMemoryError

2. android.view.WindowManager$BadTokenException

3. java.lang.IllegalArgumentException &
   java.lang.RuntimeException

4. android.database.sqlite.SQLiteException
                     www.crittercism.com - @crittercism
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 location in code for NPEs seems to be onResume()
        – Probably due to devs assuming class members accessible after
          onPause()
     • Data from intents
     • Peripheral/Sensor data (Camera, GPS, etc)
        – Some of these errors can be device/manufacturer specific
     • Broadcast receivers

                      www.crittercism.com - @crittercism
Top 5 Android Crashes
               +85% of crashes
1. java.lang.NullPointerException

1. java.lang.OutOfMemoryError

2. android.view.WindowManager$BadTokenException

3. java.lang.IllegalArgumentException &
   java.lang.RuntimeException

4. android.database.sqlite.SQLiteException
                     www.crittercism.com - @crittercism
Top 5 Android Crashes
               +85% of crashes
1. java.lang.NullPointerException

1. java.lang.OutOfMemoryError

2. android.view.WindowManager$BadTokenException

3. java.lang.IllegalArgumentException &
   java.lang.RuntimeException

4. android.database.sqlite.SQLiteException
                     www.crittercism.com - @crittercism
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.crittercism.com - @crittercism
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)
– SoftReferences, recycle
– Pre Honeycomb (<3.0) native heap, now in the normal
  heap
    • Use hprof -- if using Eclipse, Memory Analyzer (MAT)

ListViews
- Use convertView & viewHolder Pattern
                        www.crittercism.com - @crittercism
java.lang.OutOfMemoryError
• What about the NDK?
  – In the past some devs built their C++ code on
    other platforms, then used tools on that platform
    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.crittercism.com - @crittercism
Top 5 Android Crashes
               +85% of crashes
1. java.lang.NullPointerException

1. java.lang.OutOfMemoryError

2. android.view.WindowManager$BadTokenException

3. java.lang.IllegalArgumentException &
   java.lang.RuntimeException

4. android.database.sqlite.SQLiteException
                     www.crittercism.com - @crittercism
Top 5 Android Crashes
               +85% of crashes
1. java.lang.NullPointerException

1. java.lang.OutOfMemoryError

2. android.view.WindowManager$BadTokenException

3. java.lang.IllegalArgumentException &
   java.lang.RuntimeException

4. android.database.sqlite.SQLiteException
                     www.crittercism.com - @crittercism
android.view.WindowManager$BadTok
             enException
 Biggest Culprit: Dialogs

 • Common error for beginners, creating a dialog via
   getApplicationContext()
    – Android docs are wrong, need to create dialog in context of an Activity




                           www.crittercism.com - @crittercism
android.view.WindowManager$BadTok
             enException
 Biggest Culprit: Dialogs

 • Anything that changes the context of the activity will cause issues

     – Showing a dialog after activity’s onPause is called (phone call, Back, Home, etc)

     – Examples
          • Screen Rotation during a ProgressBar
               – The most common (and not recommended) fix:
                    » Add android:configChanges="orientation” to manifest, just
                       onConfigurationChanged is called
               – Recommended:
                    » save your instance state, re-set any activity context references to the new
                       one
          • Launch dialog with an old/null context

     – Be sure to use DialogFragment, old dialogs are deprecated

                                 www.crittercism.com - @crittercism
Top 5 Android Crashes
               +85% of crashes
1. java.lang.NullPointerException

1. java.lang.OutOfMemoryError

2. android.view.WindowManager$BadTokenException

3. java.lang.IllegalArgumentException &
   java.lang.RuntimeException

4. android.database.sqlite.SQLiteException
                     www.crittercism.com - @crittercism
Top 5 Android Crashes
               +85% of crashes
1. java.lang.NullPointerException

1. java.lang.OutOfMemoryError

2. android.view.WindowManager$BadTokenException

3. java.lang.IllegalArgumentException &
   java.lang.RuntimeException

4. android.database.sqlite.SQLiteException
                     www.crittercism.com - @crittercism
java.lang.IllegalArgumentException
             (extends java.lang.RuntimeException)


• Common Examples:

   – ContentProvider does not exist
      • i.e. try the Network Location Provider in the emulator
      • Don’t use undocumented Content Providers

   – Using unknown or invalid View IDs
      • Confusing a string identifier and integer value wrt setValue()

   – Activity is finished already, but you call dismiss on a dialog


                           www.crittercism.com - @crittercism
java.lang.RuntimeException
• Common Pitfalls

   – Forgetting to add an Activity to the Manifest

   – Failing to close a camera service before using it again
       • Some phones have a race condition with releasing the camera, be sure
         to make these calls in surfaceDestroyed
           1.   cameraObject.setPreviewCallback(null); // prevent race condition
           2.   cameraObject.stopPreview();
           3.   cameraObject.release();

   – Loading UI elements directly from a background thread

   – Trying to use a recycled bitmap

                            www.crittercism.com - @crittercism
Top 5 Android Crashes
               +85% of crashes
1. java.lang.NullPointerException

1. java.lang.OutOfMemoryError

2. android.view.WindowManager$BadTokenException

3. java.lang.IllegalArgumentException &
   java.lang.RuntimeException

4. android.database.sqlite.SQLiteException
                     www.crittercism.com - @crittercism
Top 5 Android Crashes
               +85% of crashes
1. java.lang.NullPointerException

1. java.lang.OutOfMemoryError

2. android.view.WindowManager$BadTokenException

3. java.lang.IllegalArgumentException &
   java.lang.RuntimeException

4. android.database.sqlite.SQLiteException
                     www.crittercism.com - @crittercism
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 connection
   – Even if you use threads, share one connection

• Prepared Queries with unknown columns is a common
  mistake

• SQL Syntax Errors

                      www.crittercism.com - @crittercism
Crashes on iOS & Android




       www.crittercism.com - @crittercism
Crashes on iOS & Android




                                            Hard to read pie chart
       www.crittercism.com - @crittercism
www.crittercism.com - @crittercism
www.crittercism.com - @crittercism
Questions?




Andrew Levy
andrew@crittercism.com
@crittercism and @andrewmlevy

Mais conteúdo relacionado

Semelhante a Crittercism Droidcon Berlin 2012 (10)

Can Metadata Keep Libraries Relevant?
Can Metadata Keep Libraries Relevant?Can Metadata Keep Libraries Relevant?
Can Metadata Keep Libraries Relevant?
 
Career plan template
Career plan templateCareer plan template
Career plan template
 
Muller and Chua - brainstorming for japan - chi 2012
Muller and Chua - brainstorming for japan - chi 2012Muller and Chua - brainstorming for japan - chi 2012
Muller and Chua - brainstorming for japan - chi 2012
 
Einstein finalist.nl
Einstein finalist.nlEinstein finalist.nl
Einstein finalist.nl
 
Inspiratiemiddag_Vincent_Everts_Finalist generatie_einstein_komt_eraan_07042011
Inspiratiemiddag_Vincent_Everts_Finalist generatie_einstein_komt_eraan_07042011Inspiratiemiddag_Vincent_Everts_Finalist generatie_einstein_komt_eraan_07042011
Inspiratiemiddag_Vincent_Everts_Finalist generatie_einstein_komt_eraan_07042011
 
Gantt chart for work
Gantt chart for workGantt chart for work
Gantt chart for work
 
Career plan template
Career plan templateCareer plan template
Career plan template
 
Koss, How to make desktop caliber browser apps
Koss, How to make desktop caliber browser appsKoss, How to make desktop caliber browser apps
Koss, How to make desktop caliber browser apps
 
SeaJS - 跨环境模块化开发实践
SeaJS - 跨环境模块化开发实践SeaJS - 跨环境模块化开发实践
SeaJS - 跨环境模块化开发实践
 
Capstone project timeline
Capstone project timelineCapstone project timeline
Capstone project timeline
 

Mais de Apteligent

WEBINAR: HOW URBAN OUTFITTERS MADE A 7X IMPROVEMENT IN THEIR MOBILE APP PERFO...
WEBINAR: HOW URBAN OUTFITTERS MADE A 7X IMPROVEMENT IN THEIR MOBILE APP PERFO...WEBINAR: HOW URBAN OUTFITTERS MADE A 7X IMPROVEMENT IN THEIR MOBILE APP PERFO...
WEBINAR: HOW URBAN OUTFITTERS MADE A 7X IMPROVEMENT IN THEIR MOBILE APP PERFO...
Apteligent
 
Getting to Mobile First: 5 Numbers to Consider!
Getting to Mobile First: 5 Numbers to Consider!Getting to Mobile First: 5 Numbers to Consider!
Getting to Mobile First: 5 Numbers to Consider!
Apteligent
 

Mais de Apteligent (16)

Mobile App User Experience Myths, Debunked
Mobile App User Experience Myths, DebunkedMobile App User Experience Myths, Debunked
Mobile App User Experience Myths, Debunked
 
Harnessing Data to Reduce User Churn
Harnessing Data to Reduce User ChurnHarnessing Data to Reduce User Churn
Harnessing Data to Reduce User Churn
 
Apteligent - Choosing the Right SDKs to Optimize App Performance
Apteligent - Choosing the Right SDKs to Optimize App PerformanceApteligent - Choosing the Right SDKs to Optimize App Performance
Apteligent - Choosing the Right SDKs to Optimize App Performance
 
Apteligent Data Report Google IO Edition
Apteligent Data Report Google IO EditionApteligent Data Report Google IO Edition
Apteligent Data Report Google IO Edition
 
Apteligent Data Report iOS 9.3 Edition
Apteligent Data Report iOS 9.3 EditionApteligent Data Report iOS 9.3 Edition
Apteligent Data Report iOS 9.3 Edition
 
7 Tips for Optimizing Mobile App Metrics
7 Tips for Optimizing Mobile App Metrics7 Tips for Optimizing Mobile App Metrics
7 Tips for Optimizing Mobile App Metrics
 
50 Beautifully Designed Apple Watch Apps
50 Beautifully Designed Apple Watch Apps50 Beautifully Designed Apple Watch Apps
50 Beautifully Designed Apple Watch Apps
 
State of Mobile Benchmark Report - MWC 2015 Edition
State of Mobile Benchmark Report -  MWC 2015 EditionState of Mobile Benchmark Report -  MWC 2015 Edition
State of Mobile Benchmark Report - MWC 2015 Edition
 
Accenture Digital: iOS 8 What You Need to Know
Accenture Digital: iOS 8 What You Need to KnowAccenture Digital: iOS 8 What You Need to Know
Accenture Digital: iOS 8 What You Need to Know
 
Apple Edition: iOS Mobile Experience Report
Apple Edition: iOS Mobile Experience ReportApple Edition: iOS Mobile Experience Report
Apple Edition: iOS Mobile Experience Report
 
50 Connected Devices - How Mobile and the Internet of Things Will Affect You
50 Connected Devices - How Mobile and the Internet of Things Will Affect You50 Connected Devices - How Mobile and the Internet of Things Will Affect You
50 Connected Devices - How Mobile and the Internet of Things Will Affect You
 
Mobile DevOps
Mobile DevOpsMobile DevOps
Mobile DevOps
 
Samsung Android Crash & Performance Analysis
Samsung Android Crash & Performance AnalysisSamsung Android Crash & Performance Analysis
Samsung Android Crash & Performance Analysis
 
testCloud & Crittercism: How to Continuously Ensure Mobile App Quality
testCloud & Crittercism: How to Continuously Ensure Mobile App QualitytestCloud & Crittercism: How to Continuously Ensure Mobile App Quality
testCloud & Crittercism: How to Continuously Ensure Mobile App Quality
 
WEBINAR: HOW URBAN OUTFITTERS MADE A 7X IMPROVEMENT IN THEIR MOBILE APP PERFO...
WEBINAR: HOW URBAN OUTFITTERS MADE A 7X IMPROVEMENT IN THEIR MOBILE APP PERFO...WEBINAR: HOW URBAN OUTFITTERS MADE A 7X IMPROVEMENT IN THEIR MOBILE APP PERFO...
WEBINAR: HOW URBAN OUTFITTERS MADE A 7X IMPROVEMENT IN THEIR MOBILE APP PERFO...
 
Getting to Mobile First: 5 Numbers to Consider!
Getting to Mobile First: 5 Numbers to Consider!Getting to Mobile First: 5 Numbers to Consider!
Getting to Mobile First: 5 Numbers to Consider!
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+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@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
+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...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

Crittercism Droidcon Berlin 2012

  • 1. Developing Fault-Tolerant, “German Engineered” Android Apps Andrew Levy andrew@crittercism.com CEO, co-founder Crittercism
  • 2. [droidcon ~]$ whoami • Andrew Levy – Co-founder & CEO @Crittercism • Crittercism – Real-time crash reports and error analysis for mobile developers – Analyzed well over a billion application loads in the past few months – Backed by Google Ventures, Kleiner-Perkins, and others www.crittercism.com - @crittercism
  • 3. What’s Ahead 1. Testing Difficulties 2. Top 5 Android Crashes 3. iOS vs Android, which crashes less??? 4. Quick peak at Crittercism’s Error Analysis 5. Questions 6. Free Stickers www.crittercism.com - @crittercism
  • 4. Android Device Diversity Example app shortly after launch: has 30k DAU, 175k unique users, 50 different devices www.crittercism.com - @crittercism
  • 5. iOS Fragmentation This app has over 850,000 users, 26 diff app versions, 12 different devices www.crittercism.com - @crittercism
  • 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 J 11, 2008 uly J 15, 2010 uly May 4, 2011 1.1 1.1.5 4.0.1 4.2.9 September 14, 2007 J 15, 2008 uly J 15, 2010 uly J 15, 2011 uly 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 J 15, 2011 uly 1.1.2 2.1 3.0.1 3.1.3 4.0.2 4.2.10 November 12, 2007 September 9, 2008 J 31, 2009 uly February 2, 2010 August 11, 2010 J 25, 2011 uly 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 J 25, 2011 uly 1.0.1 1.1.3 2.0.1 2.2.1 3.1.2 3.2 4.1 4.3.3 5.0 J 31, 2007 uly 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.crittercism.com - @crittercism
  • 7. Android Testing Build & Test • Integrated Testing Tools in your IDE • OEMs (developer.samsung.com, developer.motorola.com, etc) • 3rd Party Solutions • Robotium, MonkeyRunner, Robolectric, etc • Remote Device Testing • Also offered by OEMs • Device Anywhere, uTest, Mob4Hire, Perfecto Mobile, etc. • Crashes still make it out into the wild • QA Matrix/Permutations www.crittercism.com - @crittercism
  • 8. Top 5 Android Crashes +85% of crashes 1. java.lang.NullPointerException 1. java.lang.OutOfMemoryError 2. android.view.WindowManager$BadTokenException 3. java.lang.IllegalArgumentException & java.lang.RuntimeException 4. android.database.sqlite.SQLiteException www.crittercism.com - @crittercism
  • 9. Top 5 Android Crashes +85% of crashes 1. java.lang.NullPointerException 1. java.lang.OutOfMemoryError 2. android.view.WindowManager$BadTokenException 3. java.lang.IllegalArgumentException & java.lang.RuntimeException 4. android.database.sqlite.SQLiteException www.crittercism.com - @crittercism
  • 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 location in code for NPEs seems to be onResume() – Probably due to devs assuming class members accessible after onPause() • Data from intents • Peripheral/Sensor data (Camera, GPS, etc) – Some of these errors can be device/manufacturer specific • Broadcast receivers www.crittercism.com - @crittercism
  • 11. Top 5 Android Crashes +85% of crashes 1. java.lang.NullPointerException 1. java.lang.OutOfMemoryError 2. android.view.WindowManager$BadTokenException 3. java.lang.IllegalArgumentException & java.lang.RuntimeException 4. android.database.sqlite.SQLiteException www.crittercism.com - @crittercism
  • 12. Top 5 Android Crashes +85% of crashes 1. java.lang.NullPointerException 1. java.lang.OutOfMemoryError 2. android.view.WindowManager$BadTokenException 3. java.lang.IllegalArgumentException & java.lang.RuntimeException 4. android.database.sqlite.SQLiteException www.crittercism.com - @crittercism
  • 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.crittercism.com - @crittercism
  • 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) – SoftReferences, recycle – Pre Honeycomb (<3.0) native heap, now in the normal heap • Use hprof -- if using Eclipse, Memory Analyzer (MAT) ListViews - Use convertView & viewHolder Pattern www.crittercism.com - @crittercism
  • 15. java.lang.OutOfMemoryError • What about the NDK? – In the past some devs built their C++ code on other platforms, then used tools on that platform 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.crittercism.com - @crittercism
  • 16. Top 5 Android Crashes +85% of crashes 1. java.lang.NullPointerException 1. java.lang.OutOfMemoryError 2. android.view.WindowManager$BadTokenException 3. java.lang.IllegalArgumentException & java.lang.RuntimeException 4. android.database.sqlite.SQLiteException www.crittercism.com - @crittercism
  • 17. Top 5 Android Crashes +85% of crashes 1. java.lang.NullPointerException 1. java.lang.OutOfMemoryError 2. android.view.WindowManager$BadTokenException 3. java.lang.IllegalArgumentException & java.lang.RuntimeException 4. android.database.sqlite.SQLiteException www.crittercism.com - @crittercism
  • 18. android.view.WindowManager$BadTok enException Biggest Culprit: Dialogs • Common error for beginners, creating a dialog via getApplicationContext() – Android docs are wrong, need to create dialog in context of an Activity www.crittercism.com - @crittercism
  • 19. android.view.WindowManager$BadTok enException Biggest Culprit: Dialogs • Anything that changes the context of the activity will cause issues – Showing a dialog after activity’s onPause is called (phone call, Back, Home, etc) – Examples • Screen Rotation during a ProgressBar – The most common (and not recommended) fix: » Add android:configChanges="orientation” to manifest, just onConfigurationChanged is called – Recommended: » save your instance state, re-set any activity context references to the new one • Launch dialog with an old/null context – Be sure to use DialogFragment, old dialogs are deprecated www.crittercism.com - @crittercism
  • 20. Top 5 Android Crashes +85% of crashes 1. java.lang.NullPointerException 1. java.lang.OutOfMemoryError 2. android.view.WindowManager$BadTokenException 3. java.lang.IllegalArgumentException & java.lang.RuntimeException 4. android.database.sqlite.SQLiteException www.crittercism.com - @crittercism
  • 21. Top 5 Android Crashes +85% of crashes 1. java.lang.NullPointerException 1. java.lang.OutOfMemoryError 2. android.view.WindowManager$BadTokenException 3. java.lang.IllegalArgumentException & java.lang.RuntimeException 4. android.database.sqlite.SQLiteException www.crittercism.com - @crittercism
  • 22. java.lang.IllegalArgumentException (extends java.lang.RuntimeException) • Common Examples: – ContentProvider does not exist • i.e. try the Network Location Provider in the emulator • Don’t use undocumented Content Providers – Using unknown or invalid View IDs • Confusing a string identifier and integer value wrt setValue() – Activity is finished already, but you call dismiss on a dialog www.crittercism.com - @crittercism
  • 23. java.lang.RuntimeException • Common Pitfalls – Forgetting to add an Activity to the Manifest – Failing to close a camera service before using it again • Some phones have a race condition with releasing the camera, be sure to make these calls in surfaceDestroyed 1. cameraObject.setPreviewCallback(null); // prevent race condition 2. cameraObject.stopPreview(); 3. cameraObject.release(); – Loading UI elements directly from a background thread – Trying to use a recycled bitmap www.crittercism.com - @crittercism
  • 24. Top 5 Android Crashes +85% of crashes 1. java.lang.NullPointerException 1. java.lang.OutOfMemoryError 2. android.view.WindowManager$BadTokenException 3. java.lang.IllegalArgumentException & java.lang.RuntimeException 4. android.database.sqlite.SQLiteException www.crittercism.com - @crittercism
  • 25. Top 5 Android Crashes +85% of crashes 1. java.lang.NullPointerException 1. java.lang.OutOfMemoryError 2. android.view.WindowManager$BadTokenException 3. java.lang.IllegalArgumentException & java.lang.RuntimeException 4. android.database.sqlite.SQLiteException www.crittercism.com - @crittercism
  • 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 connection – Even if you use threads, share one connection • Prepared Queries with unknown columns is a common mistake • SQL Syntax Errors www.crittercism.com - @crittercism
  • 27. Crashes on iOS & Android www.crittercism.com - @crittercism
  • 28. Crashes on iOS & Android Hard to read pie chart www.crittercism.com - @crittercism

Notas do Editor

  1. Identify errors, be very proactive,
  2. this app is now available on hundreds of devices
  3. And it’s not just a problem on Android. Let’s think about iOS. How many version of iOS do you think have been released in the past 4 years? There’s been a total of 41 operating systems released so far – about 1 version a month. iOS version 5.0 which comes out tomorrow will be the 13th new operating system this year. 17 versions for AndroidiOS 5.0.2 delayed because of memory leaks
  4. A lot of these solutions are just functional tests, but simply cant scale to the number of permutations of device configurations and application use, give a shoutout to bitbar
  5. Save your state properly! Use instance state, persistent storage, or some of the built in
  6. Libc debug logcat
  7. Reported as a bug 1.5 years ago, still not fixed
  8. Pre honeycomb, will need compatibility library
  9. Boring one, Not one clear leader here for the cause of issue, lets say you want to display an integer in a label, if you forget to cast it to a string it’ll look for an ID of string resource instead
  10. These are easy to run into. The common theme here is clear your resources when you’re done, close your file descriptors, not only will it contribute to memory issues but you may end up running into a RuntimeException anyway. Of course, be careful once you clear a resource, and then try to use the cleared resource again!