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
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
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
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
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
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
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
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
Save your state properly! Use instance state, persistent storage, or some of the built in
Libc debug logcat
Reported as a bug 1.5 years ago, still not fixed
Pre honeycomb, will need compatibility library
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
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!