encorej / acra

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

Get java.lang.ExceptionInInitializerError for ACRA.init(this) #110

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I set up ACRA following the wiki on the site, ACRA is running like a charm on 
the emulator but when I export a signed package from within MOTODEV Studio 
(using ProGuard, set up ProGuard following the instructions in 
http://code.google.com/p/acra/wiki/ACRAProGuardHowTo) the whole Application is 
giving me a "force close" on start up.

What steps will reproduce the problem?
1. Create "MyApplication extends Application" class
2. Import needed packages org.acra.* and org.acra.annotiation.*
3. Export signed package and install it on device, try to run Application.

What is the expected output? What do you see instead?
The expected output would be that I see my Application up and running like in 
the emulator, instead I got the java.lang.ExceptionInInitializerError for the 
codeline where I try to initialize ACRA ("ACRA.init(this);").
In "Caused By" I got the following line according to ACRA:
at org.acra.ErrorReporter.<clinit>(SourceFile:207)

If I catch this Error, everything runs perfectly... but ACRA is not initialized 
and that's not what I intend to do.

What version of the product are you using? On what operating system?
ACRA Version: 4.2.3
OS Version: Android 2.3.5 on Samsung Galaxy S2
App MIN_SDK: API 7 (Google API)

Please provide any additional information below.
I first tried to initialized the ErrorReporter separately like in TicketID:88 
(ACRA.init(this) fails) but it keeps crashing and bringing up the 
java.lang.ExceptionInInitializerError...

that's what I have now in MyApplication.java

package at.starnberger.droid;

import android.app.Application;
import android.util.Log;
import org.acra.*;
import org.acra.annotation.*;

@ReportsCrashes(formKey="dDBGZGxSb1duVFVYMFpWazhxRDFtQ0E6MQ",
mode = ReportingInteractionMode.SILENT,
resToastText = R.string.crash_toast_text, // optional, displayed as soon as the 
crash occurs, before collecting data which can take a few seconds
resNotifTickerText = R.string.crash_notif_ticker_text,
resNotifTitle = R.string.crash_notif_title,
resNotifText = R.string.crash_notif_text,
resNotifIcon = android.R.drawable.stat_notify_error, // optional. default is a 
warning sign
resDialogText = R.string.crash_dialog_text,
resDialogIcon = R.drawable.warning_blue, //optional. default is a warning sign
//resDialogTitle = R.string.crash_dialog_title, // optional. default is your 
application name
//resDialogCommentPrompt = R.string.crash_dialog_comment_prompt, // optional. 
when defined, adds a user text field input with this text resource as a label
resDialogOkToast = R.string.common_txt_accept // optional. displays a Toast 
message when the user accepts to send a report.
)
public class MyApplication extends Application {
    private static final String TAG = MyApplication.class.getSimpleName();

    @Override
    public void onCreate() {
                super.onCreate();
        try {
            ErrorReporter.getInstance().init(this);
            ACRA.init(this);
        } catch(RuntimeException e) {
            Log.d(TAG,"Failed to load ACRA! Exception: " + e.toString(), e);
        } catch(ExceptionInInitializerError e) {
            Log.e(TAG, "Got ERROR: " + e.toString(), e);
        }

    }
}

Notice: I also tried it with calling "super.onCreate()" at the very end, this 
brings the same error message.

Original issue reported on code.google.com by geizpar...@gmail.com on 6 Feb 2012 at 8:42

GoogleCodeExporter commented 8 years ago
Sorry that I didn't came up with this in the first post, here is my 
proguard.cfg:

-injars 'C:\Workspaces\motodevWs\gp2012\bin\classes'
-injars 'C:\Workspaces\motodevWs\gp2012\libs'
-outjars 'C:\Workspaces\motodevWs\gp2012\bin\classes-processed.jar'

-libraryjars 'C:\android\android-sdk\platforms\android-7\android.jar'
-libraryjars 
'C:\android\android-sdk\add-ons\addon_google_apis_google_inc_7\libs\maps.jar'

-optimizations !code/simplification/arithmetic
-allowaccessmodification
-repackageclasses ''
-keepattributes *Annotation*,SourceFile,LineNumberTable,*Annotation*
-renamesourcefileattribute SourceFile
-dontpreverify
-dontwarn java.awt.**,javax.security.**,java.beans.**,com.sun.**

-keep public class * extends android.app.Activity

-keep public class * extends android.app.Application

-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.os.Parcelable {
    static android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

# keep this class so that logging will show 'ACRA' and not a obfuscated name 
like 'a'.
# Note: if you are removing log messages elsewhere in this file then this isn't 
necessary
-keep class org.acra.ACRA {
    <fields>;
    <methods>;
}

# keep this around for some enums that ACRA needs
-keep class org.acra.ReportingInteractionMode {
    <fields>;
    <methods>;
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter {
    public void addCustomData(java.lang.String,java.lang.String);
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter {
    public org.acra.ErrorReporter$ReportsSenderWorker handleSilentException(java.lang.Throwable);
}

Original comment by geizpar...@gmail.com on 6 Feb 2012 at 8:47

GoogleCodeExporter commented 8 years ago
After some research I found the solution to my problem and it was indeed 
connected to my version of "proguard.cfg". 

somehow I managed to "forget" the -keppclassmembers entry for enums which is:

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

I added this entry to the ProGuard config file (proguard.cfg) and everything 
runs perfectly!

please close this issue

Original comment by geizpar...@gmail.com on 6 Feb 2012 at 12:03

GoogleCodeExporter commented 8 years ago

Original comment by kevin.gaudin on 5 Mar 2012 at 10:02