Andrei Herford
Andrei Herford

Reputation: 18735

How to find crash source using Android Developer Console crash report?

Since I published a new version of my app in the Google Play Store I receive crash reports in the Android Developer Console.

I have uploaded the ProGuard mappings.txt right after publishing the new version. Thus all log are NOT obfuscated (all class names and methods apear in clear text). However I am still not sure hot to read them.

There are three major problems:

  1. The report only shows the crashing method but no line numbers. So I have no idea which part of a method caused the crash.
  2. Some crash reports shows different methods using OR. What does this mean?
  3. Not all reports are de-obfuscated. Some are still shown with anonymous class and method names

Example:

// Crash Log with is NOT obfuscated
Caused by: java.lang.NullPointerException: 
1:  at com.example.MyApp.Path.To.Package.MyClass.myMethod1 (MyClass.java)  // <-- No Line Numbers...
    or                     .myMethod2 (MyClass.java)    // <-- WHAT does this OR mean???
    or                     .myMethod3 (MyClass.java)
2:  at com.example.MyApp.Path.To.Package.MyClass.onCreateView (MyClass.java)
3:  at android.support.v4.app.Fragment.performCreateView (Fragment.java)
4:  at android.support.v4.app.FragmentManagerImpl.access$500 (FragmentManagerImpl.java)
    or                     .access$600 (FragmentManagerImpl.java)
    or                     .addFragment (FragmentManagerImpl.java)
    or                     .allocBackStackIndex (FragmentManagerImpl.java)
    or                     .animateRemoveFragment (FragmentManagerImpl.java)
    ...

5:  at android.support.v4.app.FragmentManagerImpl.access$500 (FragmentManagerImpl.java)
...


// Other crash seems to show the same problem but is still obfuscated
Caused by: java.lang.NullPointerException: 
1:  at com.example.MyApp.Path.To.Package.MyClass.a (MyClass.java:89)  // <-- Line numbers available here...
2:  at com.example.MyApp.Path.To.Package.MyClass.b (MyClass.java:40)
3:  at android.support.v4.app.Fragment.performCreateView (Fragment.java)
... // Same call stack as above  

Questions:

So the main question is:

How to use the information from the logs to find the source of the crash?

Upvotes: 4

Views: 979

Answers (2)

jmart
jmart

Reputation: 2931

You need to add the following options to your Proguard configuration:

# This option forces Proguard to use different obfuscated names
# for different members. It avoids the 'or' stack traces.
-useuniqueclassmembernames

# These options produce useful stacktraces preserving line numbers
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

Without -useuniqueclassmembernames, Proguard can assign identical obfuscated names for different methods from the same class (you can see it on the mapping.txt file). That's why the stacktrace knows the error happened in Method A or in Method B, but doesn't know exactly which one.

Using the -useuniqueclassmembernames option, all obfuscated names will be different and there will be no more or stacktraces. More information about this here.

Apart from this, Proguard doesn't keep information about line numbers unless we use the -renamesourcefileattribute and -keepattributes options as indicated. More information about this here.

These options will increase your apk size a bit, but it's totally worth it. This saved me many headaches analyzing my stacktraces.

Upvotes: 4

Absar Alam
Absar Alam

Reputation: 96

Better to use Fabrics instead. It will give crash report along with line numbers.

Upvotes: 0

Related Questions