rahul saini
rahul saini

Reputation: 51

Issue in Rhino API, after integrating proguard

After integrating Proguard, I'm facing issue with Rhino API.

Without proguard, below code in working fine.

org.mozilla.javascript.Context context = org.mozilla.javascript.Context.enter();
context.setOptimizationLevel(-1);
ScriptableObject scope = context.initStandardObjects();
try {
    InputStream inputStream = mContext.getAssets().open(JAVASCRIPT_FILE);
    InputStreamReader reader = new InputStreamReader(inputStream);

    context.evaluateReader(scope, reader, JAVASCRIPT_FILE, 1, null);
} catch (IOException exception) {
    throw new CustomException(null, exception);
}
Function functionAdd = (Function) scope.get(JAVASCRIPT_FUNCTION_NAME);

Object returnObject = functionAdd.call(context, scope, scope, new Object[] {
    parameter1, parameter2, parameter3
});

But after integrating Proguard, I'm getting below error:

02-26 14:58:13.200: E/AndroidRuntime(11607): Caused by: java.lang.IllegalStateException: Failed to create VMBridge instance
02-26 14:58:13.200: E/AndroidRuntime(11607): at org.a.b.ds.<clinit>(Unknown Source)
02-26 14:58:13.200: E/AndroidRuntime(11607): ... 11 more

Upvotes: 2

Views: 974

Answers (1)

S J
S J

Reputation: 176

Proguard will obfuscate the rhino library classes unless you explicitly tell it not to. As noted by Selvin, in particular the VMBridge.java class gets affected.

Keeping the rhino library classes from getting obfuscated will solve the issue. Use the following proguard exception for that:

-keep class org.mozilla.javascript.** { *; }

Upvotes: 15

Related Questions