Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raised ExceptionInInitializerError after applied proguard in Android #412

Open
macroday opened this issue Mar 21, 2018 · 4 comments
Open
Labels
Android Issues related to running Rhino on Android Triage Issues yet to be triaged

Comments

@macroday
Copy link

Hi, Please check the below error and tell me the solution for this.

java.lang.ExceptionInInitializerError
at org.a.b.l.a(Context.java:396)
at org.a.b.l.b(Context.java:3391)
at com.xx.yy.view.Activity.g(MyActivity.java:16)
at com.xx.yy.view.Activity.onActivityResult(MyActivity.java:235)
at android.app.Activity.dispatchActivityResult(Activity.java:6931)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4090)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4137)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1529)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

@macroday macroday changed the title ExceptionInInitializerError after applied proguard in Android Raised ExceptionInInitializerError after applied proguard in Android Mar 21, 2018
@gbrail
Copy link
Collaborator

gbrail commented Mar 21, 2018 via email

@macroday
Copy link
Author

macroday commented Mar 23, 2018

I could provide a min of code instead of all. Pls check below.

This is my code,

org.mozilla.javascript.Context jsContext = org.mozilla.javascript.Context.enter();
jsContext.setOptimizationLevel(-1);
scope = jsContext.initSafeStandardObjects();
jsContext.evaluateString(scope, jsScript, "invokee", 1, null);

And i have referred at Android docs that mentioned of ExceptionInInitializerError occur at static initializer state,

Signals that an unexpected exception has occurred in a static initializer. An ExceptionInInitializerError is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable.

As of release 1.4, this exception has been retrofitted to conform to the general purpose exception-chaining mechanism. The "saved throwable object" that may be provided at construction time and accessed via the getException() method is now known as the cause, and may be accessed via the getCause() method, as well as the aforementioned "legacy method."

As i can see you have used static method to initialize the context. Pls refer below,

 public static Context enter() {
        return enter((Context)null);
 }

I thought it raised might be of this. Pls help me to fix it.

@sainaen
Copy link
Contributor

sainaen commented Mar 27, 2018

@macroday
That’s a pretty standard looking initialization code to me, so I doubt there is a problem around there.

enter() is a static method, but ExceptionInInitializerError is throw when the static initializers fail, for example:

class A {
    static int i;
    static {
        // make initializer fail
        i = 1 / 0;
    }
}

Could you please post a proguard config that you’re using? I think one of the classes required by Context may be missing because of it. (By the way, here’s a one that seems to work fine.)

Also, this exception should have a cause set — an actual problem that caused initializer to fail. I don’t know if it’s missing or you just didn’t copy that part, so it would be great if you could check that we have a full stack trace here.

@macroday
Copy link
Author

macroday commented Apr 1, 2018

@sainaen

I have attached my proguard rules at below.

-dontoptimize
-keeppackagenames org.mozilla.**
-keep class org.mozilla.** { *; }
-dontwarn org.mozilla.**
-dontwarn com.squareup.**
-dontwarn org.xmlpull.v1.**
-dontnote org.xmlpull.v1.**
-keep class org.xmlpull.** { *; }
-keep class com.google.android.gms.internal.** { *; }
-keepattributes Signature,SourceFile,LineNumberTable
-assumenosideeffects class android.util.Log {
    *;
}

This error occur when i comment the below statements in proguard rules,

-dontoptimize
-keeppackagenames org.mozilla.**
-keep class org.mozilla.** { *; }
-dontwarn org.mozilla.**

I think the cause of error due to use the Context with package because while optimizing the app android will change the all package name. Please give me a better solution to fix it soon.

@p-bakker p-bakker added the Triage Issues yet to be triaged label Jul 6, 2021
@p-bakker p-bakker added the Android Issues related to running Rhino on Android label May 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Issues related to running Rhino on Android Triage Issues yet to be triaged
Projects
None yet
Development

No branches or pull requests

4 participants