【问题标题】:Android ProGuard return Line NumberAndroid ProGuard 返回行号
【发布时间】:2012-04-26 21:08:58
【问题描述】:

有没有办法让 ProGuard 返回发生崩溃的行号? 我可以使用retrace 来获取该方法,但通常对于NullPointerException 之类的事情有太多的可能性,并且在大量代码中很难确定根本原因,因为您必须检查每个对象并且它的生命循环以确保没有任何问题。如果 ProGuard 可以将其缩小到对我来说是一个行号,那真的很有帮助。

【问题讨论】:

    标签: java android apk proguard


    【解决方案1】:

    将此行添加到您的 proguard-project.txt 文件中。

    # will keep line numbers and file name obfuscation
    -renamesourcefileattribute SourceFile
    -keepattributes SourceFile,LineNumberTable
    

    https://www.guardsquare.com/en/products/proguard/manual/usage

    【讨论】:

    • 我在我的 Android Studio 解决方案中的任何地方都找不到 proguard-project.txt 文件。它在哪里??
    • @MikeKeskinov,见proguardFiles getDefaultProguardFile,在那里你会找到文件名。如果不存在,则创建一个。可能是proguard-rules.pro
    【解决方案2】:

    当您创建一个新的 Android 项目时,它会告诉您哪些行可能需要取消注释:

    # If your project uses WebView with JS, uncomment the following
    # and specify the fully qualified class name to the JavaScript interface
    # class:
    #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
    #   public *;
    #}
    
    # Uncomment this to preserve the line number information for
    # debugging stack traces.
    #-keepattributes SourceFile,LineNumberTable
    
    # If you keep the line number information, uncomment this to
    # hide the original source file name.
    #-renamesourcefileattribute SourceFile
    

    所以,你应该考虑拥有这些:

    -keepattributes SourceFile,LineNumberTable
    -renamesourcefileattribute SourceFile
    

    但是,请注意,由于某种原因,Firebase Crashlytics 团队告诉我这条线路可能会干扰他们的服务:

    -renamesourcefileattribute SourceFile
    

    因此,如果您使用它,您可能看不到有关崩溃堆栈跟踪的良好信息。

    【讨论】:

    • 我正要问这个问题,非常感谢您提供这些信息。你知道如果我不使用这条线-renamesourcefileattribute SourceFile 会导致问题吗?谢谢。
    • @Hilal 我决定不使用-renamesourcefileattribute SourceFile
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-02
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    相关资源
    最近更新 更多