Android应用崩溃:为什么有(未知来源)而不是行号

Ahm*_*med 7 android android-proguard

我建立并签名发布的应用程序偶尔会在我的机器上崩溃,在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)
Run Code Online (Sandbox Code Playgroud)

正如你所看到的那样,我的应用程序包中没有看到任何行号,而是显示未知来源.

这是我的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')
}
Run Code Online (Sandbox Code Playgroud)

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

retrace.bat|retrace.sh [-verbose] mapping.txt [<stacktrace_file>]
Run Code Online (Sandbox Code Playgroud)

在此类名称显示更好但仍然没有行号?我想知道这里究竟出了什么问题会导致行号丢失?如何在我的代码中获得显示行号的跟踪,并且仍然能够为发布做好准备?

T. *_*art 6

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

-keepattributes SourceFile,LineNumberTable
# rename the source files to something meaningless, but it must be retained
-renamesourcefileattribute ''
Run Code Online (Sandbox Code Playgroud)

  • 除了空字符串,你可以使用 `SourceFile` 来保留文件名:`-renamesourcefileattribute SourceFile` (2认同)

Pan*_*lan 6

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

minifyEnabled true
Run Code Online (Sandbox Code Playgroud)

要在使用 proguard 时获取行号,您必须在proguard-rules.pro中编写以下行

-keepattributes *Annotation*,SourceFile,LineNumberTable
Run Code Online (Sandbox Code Playgroud)

你就完成了。