[英]How to debug android app on release mode?
When I create the apk on release mode it crashes on start up 当我在发布模式下创建apk时,它会在启动时崩溃
The problem happens when I enable minifyEnabled for proguard and I solved it by adding below code to proguard-rules.pro 当我为proguard启用minifyEnabled时会出现问题,我通过将以下代码添加到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 . 我认为原因是proguard删除了我的一些代码,但我不知道哪个部分因为它模糊了我的代码并且读取logcat是没用的。 Is there anyway I understand the logcat message ? 反正我知道logcat消息吗?
java.lang.NullPointerException: throw with null exception
at e.a.z.a(:176)
at i.n.run(:71)
Since this is a production running application, do NOT compromise obfuscation (using keepattributes ) if you just need to understand crash reports. 由于这是一个生产运行的应用程序,如果您只需要了解崩溃报告,请不要妥协混淆(使用keepattributes )。
This is detailed in the android / google guidelines. 这在android / google指南中有详细说明。 You can upload symbol mapping files created by proguard that allows the crash reports to be de-obfuscated. 您可以上载proguard创建的符号映射文件,以便对崩溃报告进行反模糊处理。
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 这在这里解释: 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 Proguard有一个Retrace API,如下所述: 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 然后上传到谷歌播放以获得去混淆的报告: https : //support.google.com/googleplay/android-developer/answer/6295281
You can configure proguard to have some more information. 您可以配置proguard以获取更多信息。
-keepattributes SourceFile,LineNumberTable -keepattributes SourceFile,LineNumberTable
This would preserve file name and line numbers as well, so you will have more data in your logcat. 这也会保留文件名和行号,因此您的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. 另外,在调试版本中使用minifyEnabled
,以便将proguard应用于您的调试版本,并且您可以更好地调试它。
Once you find and fix the issue, you can remove it from the proguard. 找到并解决问题后,您可以将其从proguard中删除。
Android requires the following proguard rules to keep an Android app working: Android需要以下proguard规则才能保持Android应用的正常运行:
-keep public class * extends android.app.Activity
-keep public class * extends androidx.appcompat.app.AppCompatActivity
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
If you want to de-obfuscate the stacktrace, take a look at this guide . 如果要对堆栈跟踪进行去混淆,请查看本指南 。
If you would like to go step-by-step through your release build (the same way as you do in debug), try adding debuggable true
to your gradle configuration ( app\\build.gradle
): 如果您希望逐步完成发布版本(与调试时相同),请尝试将debuggable true
添加到您的gradle配置( app\\build.gradle
):
android
{
buildTypes
{
release {
proguardFiles 'your-proguard-config.pro'
debuggable true //<-- add this
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.