简体   繁体   English

如何在发布模式下调试Android应用程序?

[英]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.

相关问题 如何使用 Android Studio 在发布模式下调试 Android 应用程序 - How to debug the Android App in release mode using Android studio 如何调试仅在发布模式下崩溃的 Android 应用 - How do I debug an Android app that crashes only in Release Mode Android - 用于调试和发布模式的应用程序图标 - Android - app icon for debug and release mode 为什么我的(android)phonegap应用程序可以在调试模式下工作,而不能在发布模式下工作? - Why my (android) phonegap app works on debug mode but not on release mode? Android应用程式在侦错模式下运作良好,但在发布模式下当机 - Android app working fine in debug mode but crashing in release mode 在调试模式下运行的同一Android应用程序在发布模式下崩溃 - Same Android app who runs on Debug mode, crashes on release mode 在调试和发布模式下都允许从Android应用程序进行Api访问 - Allow Api Access for Android App From Both in Debug and Release Mode Android App在调试中工作,但在发布模式下不起作用 - Android App works in debug but doesn't work in release mode 如何知道我的Android应用程序是在发布版还是调试模式下构建的? - How can I know if my android app was built in release or debug mode? Android:如何为SIGNED应用的非调试模式获取Facebook的Release Key Hash - Android: How to get Release Key Hash for facebook for SIGNED app NOT Debug mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM