Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app crash: Why there is (Unknown Source) instead of line number

My app that I built and signed to publish crashes occasionally on my machine, in the logcat I open the stacktrace for a null pointer exception.. But I am not able locate exact line numbers ? because it say (Unknown Source) for example some lines look like this

   Caused by: java.lang.NullPointerException
   at   me.com.myapplication.a.i.d(Unknown Source)
   at   me.com.myapplication.MainActivity.onResume(Unknown Source)
   at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1210)

As you see where-ever there is my application package I see no line numbers instead it says Unknown Source.

Here is my gradle config for this project.

apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "me.com.myappliaction"
    minSdkVersion 8
    targetSdkVersion 21
    versionCode 6
    versionName "2.0"
}

signingConfigs {
    signed {
        storeFile file('../keystore/my.keystore')
        storePassword 'xxxxxx'
        keyAlias 'xxxxx'
        keyPassword 'xxxxxx'
    }
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

    signed {
        debuggable false
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.signed
    }

}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':mycomponent')
}

The app was using signed build variant. I used proguard command to read the trace properly using following syntax

retrace.bat|retrace.sh [-verbose] mapping.txt [<stacktrace_file>]

after this class names are shown better but still no line numbers ? I am wondering what exactly is wrong here that causes line numbers to be missing ?? How can I get trace that shows line numbers in my code and still be able to make it ready for publishing ?

like image 833
Ahmed Avatar asked Jun 25 '16 01:06

Ahmed


3 Answers

In order to retain debug information after ProGuard builds, you need to add the following configuration (to your proguard-rules.pro file):

-keepattributes SourceFile,LineNumberTable
# rename the source files to something meaningless, but it must be retained
-renamesourcefileattribute ''
like image 64
T. Neidhart Avatar answered Oct 19 '22 07:10

T. Neidhart


This error will occur when you have enabled minify in build.gradle.

minifyEnabled true

To get the line number while using proguard, you have to write following line inside proguard-rules.pro

-keepattributes *Annotation*,SourceFile,LineNumberTable

and you are done.

like image 37
Pankaj Lilan Avatar answered Oct 19 '22 08:10

Pankaj Lilan


You also could upload the mapping.txt file to your Google Play Developer Console. On the console just click on the app you want to deobfuscate. Then go to "Android vitals" > "ANRs & Crashes":

https://play.google.com/apps/publish/?dev_acc=[YOUR-DEV_ID]#DeobfuscationMappingFilesPlace:p=[your.app.package]

and upload the mapping.txt file that fits the current version of your app.

Location of mapping.txt:

Android Studio:

\[YOUR-PROJECT-DIR]\app\build\outputs\mapping\release\mapping.txt

Eclipse:

\[ECLIPSE-WORKSPACE]\[YOUR-PROJECT-DIR]\proguard\mapping.txt

Beware: Errors are deobfuscated only AFTER the upload of the mapping.txt. There is no deobfuscation of already reported crashes in the Google Play Developer Console.

like image 30
Richard R Avatar answered Oct 19 '22 09:10

Richard R