【问题标题】:Android app crash: Why there is (Unknown Source) instead of line numberAndroid应用程序崩溃:为什么有(未知来源)而不是行号
【发布时间】:2016-06-25 01:34:32
【问题描述】:

我构建并签名的应用程序偶尔会在我的机器上崩溃,在 logcat 中我打开堆栈跟踪以获取空指针异常。但我无法找到确切的行号?因为它说(未知来源) 例如有些行看起来像这样

   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)

正如你所见,无论我的应用程序包在哪里,我都看不到行号,而是显示未知来源。

这是我对这个项目的 gradle 配置。

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')
}

该应用正在使用已签名的构建变体。 我使用 proguard 命令使用以下语法正确读取跟踪

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

在这个类名显示得更好但仍然没有行号之后?我想知道这里到底有什么问题导致行号丢失?如何获得在我的代码中显示行号的跟踪,并且仍然能够使其为发布做好准备?

【问题讨论】:

  • 您是否尝试过在调试模式下运行应用程序并采取任何措施重复错误?你会得到未知来源,因为代码被混淆和最小化
  • 无法在调试中重现,但是我使用的回溯命令是否意味着相反并显示确切的行?
  • 这就是您去混淆的方式,是的,但是,我不确定是否会提取行号,因为代码仍然被缩小。您是否从开发人员控制台获取此跟踪信息? support.google.com/googleplay/android-developer/answer/6295281
  • 不,不是来自开发控制台,它在我的设备上崩溃了,所以我从复制到文本文件中的 logcat 中获取堆栈跟踪,然后尝试回溯。我删除了 debuggable false、minifyEnabled true 和 proguardFiles 这三行,然后插入了一个假崩溃,然后它显示了行号,但是使用 proguard 和 minify 等它不显示行号。
  • 对,这是有道理的,因为它不再被缩小和混淆

标签: android android-proguard


【解决方案1】:

为了在 ProGuard 构建后保留调试信息,您需要添加以下配置(到您的 proguard-rules.pro 文件中):

-keepattributes SourceFile,LineNumberTable
# rename the source files to something meaningless, but it must be retained
-renamesourcefileattribute ''

【讨论】:

  • 代替空字符串,可以使用SourceFile,保留文件名:-renamesourcefileattribute SourceFile
【解决方案2】:

当您在 build.gradle 中启用 minify 时会出现此错误。

minifyEnabled true

要在使用 proguard 时获取行号,您必须在 proguard-rules.pro

中编写以下行
-keepattributes *Annotation*,SourceFile,LineNumberTable

你就完成了。

【讨论】:

    【解决方案3】:

    您也可以将 mapping.txt 文件上传到您的 Google Play 开发者控制台。在控制台上,只需单击要反混淆的应用程序。然后转到“Android Vitals”>“ANR 和崩溃”:

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

    并上传适合您应用当前版本的 mapping.txt 文件。

    mapping.txt的位置:

    Android 工作室:

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

    日食:

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

    注意:只有在上传 mapping.txt 之后,才会对错误进行去混淆处理。 Google Play 开发者控制台中没有对已报告的崩溃进行去混淆处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多