sank20 / acra

Automatically exported from code.google.com/p/acra
0 stars 0 forks source link

Using ACRA with ProGuard doesn't seem to produce stack traces #22

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm not sure this is the right place to ask this but will ACRA work with 
ProGuard which obfuscates the method names etc.?  

What steps will reproduce the problem?
1.I've included Acra 3.0 in my Android application and if I run it without 
ProGuard it works!
2. If I include ProGuard it doesn't seem to create the report.
3. I have configured ProGuard with the following "extra" seetings in 
proguard.cfg (to keep these from being tossed out by ProGuard):

-keep public class org.acra.ErrorReporter
{
    public void addCustomData(java.lang.String,java.lang.String);
}

-keep public class org.acra.ErrorReporter
{
    public org.acra.ErrorReporter$ReportsSenderWorker handleSilentException(java.lang.Throwable);
}

I was expecting to see a stack trace in google docs which was obfuscated, but 
instead, nothing shows up with ProGuard "turned on". So, I'm assuming either it 
is my ProGuard.cfg file settings or potentially ACRA doesn't support code that 
has been obfuscated with a tool like ProGuard.  

If this is the wrong place to ask a question about ACRA I will re-post 
somewhere else...

Thanks!

Original issue reported on code.google.com by ping...@gmail.com on 8 Dec 2010 at 10:43

GoogleCodeExporter commented 8 years ago
I did not test with Proguard at all.

Do you have some interesting traces in the LogCat ?

Original comment by kevin.gaudin on 8 Dec 2010 at 10:48

GoogleCodeExporter commented 8 years ago
ProGuard in only included when doing a 'release build' where you export the 
project to a .APK file and then install it with 'ADB Install ProgramName' to an 
emulator or a real device.  So, when I install from a release .APK file, ACRA 
does *not* show up in LogCat.  However, if I run it from Eclipse LogCat does 
show ACRA messages including writing crash report, connecting to google 
spreadsheets, posting crash data, etc.  So, either I'm just not configuring 
ProGuard correctly (and it is pulling out the ARCA calls which I don't see it 
doing in the generated 'usage.txt' file it creates) or possibly ACRA doesn't 
support obfuscation like this.  I think it is probably my ProGuard 
configuration but I thought I would ask to see if it was something that was 
know to work or not...

Thanks again

Original comment by ping...@gmail.com on 9 Dec 2010 at 12:24

GoogleCodeExporter commented 8 years ago
Ok, I'll have to test that.

Original comment by kevin.gaudin on 9 Dec 2010 at 12:30

GoogleCodeExporter commented 8 years ago
Thanks!  I will keep playing around with different configurations of ProGuard 
and will post back if I find something that works.  I'm not sure in the end if 
it does work what it will look like in the google spreadsheet for the call 
stack but I want to see if I can decipher it using some the of the SDK tools...

Original comment by ping...@gmail.com on 9 Dec 2010 at 12:35

GoogleCodeExporter commented 8 years ago
I just read that ProGuard considers Annotations as optional and removes them.

ACRA v3 configuration system is based on a Runtime visible Annotation which is 
read during the execution of ACRA.init(Application app) via reflection API.

So, from the examples given at 
http://proguard.sourceforge.net/manual/examples.html#annotations I guess you 
should add -keepattributes *Annotation* to your ProGuard conf.

Could you please test again with this parameter ?

Original comment by kevin.gaudin on 9 Dec 2010 at 1:48

GoogleCodeExporter commented 8 years ago
Thanks but I had no luck with adding -keepattributes *Annotation*.  I even 
tried:

-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
                SourceFile,LineNumberTable,*Annotation*,EnclosingMethod

So far the only thing that seems to "keep" ACRA is:

-dontobfuscate
-dontoptimize
(so ProGuard is only shrinking)

I will keep playing around with other settings to see if I can get it to work 
with obfuscating and / or optimizing...

Original comment by ping...@gmail.com on 9 Dec 2010 at 3:01

GoogleCodeExporter commented 8 years ago
I spoke too soon.  By including -keepattributes *Annotation* it does get 
further and calls into the ACRA.init but then crashes in that call.  I thought 
this was my code crashing as I have a bit of code to cause a crash at start up 
and I didn't look at the LogCat close enough.   The current problem is it 
doesn't know what "SILENT" is so that must be getting removed I would guess. 

Here is the stack trace from where I'm calling ACRA.init within my onCreate:  

FATAL EXCEPTION: main
java.lang.NoSuchFieldError: SILENT
    at java.lang.reflect.Method.getDefaultValue(Native Method)
    at java.lang.reflect.Method.getDefaultValue(Method.java:337)
    at org.apache.harmony.lang.annotation.AnnotationFactory.getElementsDescription(AnnotationFactory.java:78)
    at org.apache.harmony.lang.annotation.AnnotationFactory.<init>(AnnotationFactory.java:118)
    at org.apache.harmony.lang.annotation.AnnotationFactory.createAnnotation(AnnotationFactory.java:100)
    at java.lang.Class.getDeclaredAnnotations(Native Method)
    at java.lang.Class.getAnnotations(Class.java:322)
    at java.lang.Class.getAnnotation(Class.java:292)
    at org.acra.ACRA.a(SourceFile:115)

Original comment by ping...@gmail.com on 9 Dec 2010 at 3:45

GoogleCodeExporter commented 8 years ago
I guess the enum has been obfuscated. Here is the corresponding ProGuard 
example:
http://proguard.sourceforge.net/manual/examples.html#enumerations

Original comment by kevin.gaudin on 9 Dec 2010 at 6:44

GoogleCodeExporter commented 8 years ago
Hmmmm... I already have:

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

So I'm not sure why it can't find it.  I will keep looking...

Thanks for helping!

Original comment by ping...@gmail.com on 9 Dec 2010 at 7:04

GoogleCodeExporter commented 8 years ago
Looks like the enum names are being obfuscated.

from my mapping.txt file

1990 org.acra.ReportingInteractionMode -> org.acra.c:
1991     org.acra.ReportingInteractionMode SILENT -> a
1992     org.acra.ReportingInteractionMode NOTIFICATION -> b
1993     org.acra.ReportingInteractionMode TOAST -> c
1994     org.acra.ReportingInteractionMode[] ENUM$VALUES -> d
1995     1:1:org.acra.ReportingInteractionMode[] values() -> values
1996     1:1:org.acra.ReportingInteractionMode valueOf(java.lang.String) -> 
valueOf

-keep class org.acra.ReportingInteractionMode {
    *;
}

fixes it for me.

Original comment by tj.mccon...@gmail.com on 13 Dec 2010 at 5:07

GoogleCodeExporter commented 8 years ago
That did the trick!  Thanks!

Original comment by ping...@gmail.com on 14 Dec 2010 at 2:46

GoogleCodeExporter commented 8 years ago
Would anyone write a wiki doc on using ACRA with Proguard ?

Original comment by kevin.gaudin on 22 Dec 2010 at 12:45

GoogleCodeExporter commented 8 years ago
I can try.  How do you create a wiki page on the ACRA site?

Original comment by ping...@gmail.com on 22 Dec 2010 at 12:14

GoogleCodeExporter commented 8 years ago
Please send me your email (the one which is associated with your googlecode 
account) to kevin.gaudin@gmail.com. I'll add you to the project's contributors 
and give you the rights to modify wiki pages. 

Thanks! 

Original comment by kevin.gaudin on 22 Dec 2010 at 1:44

GoogleCodeExporter commented 8 years ago
Wiki has been updated with details on how to make ACRA work with Proguard.

Original comment by william....@gmail.com on 16 Jul 2011 at 5:59

GoogleCodeExporter commented 8 years ago
And here is the wiki page:
https://github.com/ACRA/acra/wiki/ProGuard

Original comment by nick.h...@gmail.com on 23 Jan 2013 at 11:21