Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug android app on release mode?

When I create the apk on release mode it crashes on start up

The problem happens when I enable minifyEnabled for proguard and I solved it by adding below code to proguard-rules.pro

-keep class my.package.name.** {*;}

I think the reason is proguard delete some of my code but I don't know which part because it obscure my code and reading logcat is useless . Is there anyway I understand the logcat message ?

java.lang.NullPointerException: throw with null exception
    at e.a.z.a(:176)
    at i.n.run(:71)
like image 257
Alireza Avatar asked Jun 13 '19 09:06

Alireza


2 Answers

Since this is a production running application, do NOT compromise obfuscation (using keepattributes) if you just need to understand crash reports.

This is detailed in the android / google guidelines. You can upload symbol mapping files created by proguard that allows the crash reports to be de-obfuscated.

The mapping files are usually generated here:

build/outputs/mapping/release/mapping.txt

This is explained here : https://developer.android.com/studio/build/shrink-code#decode-stack-trace

Proguard has a Retrace API described here : https://www.guardsquare.com/en/products/proguard/manual/retrace

And here on to upload to google-play to get de-obfuscated reports : https://support.google.com/googleplay/android-developer/answer/6295281

like image 92
ehanoc Avatar answered Dec 17 '22 16:12

ehanoc


You can configure proguard to have some more information.

-keepattributes SourceFile,LineNumberTable

This would preserve file name and line numbers as well, so you will have more data in your logcat.

Also, use minifyEnabled on your debug build so that proguard would be applied to your debug build and you would be able to debug it better.

Once you find and fix the issue, you can remove it from the proguard.

like image 40
Froyo Avatar answered Dec 17 '22 18:12

Froyo