[英]How to debug the Android App in release mode using Android studio
[英]How to debug android app on release mode?
当我在发布模式下创建apk时,它会在启动时崩溃
当我为proguard启用minifyEnabled时会出现问题,我通过将以下代码添加到proguard-rules.pro来解决它
-keep class my.package.name.** {*;}
我认为原因是proguard删除了我的一些代码,但我不知道哪个部分因为它模糊了我的代码并且读取logcat是没用的。 反正我知道logcat消息吗?
java.lang.NullPointerException: throw with null exception
at e.a.z.a(:176)
at i.n.run(:71)
由于这是一个生产运行的应用程序,如果您只需要了解崩溃报告,请不要妥协混淆(使用keepattributes )。
这在android / google指南中有详细说明。 您可以上载proguard创建的符号映射文件,以便对崩溃报告进行反模糊处理。
映射文件通常在这里生成:
build/outputs/mapping/release/mapping.txt
这在这里解释: https : //developer.android.com/studio/build/shrink-code#decode-stack-trace
Proguard有一个Retrace API,如下所述: https : //www.guardsquare.com/en/products/proguard/manual/retrace
然后上传到谷歌播放以获得去混淆的报告: https : //support.google.com/googleplay/android-developer/answer/6295281
您可以配置proguard以获取更多信息。
-keepattributes SourceFile,LineNumberTable
这也会保留文件名和行号,因此您的logcat中将有更多数据。
另外,在调试版本中使用minifyEnabled
,以便将proguard应用于您的调试版本,并且您可以更好地调试它。
找到并解决问题后,您可以将其从proguard中删除。
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>;
}
如果要对堆栈跟踪进行去混淆,请查看本指南 。
如果您希望逐步完成发布版本(与调试时相同),请尝试将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.